From 4cab4a892e3f5958279709f2e92629038d420dc6 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Fri, 18 Jan 2013 15:47:40 +0100 Subject: [PATCH] Include instance uptime information in the stack. --- constants.go | 14 ++++++++++++ registry.go | 49 ++++------------------------------------- telemetry.go | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 45 deletions(-) create mode 100644 constants.go create mode 100644 telemetry.go diff --git a/constants.go b/constants.go new file mode 100644 index 0000000..0a7b2fc --- /dev/null +++ b/constants.go @@ -0,0 +1,14 @@ +/* +Copyright (c) 2013, Matt T. Proud +All rights reserved. + +Use of this source code is governed by a BSD-style license that can be found in +the LICENSE file. +*/ + +package registry + +var ( + // NilLabels is a nil set of labels merely for end-user convenience. + NilLabels map[string]string +) diff --git a/registry.go b/registry.go index 8fee82f..681e3a1 100644 --- a/registry.go +++ b/registry.go @@ -11,7 +11,6 @@ package registry import ( "encoding/base64" "encoding/json" - "github.com/matttproud/golang_instrumentation/maths" "github.com/matttproud/golang_instrumentation/metrics" "log" "net/http" @@ -21,48 +20,18 @@ import ( ) const ( - jsonContentType = "application/json" - contentType = "Content-Type" - jsonSuffix = ".json" authorization = "Authorization" + contentType = "Content-Type" + jsonContentType = "application/json" + jsonSuffix = ".json" ) -/* -Boilerplate metrics about the metrics reporting subservice. These are only -exposed if the DefaultRegistry's exporter is hooked into the HTTP request -handler. -*/ - -var requestCount *metrics.CounterMetric = &metrics.CounterMetric{} -var requestLatencyLogarithmicBuckets []float64 = metrics.LogarithmicSizedBucketsFor(0, 1000) -var requestLatencyEqualBuckets []float64 = metrics.EquallySizedBucketsFor(0, 1000, 10) -var requestLatencyLogarithmicAccumulating *metrics.Histogram = metrics.CreateHistogram(&metrics.HistogramSpecification{ - Starts: requestLatencyLogarithmicBuckets, - BucketMaker: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(50, maths.Average), 1000), - ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.9, 0.99}, -}) -var requestLatencyEqualAccumulating *metrics.Histogram = metrics.CreateHistogram(&metrics.HistogramSpecification{ - Starts: requestLatencyEqualBuckets, - BucketMaker: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(50, maths.Average), 1000), - ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.9, 0.99}, -}) -var requestLatencyLogarithmicTallying *metrics.Histogram = metrics.CreateHistogram(&metrics.HistogramSpecification{ - Starts: requestLatencyLogarithmicBuckets, - BucketMaker: metrics.TallyingBucketBuilder, - ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.9, 0.99}, -}) -var requestLatencyEqualTallying *metrics.Histogram = metrics.CreateHistogram(&metrics.HistogramSpecification{ - Starts: requestLatencyEqualBuckets, - BucketMaker: metrics.TallyingBucketBuilder, - ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.9, 0.99}, -}) - /* This callback accumulates the microsecond duration of the reporting framework's overhead such that it can be reported. */ var requestLatencyAccumulator metrics.CompletionCallback = func(duration time.Duration) { - microseconds := float64(int64(duration) / 1E3) + microseconds := float64(duration / time.Millisecond) requestLatencyLogarithmicAccumulating.Add(microseconds) requestLatencyEqualAccumulating.Add(microseconds) @@ -173,13 +142,3 @@ func (registry *Registry) YieldExporter() http.HandlerFunc { metrics.InstrumentCall(instrumentable, requestLatencyAccumulator) } } - -func init() { - 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) -} diff --git a/telemetry.go b/telemetry.go new file mode 100644 index 0000000..82c29f1 --- /dev/null +++ b/telemetry.go @@ -0,0 +1,62 @@ +/* +Copyright (c) 2013, Matt T. Proud +All rights reserved. + +Use of this source code is governed by a BSD-style license that can be found in +the LICENSE file. +*/ + +package registry + +import ( + "github.com/matttproud/golang_instrumentation/maths" + "github.com/matttproud/golang_instrumentation/metrics" + "time" +) + +/* +Boilerplate metrics about the metrics reporting subservice. These are only +exposed if the DefaultRegistry's exporter is hooked into the HTTP request +handler. +*/ +var ( + // TODO(matt): Refresh these names to support namespacing. + + requestCount *metrics.CounterMetric = &metrics.CounterMetric{} + requestLatencyLogarithmicBuckets []float64 = metrics.LogarithmicSizedBucketsFor(0, 1000) + requestLatencyEqualBuckets []float64 = metrics.EquallySizedBucketsFor(0, 1000, 10) + requestLatencyLogarithmicAccumulating *metrics.Histogram = metrics.CreateHistogram(&metrics.HistogramSpecification{ + Starts: requestLatencyLogarithmicBuckets, + BucketMaker: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(50, maths.Average), 1000), + ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.9, 0.99}, + }) + requestLatencyEqualAccumulating *metrics.Histogram = metrics.CreateHistogram(&metrics.HistogramSpecification{ + Starts: requestLatencyEqualBuckets, + BucketMaker: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(50, maths.Average), 1000), + ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.9, 0.99}, + }) + requestLatencyLogarithmicTallying *metrics.Histogram = metrics.CreateHistogram(&metrics.HistogramSpecification{ + Starts: requestLatencyLogarithmicBuckets, + BucketMaker: metrics.TallyingBucketBuilder, + ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.9, 0.99}, + }) + requestLatencyEqualTallying *metrics.Histogram = metrics.CreateHistogram(&metrics.HistogramSpecification{ + Starts: requestLatencyEqualBuckets, + BucketMaker: metrics.TallyingBucketBuilder, + ReportablePercentiles: []float64{0.01, 0.05, 0.5, 0.9, 0.99}, + }) + + startTime *metrics.GaugeMetric = &metrics.GaugeMetric{} +) + +func init() { + startTime.Set(float64(time.Now().Unix())) + + DefaultRegistry.Register("requests_metrics_total", "A counter of the total requests made against the telemetry system.", NilLabels, requestCount) + DefaultRegistry.Register("requests_metrics_latency_logarithmic_accumulating_microseconds", "A histogram of the response latency for requests made against the telemetry system.", NilLabels, requestLatencyLogarithmicAccumulating) + DefaultRegistry.Register("requests_metrics_latency_equal_accumulating_microseconds", "A histogram of the response latency for requests made against the telemetry system.", NilLabels, requestLatencyEqualAccumulating) + DefaultRegistry.Register("requests_metrics_latency_logarithmic_tallying_microseconds", "A histogram of the response latency for requests made against the telemetry system.", NilLabels, requestLatencyLogarithmicTallying) + DefaultRegistry.Register("request_metrics_latency_equal_tallying_microseconds", "A histogram of the response latency for requests made against the telemetry system.", NilLabels, requestLatencyEqualTallying) + + DefaultRegistry.Register("instance_start_time_seconds", "The time at which the current instance started (UTC).", NilLabels, startTime) +}