53 lines
960 B
Go
53 lines
960 B
Go
|
// influxdb
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
influxdb "github.com/influxdata/influxdb/client/v2"
|
||
|
)
|
||
|
|
||
|
func writeStats() {
|
||
|
if opts.Debug {
|
||
|
fmt.Printf("writing to influxdb server: %s", opts.Influxdb)
|
||
|
}
|
||
|
|
||
|
c, err := influxdb.NewHTTPClient(influxdb.HTTPConfig{
|
||
|
Addr: opts.Influxdb,
|
||
|
})
|
||
|
if err != nil {
|
||
|
fmt.Printf("Error: %+v\n", err)
|
||
|
return
|
||
|
}
|
||
|
defer c.Close()
|
||
|
|
||
|
bp, err := influxdb.NewBatchPoints(influxdb.BatchPointsConfig{
|
||
|
Database: "dovecot",
|
||
|
Precision: "s",
|
||
|
})
|
||
|
if err != nil {
|
||
|
fmt.Printf("Error: %+v\n", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
tags := map[string]string{"server": opts.Hostname}
|
||
|
fields := map[string]interface{}{
|
||
|
"user": count.GetUser(),
|
||
|
"log": count.GetLog(),
|
||
|
"err": count.GetErr(),
|
||
|
"rem": count.GetRem(),
|
||
|
"dup": count.GetDup(),
|
||
|
"stop": count.GetTime(),
|
||
|
}
|
||
|
pt, err := influxdb.NewPoint("ll2mongo", tags, fields)
|
||
|
if err != nil {
|
||
|
fmt.Printf("Error: %+v\n", err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
bp.AddPoint(pt)
|
||
|
|
||
|
// Write the batch
|
||
|
c.Write(bp)
|
||
|
}
|