Skip to content

Commit

Permalink
Merge pull request prometheus#9 from matttproud/feature/base-labels-o…
Browse files Browse the repository at this point in the history
…n-registration

Add ``baseLabels`` to the registration signature.
  • Loading branch information
juliusv committed Jan 15, 2013
2 parents 32452fc + 1134be8 commit d670eba
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
15 changes: 9 additions & 6 deletions examples/random/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,15 @@ func main() {
zed_rpc_calls := &metrics.CounterMetric{}

metrics := registry.NewRegistry()
metrics.Register("rpc_latency_foo_microseconds", "RPC latency for foo service.", foo_rpc_latency)
metrics.Register("rpc_calls_foo_total", "RPC calls for foo service.", foo_rpc_calls)
metrics.Register("rpc_latency_bar_microseconds", "RPC latency for bar service.", bar_rpc_latency)
metrics.Register("rpc_calls_bar_total", "RPC calls for bar service.", bar_rpc_calls)
metrics.Register("rpc_latency_zed_microseconds", "RPC latency for zed service.", zed_rpc_latency)
metrics.Register("rpc_calls_zed_total", "RPC calls for zed service.", zed_rpc_calls)

nilBaseLabels := make(map[string]string)

metrics.Register("rpc_latency_foo_microseconds", "RPC latency for foo service.", nilBaseLabels, foo_rpc_latency)
metrics.Register("rpc_calls_foo_total", "RPC calls for foo service.", nilBaseLabels, foo_rpc_calls)
metrics.Register("rpc_latency_bar_microseconds", "RPC latency for bar service.", nilBaseLabels, bar_rpc_latency)
metrics.Register("rpc_calls_bar_total", "RPC calls for bar service.", nilBaseLabels, bar_rpc_calls)
metrics.Register("rpc_latency_zed_microseconds", "RPC latency for zed service.", nilBaseLabels, zed_rpc_latency)
metrics.Register("rpc_calls_zed_total", "RPC calls for zed service.", nilBaseLabels, zed_rpc_calls)

go func() {
for {
Expand Down
18 changes: 10 additions & 8 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ var DefaultRegistry = NewRegistry()
/*
Associate a Metric with the DefaultRegistry.
*/
func Register(name, unusedDocstring string, metric metrics.Metric) {
DefaultRegistry.Register(name, unusedDocstring, metric)
func Register(name, unusedDocstring string, unusedBaseLabels map[string]string, metric metrics.Metric) {
DefaultRegistry.Register(name, unusedDocstring, unusedBaseLabels, metric)
}

/*
Register a metric with a given name. Name should be globally unique.
*/
func (r *Registry) Register(name, unusedDocstring string, metric metrics.Metric) {
func (r *Registry) Register(name, unusedDocstring string, unusedBaseLabels map[string]string, metric metrics.Metric) {
r.mutex.Lock()
defer r.mutex.Unlock()

Expand Down Expand Up @@ -175,9 +175,11 @@ func (registry *Registry) YieldExporter() http.HandlerFunc {
}

func init() {
DefaultRegistry.Register("requests_metrics_total", "A counter of the total requests made against the telemetry system.", requestCount)
DefaultRegistry.Register("requests_metrics_latency_logarithmic_accumulating_microseconds", "A histogram of the response latency for requests made against the telemetry system.", requestLatencyLogarithmicAccumulating)
DefaultRegistry.Register("requests_metrics_latency_equal_accumulating_microseconds", "A histogram of the response latency for requests made against the telemetry system.", requestLatencyEqualAccumulating)
DefaultRegistry.Register("requests_metrics_latency_logarithmic_tallying_microseconds", "A histogram of the response latency for requests made against the telemetry system.", requestLatencyLogarithmicTallying)
DefaultRegistry.Register("request_metrics_latency_equal_tallying_microseconds", "A histogram of the response latency for requests made against the telemetry system.", requestLatencyEqualTallying)
nilBaseLabels := make(map[string]string)

DefaultRegistry.Register("requests_metrics_total", "A counter of the total requests made against the telemetry system.", nilBaseLabels, requestCount)
DefaultRegistry.Register("requests_metrics_latency_logarithmic_accumulating_microseconds", "A histogram of the response latency for requests made against the telemetry system.", nilBaseLabels, requestLatencyLogarithmicAccumulating)
DefaultRegistry.Register("requests_metrics_latency_equal_accumulating_microseconds", "A histogram of the response latency for requests made against the telemetry system.", nilBaseLabels, requestLatencyEqualAccumulating)
DefaultRegistry.Register("requests_metrics_latency_logarithmic_tallying_microseconds", "A histogram of the response latency for requests made against the telemetry system.", nilBaseLabels, requestLatencyLogarithmicTallying)
DefaultRegistry.Register("request_metrics_latency_equal_tallying_microseconds", "A histogram of the response latency for requests made against the telemetry system.", nilBaseLabels, requestLatencyEqualTallying)
}

0 comments on commit d670eba

Please sign in to comment.