aggiunto timeout per la connessione con influxdb
This commit is contained in:
parent
a03057fe81
commit
1ebc85d1c3
2 changed files with 52 additions and 1 deletions
51
influxdb.go
Normal file
51
influxdb.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
// influxdb
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
influxdb "github.com/influxdata/influxdb/client/v2"
|
||||
)
|
||||
|
||||
func writeStats(start time.Time, stop time.Duration) {
|
||||
if opts.Debug {
|
||||
fmt.Printf("writing to influxdb server: %s", opts.Influxdb)
|
||||
}
|
||||
|
||||
c, err := influxdb.NewHTTPClient(influxdb.HTTPConfig{
|
||||
Addr: opts.Influxdb,
|
||||
Timeout: 2 * time.Second,
|
||||
})
|
||||
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{}{
|
||||
"LoginOK": countOK,
|
||||
"LoginTOT": countTOT,
|
||||
"stop": stop.Seconds(),
|
||||
}
|
||||
pt, err := influxdb.NewPoint("llday", tags, fields, start)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %+v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
bp.AddPoint(pt)
|
||||
|
||||
// Write the batch
|
||||
c.Write(bp)
|
||||
}
|
|
@ -12,7 +12,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
_VERSION = "v1.2.0"
|
||||
_VERSION = "v1.2.1"
|
||||
_tformat = "2006-01-02"
|
||||
_24h = (time.Hour * 23) + (time.Minute * 59) + (time.Second * 59)
|
||||
_10m = (time.Minute * 10)
|
||||
|
|
Loading…
Add table
Reference in a new issue