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

16
main.go
View file

@ -6,12 +6,13 @@ import (
"fmt"
"log"
"os"
"regexp"
"sync"
"time"
)
const (
_Version = "v4.0.3"
_Version = "v4.0.4"
_Producer = 0
_Consumer = 1
_Remover = 2
@ -42,11 +43,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())
if opts.Influxdb != "" {
re, _ := regexp.Compile(`(\w+)@(\d+.\d+.\d+.\d+:\d+)`)
if re.MatchString(opts.Influxdb) {
match := re.FindStringSubmatch(opts.Influxdb)
infhost = match[1]
infdb = match[2]
} else {
opts.Influxdb = ""
}
}

View file

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