-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
65 lines (58 loc) · 2.28 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright © 2020 Circonus, Inc. <[email protected]>
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
package main
import (
"log"
"os"
"path/filepath"
"time"
"github.com/namsral/flag"
)
type config struct {
statsdHosts string
prefix string
tags string
tagFormat string
flushInterval time.Duration
runTime time.Duration
spawnDrift int
counters int
sampleRate float64
gauges int
timers int
valueMax int
valueMin int
timerSamples int
agents int
version bool
quiet bool
}
func genConfig() config {
c := config{}
defaultPrefix, err := os.Executable()
if err != nil {
log.Fatal(err)
}
flag.String(flag.DefaultConfigFlagname, "", "path to config file")
flag.StringVar(&c.statsdHosts, "statsd-hosts", "localhost:8125:udp", "comma separated list of ip:port:proto for statsD host(s)")
flag.StringVar(&c.prefix, "prefix", filepath.Base(defaultPrefix), "prefix for metrics")
flag.DurationVar(&c.runTime, "run-time", time.Duration(0), "how long to run, 0=forever")
flag.DurationVar(&c.flushInterval, "flush-interval", 10*time.Second, "how often to flush metrics")
flag.IntVar(&c.spawnDrift, "spawn-drift", 10, "spread new agent generation by 0-n seconds")
flag.StringVar(&c.tagFormat, "tag-format", "", "format of the tags to send. accepted values \"datadog\" or \"influx\"")
flag.StringVar(&c.tags, "tags", "", "list of K:V comma separated tags. Example: key1:tag1,key2:tag2")
flag.IntVar(&c.counters, "counters", 50, "number of counters for each agent to hold")
flag.IntVar(&c.valueMax, "value-max", 100, "maximum value")
flag.IntVar(&c.valueMin, "value-min", 0, "minimum value")
flag.IntVar(&c.gauges, "gauges", 30, "number of gauges for each agent to hold")
flag.IntVar(&c.timers, "timers", 20, "number of timers for each agent to hold")
flag.IntVar(&c.timerSamples, "timer-samples", 10, "number of timer samples per iteration")
flag.IntVar(&c.agents, "agents", 10, "max number of agents to run concurrently")
flag.Float64Var(&c.sampleRate, "sample-rate", 0, "sampling rate")
flag.BoolVar(&c.version, "version", false, "show version information")
flag.BoolVar(&c.quiet, "quiet", false, "run gen-statsd in quiet mode")
flag.Parse()
return c
}