mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-28 23:19:46 -08:00
Merge pull request #167 from pborzenkov/filter-collectors
Filter list of collectors enabled by default
This commit is contained in:
commit
1384becb12
|
@ -41,8 +41,10 @@ var (
|
||||||
memProfile = flag.String("debug.memprofile-file", "", "Write memory profile to this file upon receipt of SIGUSR1.")
|
memProfile = flag.String("debug.memprofile-file", "", "Write memory profile to this file upon receipt of SIGUSR1.")
|
||||||
listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.")
|
listenAddress = flag.String("web.listen-address", ":9100", "Address on which to expose metrics and web interface.")
|
||||||
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
|
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
|
||||||
enabledCollectors = flag.String("collectors.enabled", "diskstats,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname", "Comma-separated list of collectors to use.")
|
enabledCollectors = flag.String("collectors.enabled",
|
||||||
printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.")
|
filterAvailableCollectors("diskstats,filefd,filesystem,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname"),
|
||||||
|
"Comma-separated list of collectors to use.")
|
||||||
|
printCollectors = flag.Bool("collectors.print", false, "If true, print available collectors and exit.")
|
||||||
|
|
||||||
collectorLabelNames = []string{"collector", "result"}
|
collectorLabelNames = []string{"collector", "result"}
|
||||||
|
|
||||||
|
@ -81,6 +83,17 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) {
|
||||||
scrapeDurations.Collect(ch)
|
scrapeDurations.Collect(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filterAvailableCollectors(collectors string) string {
|
||||||
|
availableCollectors := make([]string, 0)
|
||||||
|
for _, c := range strings.Split(collectors, ",") {
|
||||||
|
_, ok := collector.Factories[c]
|
||||||
|
if ok {
|
||||||
|
availableCollectors = append(availableCollectors, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.Join(availableCollectors, ",")
|
||||||
|
}
|
||||||
|
|
||||||
func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
|
func execute(name string, c collector.Collector, ch chan<- prometheus.Metric) {
|
||||||
begin := time.Now()
|
begin := time.Now()
|
||||||
err := c.Update(ch)
|
err := c.Update(ch)
|
||||||
|
|
Loading…
Reference in a new issue