Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metricsregistry #120

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ func (c *CounterContainer) Get(metricName string, labels prometheus.Labels, help
Help: help,
ConstLabels: labels,
})
if err := prometheus.Register(counter); err != nil {
metric := &Metric{
Name: metricName,
Help: defaultHelp,
M: counter,
}
if err := registry.Register(hash, metric); err != nil {
return nil, err
}
c.Elements[hash] = counter
Expand All @@ -107,7 +112,12 @@ func (c *GaugeContainer) Get(metricName string, labels prometheus.Labels, help s
Help: help,
ConstLabels: labels,
})
if err := prometheus.Register(gauge); err != nil {
metric := &Metric{
Name: metricName,
Help: defaultHelp,
M: gauge,
}
if err := registry.Register(hash, metric); err != nil {
return nil, err
}
c.Elements[hash] = gauge
Expand Down Expand Up @@ -135,7 +145,12 @@ func (c *SummaryContainer) Get(metricName string, labels prometheus.Labels, help
Help: help,
ConstLabels: labels,
})
if err := prometheus.Register(summary); err != nil {
metric := &Metric{
Name: metricName,
Help: defaultHelp,
M: summary,
}
if err := registry.Register(hash, metric); err != nil {
return nil, err
}
c.Elements[hash] = summary
Expand Down
22 changes: 13 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/howeyc/fsnotify"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
)
Expand All @@ -32,24 +33,27 @@ func init() {
}

var (
listenAddress = flag.String("web.listen-address", ":9102", "The address on which to expose the web interface and generated Prometheus metrics.")
metricsEndpoint = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics.")
statsdListenAddress = flag.String("statsd.listen-address", "", "The UDP address on which to receive statsd metric lines. DEPRECATED, use statsd.listen-udp instead.")
statsdListenUDP = flag.String("statsd.listen-udp", ":9125", "The UDP address on which to receive statsd metric lines. \"\" disables it.")
statsdListenTCP = flag.String("statsd.listen-tcp", ":9125", "The TCP address on which to receive statsd metric lines. \"\" disables it.")
mappingConfig = flag.String("statsd.mapping-config", "", "Metric mapping configuration file name.")
readBuffer = flag.Int("statsd.read-buffer", 0, "Size (in bytes) of the operating system's transmit read buffer associated with the UDP connection. Please make sure the kernel parameters net.core.rmem_max is set to a value greater than the value specified.")
showVersion = flag.Bool("version", false, "Print version information.")
listenAddress = flag.String("web.listen-address", ":9102", "The address on which to expose the web interface and generated Prometheus metrics.")
metricsEndpoint = flag.String("web.telemetry-path", "/statsd", "Path under which to expose the collected statsd metrics.")
exporterMetricsEndpoint = flag.String("web.exporter-telemetry-path", "/metrics", "Path under which to expose metrics related to the exporter (not the statsd metrics).")
statsdListenAddress = flag.String("statsd.listen-address", "", "The UDP address on which to receive statsd metric lines. DEPRECATED, use statsd.listen-udp instead.")
statsdListenUDP = flag.String("statsd.listen-udp", ":9125", "The UDP address on which to receive statsd metric lines. \"\" disables it.")
statsdListenTCP = flag.String("statsd.listen-tcp", ":9125", "The TCP address on which to receive statsd metric lines. \"\" disables it.")
mappingConfig = flag.String("statsd.mapping-config", "", "Metric mapping configuration file name.")
readBuffer = flag.Int("statsd.read-buffer", 0, "Size (in bytes) of the operating system's transmit read buffer associated with the UDP connection. Please make sure the kernel parameters net.core.rmem_max is set to a value greater than the value specified.")
showVersion = flag.Bool("version", false, "Print version information.")
)

func serveHTTP() {
http.Handle(*metricsEndpoint, prometheus.Handler())
http.Handle(*exporterMetricsEndpoint, prometheus.Handler())
http.Handle(*metricsEndpoint, promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>StatsD Bridge</title></head>
<body>
<h1>StatsD Bridge</h1>
<p><a href="` + *metricsEndpoint + `">Metrics</a></p>
<p><a href="` + *exporterMetricsEndpoint + `">Exporter Metrics</a></p>
</body>
</html>`))
})
Expand Down
Loading