Skip to content

Commit

Permalink
add: run-time option
Browse files Browse the repository at this point in the history
  • Loading branch information
maier committed Jan 7, 2021
1 parent 7d8bdd0 commit 3e3aa52
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 11 additions & 2 deletions agent.go
Expand Up @@ -42,6 +42,7 @@ type Agent struct {

//NewAgentController creates a new agent pool
func NewAgentController() *AgentController {
rand.Seed(time.Now().UnixNano())
ctx, cancel := context.WithCancel(context.Background())
return &AgentController{
sig: make(chan os.Signal, 1),
Expand All @@ -54,8 +55,16 @@ func NewAgentController() *AgentController {
//Start kicks off the main process of sending statsD metrics from agents
func (ac *AgentController) Start(c config) error {

SignalNotifySetup(ac.sig)
go HandleSignals(ac.cncl, ac.sig)
if c.runTime > time.Duration(0) {
go func() {
time.Sleep(c.runTime)
log.Printf("run time (%s) reached, cancelling", c.runTime.String())
ac.cncl()
}()
}

ac.signalNotifySetup()
go ac.handleSignals()

targets := strings.Split(c.statsdHosts, ",")
statsdClients := make([]*statsd.Client, 0)
Expand Down
2 changes: 2 additions & 0 deletions config.go
Expand Up @@ -20,6 +20,7 @@ type config struct {
tags string
tagFormat string
flushInterval time.Duration
runTime time.Duration
spawnDrift int
counters int
gauges int
Expand All @@ -41,6 +42,7 @@ func genConfig() config {
flag.String(flag.DefaultConfigFlagname, "", "path to config file")
flag.StringVar(&c.statsdHosts, "statsd-host", "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\"")
Expand Down

0 comments on commit 3e3aa52

Please sign in to comment.