mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-03-06 02:26:36 +00:00
feat: Allow default metrics to be disabled
Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
24
exporter.go
24
exporter.go
@@ -269,6 +269,10 @@ func main() {
|
|||||||
"telemetry.path",
|
"telemetry.path",
|
||||||
"URL path for surfacing collected metrics.",
|
"URL path for surfacing collected metrics.",
|
||||||
).Default("/metrics").String()
|
).Default("/metrics").String()
|
||||||
|
disableExporterMetrics = kingpin.Flag(
|
||||||
|
"web.disable-exporter-metrics",
|
||||||
|
"Exclude metrics about the exporter itself (promhttp_*, process_*, go_*).",
|
||||||
|
).Bool()
|
||||||
maxRequests = kingpin.Flag(
|
maxRequests = kingpin.Flag(
|
||||||
"telemetry.max-requests",
|
"telemetry.max-requests",
|
||||||
"Maximum number of concurrent requests. 0 to disable.",
|
"Maximum number of concurrent requests. 0 to disable.",
|
||||||
@@ -347,7 +351,8 @@ func main() {
|
|||||||
log.Infof("Enabled collectors: %v", strings.Join(keys(collectors), ", "))
|
log.Infof("Enabled collectors: %v", strings.Join(keys(collectors), ", "))
|
||||||
|
|
||||||
h := &metricsHandler{
|
h := &metricsHandler{
|
||||||
timeoutMargin: *timeoutMargin,
|
timeoutMargin: *timeoutMargin,
|
||||||
|
includeExporterMetrics: *disableExporterMetrics,
|
||||||
collectorFactory: func(timeout time.Duration, requestedCollectors []string) (error, *windowsCollector) {
|
collectorFactory: func(timeout time.Duration, requestedCollectors []string) (error, *windowsCollector) {
|
||||||
filteredCollectors := make(map[string]collector.Collector)
|
filteredCollectors := make(map[string]collector.Collector)
|
||||||
// scrape all enabled collectors if no collector is requested
|
// scrape all enabled collectors if no collector is requested
|
||||||
@@ -450,8 +455,9 @@ func withConcurrencyLimit(n int, next http.HandlerFunc) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type metricsHandler struct {
|
type metricsHandler struct {
|
||||||
timeoutMargin float64
|
timeoutMargin float64
|
||||||
collectorFactory func(timeout time.Duration, requestedCollectors []string) (error, *windowsCollector)
|
includeExporterMetrics bool
|
||||||
|
collectorFactory func(timeout time.Duration, requestedCollectors []string) (error, *windowsCollector)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mh *metricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (mh *metricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -479,11 +485,13 @@ func (mh *metricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
reg.MustRegister(wc)
|
reg.MustRegister(wc)
|
||||||
reg.MustRegister(
|
if !mh.includeExporterMetrics {
|
||||||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
reg.MustRegister(
|
||||||
collectors.NewGoCollector(),
|
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||||
version.NewCollector("windows_exporter"),
|
collectors.NewGoCollector(),
|
||||||
)
|
version.NewCollector("windows_exporter"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
h := promhttp.HandlerFor(reg, promhttp.HandlerOpts{})
|
h := promhttp.HandlerFor(reg, promhttp.HandlerOpts{})
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
|
|||||||
Reference in New Issue
Block a user