aggiornata la configurazione per influxdb

This commit is contained in:
Michele 2017-03-06 12:43:24 +01:00
parent ca0605108a
commit c244dc8922
3 changed files with 18 additions and 12 deletions

View file

@ -8,13 +8,18 @@ import (
influxdb "github.com/influxdata/influxdb/client/v2" influxdb "github.com/influxdata/influxdb/client/v2"
) )
var (
infdb string
infhost string
)
func writeStats(start time.Time) { func writeStats(start time.Time) {
if opts.Debug { if opts.Debug {
fmt.Printf("writing to influxdb server: %s", opts.Influxdb) fmt.Printf("writing to influxdb server: %s", opts.Influxdb)
} }
c, err := influxdb.NewHTTPClient(influxdb.HTTPConfig{ c, err := influxdb.NewHTTPClient(influxdb.HTTPConfig{
Addr: opts.Influxdb, Addr: fmt.Sprintf("http://%s", infdb),
Timeout: 2 * time.Second, Timeout: 2 * time.Second,
}) })
if err != nil { if err != nil {
@ -32,7 +37,7 @@ func writeStats(start time.Time) {
return return
} }
tags := map[string]string{"server": opts.Hostname, "domain": dbs.Database} tags := map[string]string{"server": infhost, "domain": dbs.Database}
fields := map[string]interface{}{ fields := map[string]interface{}{
"user": count.GetUser(), "user": count.GetUser(),
"log": count.GetLog(), "log": count.GetLog(),

16
main.go
View file

@ -6,12 +6,13 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"regexp"
"sync" "sync"
"time" "time"
) )
const ( const (
_Version = "v4.0.3" _Version = "v4.0.4"
_Producer = 0 _Producer = 0
_Consumer = 1 _Consumer = 1
_Remover = 2 _Remover = 2
@ -42,11 +43,14 @@ func main() {
os.Exit(0) os.Exit(0)
} }
if opts.Hostname == "" { if opts.Influxdb != "" {
var err error re, _ := regexp.Compile(`(\w+)@(\d+.\d+.\d+.\d+:\d+)`)
opts.Hostname, err = os.Hostname() if re.MatchString(opts.Influxdb) {
if err != nil { match := re.FindStringSubmatch(opts.Influxdb)
fmt.Println("Hostname error: ", err.Error()) infhost = match[1]
infdb = match[2]
} else {
opts.Influxdb = ""
} }
} }

View file

@ -24,7 +24,6 @@ type Options struct {
Version bool Version bool
MaxError int MaxError int
Influxdb string Influxdb string
Hostname string
Month string Month string
Pidfile string Pidfile string
Queue int Queue int
@ -44,8 +43,7 @@ func usage() {
-t <redis keys ttl> -t <redis keys ttl>
-l <logfile> -l <logfile>
-T <running timeout> -T <running timeout>
-H <hostname> -i <influxdb [localname@ip:port]>
-i <influxdb uri>
-q <parallel consumer> -q <parallel consumer>
-v <version> -v <version>
-D <debug> -D <debug>
@ -66,7 +64,6 @@ func init() {
opts.Exe = path.Base(os.Args[0]) opts.Exe = path.Base(os.Args[0])
flag.StringVar(&opts.Influxdb, "i", "", "influxdb server") flag.StringVar(&opts.Influxdb, "i", "", "influxdb server")
flag.StringVar(&opts.Hostname, "H", "", "hostname")
flag.StringVar(&dbs.MongoURI, "m", "", "Mongodb") flag.StringVar(&dbs.MongoURI, "m", "", "Mongodb")
flag.StringVar(&dbs.Database, "d", dbs.Database, "Mongodb Database") flag.StringVar(&dbs.Database, "d", dbs.Database, "Mongodb Database")
flag.StringVar(&dbs.RedisURI, "r", dbs.RedisURI, "Redis") flag.StringVar(&dbs.RedisURI, "r", dbs.RedisURI, "Redis")