2015-11-20 15:23:12 +01:00
|
|
|
// options
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
2016-10-05 11:55:50 +02:00
|
|
|
// Options structure
|
2015-11-20 15:23:12 +01:00
|
|
|
type Options struct {
|
|
|
|
RedisTTL time.Duration
|
|
|
|
CurrentPath string
|
|
|
|
Exe string
|
|
|
|
LogFile string
|
2015-12-18 17:16:51 +01:00
|
|
|
ConfigFile string
|
2015-11-20 16:17:31 +01:00
|
|
|
Timeout time.Duration
|
2015-11-20 15:23:12 +01:00
|
|
|
Debug bool
|
2017-02-10 16:56:09 +01:00
|
|
|
Test bool
|
2015-11-20 15:23:12 +01:00
|
|
|
Version bool
|
2015-11-24 12:28:22 +01:00
|
|
|
MaxError int
|
2016-02-18 13:12:53 +01:00
|
|
|
Influxdb string
|
2016-05-13 12:11:52 +02:00
|
|
|
Month string
|
2018-10-24 09:33:08 +02:00
|
|
|
Queue int
|
|
|
|
Retention float64
|
2018-11-22 12:29:08 +01:00
|
|
|
Consul string
|
2018-11-27 15:10:19 +01:00
|
|
|
Port int
|
2015-11-20 15:23:12 +01:00
|
|
|
}
|
|
|
|
|
2016-05-16 16:12:16 +02:00
|
|
|
var (
|
|
|
|
opts = Options{
|
2017-02-10 16:56:09 +01:00
|
|
|
RedisTTL: time.Hour * 11688, // 16 mesi
|
|
|
|
LogFile: "log/llmongo.log",
|
2016-05-16 16:12:16 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2015-11-20 15:23:12 +01:00
|
|
|
func usage() {
|
2017-03-03 16:59:18 +01:00
|
|
|
fmt.Println(`Usage: llmongo
|
|
|
|
-m <mongodb [ip:port,ip:port]>
|
2017-03-07 17:42:53 +01:00
|
|
|
-d <mongodb database [dbname]>
|
2018-11-22 12:29:08 +01:00
|
|
|
-r <redisdb [ip:port]>
|
2017-03-03 16:59:18 +01:00
|
|
|
-t <redis keys ttl>
|
|
|
|
-l <logfile>
|
|
|
|
-T <running timeout>
|
2018-11-22 12:29:08 +01:00
|
|
|
-i <influxdb [localname@ip:port]>
|
|
|
|
-C <consul [ip:port]>
|
2018-11-27 15:10:19 +01:00
|
|
|
-P <check port> [port] ## used by consul to check services ##
|
2017-03-03 16:59:18 +01:00
|
|
|
-q <parallel consumer>
|
2018-10-24 09:33:08 +02:00
|
|
|
-R <retention>
|
2017-03-03 16:59:18 +01:00
|
|
|
-v <version>
|
|
|
|
-D <debug>
|
|
|
|
-DD <Test>`)
|
2016-10-05 11:55:50 +02:00
|
|
|
fmt.Println()
|
2015-11-20 15:23:12 +01:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var err error
|
|
|
|
opts.CurrentPath, err = filepath.Abs(filepath.Dir(os.Args[0]))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
opts.LogFile = path.Join(opts.CurrentPath, opts.LogFile)
|
|
|
|
opts.Exe = path.Base(os.Args[0])
|
|
|
|
|
2016-02-18 13:12:53 +01:00
|
|
|
flag.StringVar(&opts.Influxdb, "i", "", "influxdb server")
|
2016-11-10 09:01:10 +01:00
|
|
|
flag.StringVar(&dbs.MongoURI, "m", "", "Mongodb")
|
2017-03-07 17:42:53 +01:00
|
|
|
flag.StringVar(&dbs.Database, "d", "", "Mongodb Database")
|
|
|
|
flag.StringVar(&dbs.RedisURI, "r", "", "Redis")
|
2015-11-20 15:23:12 +01:00
|
|
|
flag.StringVar(&opts.LogFile, "l", opts.LogFile, "Logs filename")
|
2018-11-22 12:29:08 +01:00
|
|
|
flag.StringVar(&opts.Consul, "C", opts.Consul, "consul client")
|
2018-11-27 15:10:19 +01:00
|
|
|
flag.IntVar(&opts.Port, "P", 10500, "service check port")
|
2015-11-20 16:17:31 +01:00
|
|
|
flag.DurationVar(&opts.RedisTTL, "t", opts.RedisTTL, "Redis keys TTL")
|
2015-11-20 15:23:12 +01:00
|
|
|
flag.BoolVar(&opts.Version, "v", false, "Version")
|
2015-11-20 16:31:39 +01:00
|
|
|
flag.DurationVar(&opts.Timeout, "T", 0, "Running timeout")
|
2015-11-20 15:23:12 +01:00
|
|
|
flag.BoolVar(&opts.Debug, "D", false, "Debug")
|
2017-02-10 16:56:09 +01:00
|
|
|
flag.BoolVar(&opts.Test, "DD", false, "Test")
|
2015-11-24 12:28:22 +01:00
|
|
|
flag.IntVar(&opts.MaxError, "E", 100, "Max Mongodb Error")
|
2017-01-04 17:40:59 +01:00
|
|
|
flag.IntVar(&opts.Queue, "q", 2, "parallel consumer")
|
2018-10-24 09:33:08 +02:00
|
|
|
flag.Float64Var(&opts.Retention, "R", 15552000, "retention")
|
2015-11-20 15:23:12 +01:00
|
|
|
}
|