File: README.md

package info (click to toggle)
golang-github-dcso-fluxline 0.0~git20200907.78686e5-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 84 kB
  • sloc: makefile: 16
file content (65 lines) | stat: -rw-r--r-- 1,514 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# fluxline [![CircleCI](https://circleci.com/gh/DCSO/fluxline.svg?style=shield)](https://circleci.com/gh/DCSO/fluxline) [![Documentation](https://godoc.org/github.com/DCSO/fluxline?status.svg)](http://godoc.org/github.com/DCSO/fluxline)

Encoder for Golang to prepare sets of metrics in [InfluxDB's Line Protocol](https://docs.influxdata.com/influxdb/v1.4/write_protocols/line_protocol_reference) 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

```bash
go get github.com/DCSO/fluxline
```

## Usage example

```golang
package main

import (
  "bytes"
  "fmt"
  "log"

  "github.com/DCSO/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())
}
```