1
0
Fork 0
A tool that was used to buffer InfluxDB metrics before version 1.0 that is completely obsolete at this point
Go to file
Gregory Eremin 3495977a8d Don't start a goroutine when flushing buffer 2014-10-05 02:44:40 +04:00
README.md Close buffer in #readme example 2014-08-12 15:24:33 +07:00
buffer.go Don't start a goroutine when flushing buffer 2014-10-05 02:44:40 +04:00
buffer_test.go Don't start a goroutine when flushing buffer 2014-10-05 02:44:40 +04:00

README.md

InfluxDB aggregated buffer

In order to achieve maximum writing performance to InfluxDB an application needs to write series with as many points per series, as many series per batch as possible.

This buffer does exactly that: it aggregates multiple points into single series and multiple series into single batch. When buffer gets full it flushes series into database.

Example:

package main

import (
	"net/http"

	influxdb "github.com/influxdb/influxdb/client"
	"github.com/localhots/influxdb_buffer"
)

func handleMetrics(rw http.ResponseWriter, req *http.Request) {
	ua := parseUserAgent(req.UserAgent())
	geo := fetchGeoInfo(req.RemoteAddr)

	buf.Add(
        &influxdb.Series{
            Name:    "app.browsers",
            Columns: []string{"vendor", "version", "mobile"},
            Points:  [][]interface{}{{ua.Vendor, ua.Version, ua.IsMobile}},
        },
        &influxdb.Series{
            Name:    "app.visitors.geo",
            Columns: []string{"ip", "country", "city", "isp"},
            Points:  [][]interface{}{{ip, geo.Country, geo.City, geo.Isp}},
        },
    )
}

func writeMetrics(series []*influxdb.Series) {
	influxdb.WriteSeriesWithTimePrecision(series, "s")
}

var (
	buf *buffer.Buffer
)

func main() {
	buf = buffer.New(100, writeMetrics)
    defer buf.Close()

	http.HandleFunc("/metrics", handleMetrics)
	http.ListenAndServe(":8080", nil)
}