objects structure
This commit is contained in:
parent
9c7006dcea
commit
914177d440
5 changed files with 117 additions and 113 deletions
52
influxdb.go
52
influxdb.go
|
@ -9,16 +9,32 @@ import (
|
|||
)
|
||||
|
||||
type InfluxdbOutput struct {
|
||||
CountOK int
|
||||
CountTOT int
|
||||
Start time.Time
|
||||
Stop time.Duration
|
||||
Pipe time.Duration
|
||||
Find time.Duration
|
||||
Insert time.Duration
|
||||
InsUsers int
|
||||
TotUsers int
|
||||
TotLogins int
|
||||
Now time.Time
|
||||
Start time.Time
|
||||
Stop time.Duration
|
||||
Pipe time.Duration
|
||||
Find time.Duration
|
||||
Insert time.Duration
|
||||
}
|
||||
|
||||
func writeStats(start time.Time, ys time.Time) {
|
||||
func Influxdb(start time.Time, ys time.Time) *InfluxdbOutput {
|
||||
i := InfluxdbOutput{
|
||||
InsUsers: 0,
|
||||
TotLogins: 0,
|
||||
TotUsers: 0,
|
||||
Insert: 0,
|
||||
Find: 0,
|
||||
Start: ys,
|
||||
Now: start,
|
||||
}
|
||||
|
||||
return &i
|
||||
}
|
||||
|
||||
func (i InfluxdbOutput) writeStats() {
|
||||
if opts.Debug {
|
||||
fmt.Printf("writing to influxdb server: %s", opts.Influxdb)
|
||||
}
|
||||
|
@ -42,17 +58,18 @@ func writeStats(start time.Time, ys time.Time) {
|
|||
return
|
||||
}
|
||||
|
||||
tags := map[string]string{"server": opts.Hostname, "date": ys.String()}
|
||||
tags := map[string]string{"server": opts.Hostname, "date": i.Start.String()}
|
||||
fields := map[string]interface{}{
|
||||
"LoginOK": idb.CountOK,
|
||||
"LoginTOT": idb.CountTOT,
|
||||
"start": ys.Format(_tformat),
|
||||
"stop": idb.Stop.Seconds(),
|
||||
"pipe": idb.Pipe.Nanoseconds(),
|
||||
"find": idb.Find.Nanoseconds(),
|
||||
"insert": idb.Insert.Nanoseconds(),
|
||||
"UsersOK": idb.InsUsers,
|
||||
"UsersTOT": idb.TotUsers,
|
||||
"LoginsTOT": idb.TotLogins,
|
||||
"start": i.Start.Format(_tformat),
|
||||
"stop": idb.Stop.Seconds(),
|
||||
"pipe": idb.Pipe.Nanoseconds(),
|
||||
"find": idb.Find.Nanoseconds(),
|
||||
"insert": idb.Insert.Nanoseconds(),
|
||||
}
|
||||
pt, err := influxdb.NewPoint("llday", tags, fields, start)
|
||||
pt, err := influxdb.NewPoint("llday", tags, fields, i.Now)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %+v\n", err)
|
||||
return
|
||||
|
@ -60,6 +77,5 @@ func writeStats(start time.Time, ys time.Time) {
|
|||
|
||||
bp.AddPoint(pt)
|
||||
|
||||
// Write the batch
|
||||
c.Write(bp)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue