write stats to influxdb

This commit is contained in:
Miki 2016-02-19 10:48:55 +01:00
parent 494696c336
commit a03057fe81
2 changed files with 22 additions and 4 deletions

View file

@ -12,7 +12,7 @@ import (
)
const (
_VERSION = "v1.1.1"
_VERSION = "v1.2.0"
_tformat = "2006-01-02"
_24h = (time.Hour * 23) + (time.Minute * 59) + (time.Second * 59)
_10m = (time.Minute * 10)
@ -44,6 +44,14 @@ func main() {
os.Exit(0)
}
if opts.Hostname == "" {
var err error
opts.Hostname, err = os.Hostname()
if err != nil {
fmt.Println("Hostname error: ", err.Error())
}
}
fs, err := os.OpenFile(opts.LogFile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err != nil {
fmt.Println("Log file error: ", err.Error())
@ -100,6 +108,12 @@ func main() {
log.Printf("Stop %s: %s\n", ys[i], time.Since(pStart))
}
fmt.Printf("Stop: OK: %d - TOT: %d - Time: %s\n\r", countOK, countTOT, time.Since(start))
log.Printf("Stop: OK: %d - TOT: %d - Time: %s\n\r", countOK, countTOT, time.Since(start))
stop := time.Since(start)
fmt.Printf("Stop: OK: %d - TOT: %d - Time: %s\n\r", countOK, countTOT, stop)
log.Printf("Stop: OK: %d - TOT: %d - Time: %s\n\r", countOK, countTOT, stop)
if opts.Influxdb != "" {
writeStats(start, stop)
}
}

View file

@ -19,12 +19,14 @@ type Options struct {
Duration time.Duration
Interval time.Duration
LogFile string
Influxdb string
Hostname string
Version bool
Debug bool
}
func usage() {
fmt.Println("Usage: lastlogin_consolidate -ms <mongo source mongodb://IP:PORT> -md <mongo destination mongodb://IP:PORT> -l <logfile> -d <date> -dd <duration> -i <interval> -v\n")
fmt.Println("Usage: lastlogin_consolidate -ms <mongo source mongodb://IP:PORT> -md <mongo destination mongodb://IP:PORT> -l <logfile> -d <date> -dd <duration> -i <interval> -I <influxdb uri> -v\n")
os.Exit(0)
}
@ -38,6 +40,8 @@ func init() {
flag.StringVar(&opts.MongoSrc, "ms", opts.MongoSrc, "Mongodb Source")
flag.StringVar(&opts.MongoDst, "md", "", "Mongodb Destination")
flag.StringVar(&opts.Influxdb, "I", "", "Influxdb uri")
flag.StringVar(&opts.Hostname, "H", "", "Hostname")
flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename")
flag.StringVar(&opts.StartDate, "d", opts.StartDate, "Date")
flag.DurationVar(&opts.Duration, "dd", opts.Duration, "Duration")