Skip to content

Commit

Permalink
Expose all metrics via /metrics endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Jan 30, 2020
1 parent 751b8d8 commit f8de78e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# GPFS Prometheus exporter

The GPFS exporter collects metrics from the GPFS filesystem.
The exporter supports the `/metrics` endpoint with data about the exporter and the `/gpfs` endpoint used to collect GPFS metrics.
The exporter supports the `/metrics` endpoint to gather GPFS metrics an metrics about the exporter.

## Collectors

Expand Down
17 changes: 10 additions & 7 deletions cmd/gpfs_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
)

var (
listenAddr = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9303").String()
listenAddr = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9303").String()
disableExporterMetrics = kingpin.Flag("web.disable-exporter-metrics", "Exclude metrics about the exporter (promhttp_*, process_*, go_*)").Default("false").Bool()
)

func gpfsHandler() http.HandlerFunc {
Expand All @@ -27,8 +28,13 @@ func gpfsHandler() http.HandlerFunc {
registry.MustRegister(collector)
}

gatherers := prometheus.Gatherers{registry}
if !*disableExporterMetrics {
gatherers = append(gatherers, prometheus.DefaultGatherer)
}

// Delegate http serving to Prometheus client library, which will call collector.Collect.
h := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
h := promhttp.HandlerFor(gatherers, promhttp.HandlerOpts{})
h.ServeHTTP(w, r)
}
}
Expand All @@ -43,16 +49,13 @@ func main() {
log.Infoln("Build context", version.BuildContext())
log.Infof("Starting Server: %s", *listenAddr)

http.Handle("/metrics", promhttp.Handler())
http.Handle("/gpfs", gpfsHandler())
http.Handle("/metrics", gpfsHandler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>GPFS Exporter</title></head>
<body>
<h1>Metrics Exporter</h1>
<h1>GPFS Metrics Exporter</h1>
<p><a href='/metrics'>Metrics</a></p>
<h1>GPFS Exporter</h1>
<p><a href='/gpfs'>GPFS Metrics</a></p>
</body>
</html>`))
})
Expand Down

0 comments on commit f8de78e

Please sign in to comment.