Skip to content

Commit

Permalink
Make Timeout configurable via a flag
Browse files Browse the repository at this point in the history
Signed-off-by: alban.hurtaud <[email protected]>
  • Loading branch information
ahurtaud committed Nov 22, 2019
1 parent 7ec30b1 commit 50a163b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,14 @@ import (
"gopkg.in/alecthomas/kingpin.v2"
)

// timeout specifies the number of iterations after which a metric times out,
// i.e. becomes stale and is removed from collectdCollector.valueLists. It is
// modeled and named after the top-level "Timeout" setting of collectd.
const timeout = 2

var (
listenAddress = kingpin.Flag("web.listen-address", "Address on which to expose metrics and web interface.").Default(":9103").String()
collectdAddress = kingpin.Flag("collectd.listen-address", "Network address on which to accept collectd binary network packets, e.g. \":25826\".").Default("").String()
collectdBuffer = kingpin.Flag("collectd.udp-buffer", "Size of the receive buffer of the socket used by collectd binary protocol receiver.").Default("0").Int()
collectdAuth = kingpin.Flag("collectd.auth-file", "File mapping user names to pre-shared keys (passwords).").Default("").String()
collectdSecurity = kingpin.Flag("collectd.security-level", "Minimum required security level for accepted packets. Must be one of \"None\", \"Sign\" and \"Encrypt\".").Default("None").String()
collectdTypesDB = kingpin.Flag("collectd.typesdb-file", "Collectd types.db file for datasource names mapping. Needed only if using a binary network protocol.").Default("").String()
collectdTimeout = kingpin.Flag("collectd.timeout", "Specifies the number of iterations after which a metric times out and is removed from collectdCollector.valueLists.").Default("2").Uint64()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose Prometheus metrics.").Default("/metrics").String()
collectdPostPath = kingpin.Flag("web.collectd-push-path", "Path under which to accept POST requests from collectd.").Default("/collectd-post").String()
lastPush = prometheus.NewGauge(
Expand All @@ -59,6 +55,11 @@ var (
},
)
metric_name_re = regexp.MustCompile("[^a-zA-Z0-9_:]")

// timeout specifies the number of iterations after which a metric times out,
// i.e. becomes stale and is removed from collectdCollector.valueLists. It is
// modeled and named after the top-level "Timeout" setting of collectd.
timeout time.Duration
)

// newName converts one data source of a value list to a string representation.
Expand Down Expand Up @@ -314,6 +315,8 @@ func main() {
flag.AddFlags(kingpin.CommandLine, promlogConfig)
kingpin.HelpFlag.Short('h')
kingpin.Parse()

timeout = time.Duration(*collectdTimeout)
logger := promlog.New(promlogConfig)

kingpin.Version(version.Print("collectd_exporter"))
Expand Down

0 comments on commit 50a163b

Please sign in to comment.