spedisce a influxdb la data

This commit is contained in:
Miki 2016-04-21 16:11:27 +02:00
parent e3d7b1dae5
commit 2e53d3fb4f
2 changed files with 22 additions and 14 deletions

View file

@ -11,13 +11,14 @@ import (
type InfluxdbOutput struct {
CountOK int
CountTOT int
Start time.Time
Stop time.Duration
Pipe time.Duration
Find time.Duration
Insert time.Duration
}
func writeStats(start time.Time) {
func writeStats(start time.Time, ys time.Time) {
if opts.Debug {
fmt.Printf("writing to influxdb server: %s", opts.Influxdb)
}
@ -41,10 +42,11 @@ func writeStats(start time.Time) {
return
}
tags := map[string]string{"server": opts.Hostname}
tags := map[string]string{"server": opts.Hostname, "date": ys.String()}
fields := map[string]interface{}{
"LoginOK": idb.CountOK,
"LoginTOT": idb.CountTOT,
"start": ys,
"stop": idb.Stop.Seconds(),
"pipe": idb.Pipe.Nanoseconds(),
"find": idb.Find.Nanoseconds(),

View file

@ -12,7 +12,7 @@ import (
)
const (
_VERSION = "v1.3.0"
_VERSION = "v1.3.1"
_tformat = "2006-01-02"
_24h = (time.Hour * 23) + (time.Minute * 59) + (time.Second * 59)
_10m = (time.Minute * 10)
@ -82,12 +82,14 @@ func main() {
// DEBUG
//fmt.Printf("Start %+v\n\r", y)
var ys []time.Time
var ye []time.Time
// var ys []time.Time
// var ye []time.Time
var ys time.Time
var ye time.Time
// if opts.Duration <= (time.Hour * 24) {
ys = append(ys, time.Date(y.Year(), y.Month(), y.Day(), 0, 0, 0, 0, time.UTC))
ye = append(ye, ys[0].Add(opts.Duration))
ys = time.Date(y.Year(), y.Month(), y.Day(), 0, 0, 0, 0, time.UTC)
ye = ys.Add(opts.Duration)
/*
} else {
@ -108,15 +110,19 @@ func main() {
fmt.Printf("Start: %+v, Stop: %+v\n\r", ys, ye)
}
for i := range ys {
// for i := range ys {
pStart := time.Now()
pStart := time.Now()
aggregate(ys[i], ye[i])
// aggregate(ys[i], ye[i])
aggregate(ys, ye)
fmt.Printf("Stop %s: %s\n", ys[i], time.Since(pStart))
log.Printf("Stop %s: %s\n", ys[i], time.Since(pStart))
}
fmt.Printf("Stop %s: %s\n", ys, time.Since(pStart))
log.Printf("Stop %s: %s\n", ys, time.Since(pStart))
// fmt.Printf("Stop %s: %s\n", ys[i], time.Since(pStart))
// log.Printf("Stop %s: %s\n", ys[i], time.Since(pStart))
// }
idb.Stop = time.Since(start)
@ -124,6 +130,6 @@ func main() {
log.Printf("Stop: OK: %d - TOT: %d - Time: %s\n\r", idb.CountOK, idb.CountTOT, idb.Stop)
if opts.Influxdb != "" {
writeStats(start)
writeStats(start, ys)
}
}