fluxline

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2019 License: BSD-3-Clause Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

fluxline Documentation

Encoder for Golang to prepare sets of metrics in InfluxDB's Line Protocol format. As input, we use structs annotated with the influx tag, similar to how encoding/json works.

Supports the following Go builtin types as fields:

  • string
  • int32, int64, int16, int8, int, uint32, uint64, uint16, uint8, uint
  • float64, float32
  • bool
  • time.Time

Remarks

Not thread safe. If the struct is modified elsewhere concurrently, one would need to protect the read access required for encoding.

Get the code

go get github.com/HeavyHorst/fluxline

Usage example

package main

import (
  "bytes"
  "fmt"
  "log"

  "github.com/HeavyHorst/fluxline"
)

const measurement = "example"

type MyCounts struct {
  Success uint64 `influx:"success"`
  Error   uint64 `influx:"error"`
}

func main() {
  var counts MyCounts
  var b bytes.Buffer

  // ...
  counts.Success++
  // ...
  counts.Success++
  // ...
  counts.Error++
  // ...

  tags := make(map[string]string)
  tags["foo"] = "bar"

  encoder := fluxline.NewEncoder(&b)
  err := encoder.Encode(measurement, counts, tags)
  if err != nil {
		log.Fatal(err)
	}
  fmt.Print(b.String())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder struct {
	io.Writer
	// contains filtered or unexported fields
}

Encoder represents a component that encapsulates a target environment for measurement submissions, as given by hostname and receiving writer.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder creates a new encoder that writes to the given io.Writer.

func NewEncoderWithHostname

func NewEncoderWithHostname(w io.Writer, host string) *Encoder

NewEncoderWithHostname creates a new encoder that writes to the given io.Writer with an overridden hostname

func (*Encoder) Encode

func (a *Encoder) Encode(prefix string, val interface{}, tags map[string]string, opts ...Option) error

Encode writes the line protocol representation for a given measurement name, data struct and tag map to the io.Writer specified on encoder creation.

func (*Encoder) EncodeMap

func (a *Encoder) EncodeMap(prefix string, val map[string]interface{}, tags map[string]string, opts ...Option) error

EncodeMap writes the line protocol representation for a given measurement name, field value map and tag map to the io.Writer specified on encoder creation.

func (*Encoder) EncodeWithoutTypes

func (a *Encoder) EncodeWithoutTypes(prefix string, val interface{}, tags map[string]string, opts ...Option) error

EncodeWithoutTypes writes the line protocol representation for a given measurement name, data struct and tag map to the io.Writer specified on encoder creation. In contrast to Encode(), this method never appends type suffixes to values.

type Option

type Option func(*options)

func WithTime

func WithTime(t time.Time) Option

WithTime overrides the default timestamp (time.Now)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL