- Provide an example of this working with a uniform distribution.

This commit is contained in:
Matt T. Proud 2012-05-21 11:05:41 +02:00
parent a1f4f3eec2
commit fe4f71b333
2 changed files with 50 additions and 4 deletions

View File

@ -9,10 +9,10 @@ re-implementation should other folks need to consume and analyze such telemetry.
N.B. --- I have spent a bit of time working through the model in my head and N.B. --- I have spent a bit of time working through the model in my head and
probably haven't elucidated my ideas as clearly as I need to. If you examine probably haven't elucidated my ideas as clearly as I need to. If you examine
src/main.go and src/export/registry.go, you'll find an example of what type of examples/{simple,uniform_random}/main.go and registry.go, you'll find several
potential instrumentation use cases this package addresses. There are probably examples of what types of potential instrumentation use cases this package
numerous Go language idiomatic changes that need to be made, but this task has addresses. There are probably numerous Go language idiomatic changes that need
been deferred for now. to be made, but this task has been deferred for now.
# Continuous Integration # Continuous Integration
[![Build Status](https://secure.travis-ci.org/matttproud/golang_instrumentation.png?branch=master)](http://travis-ci.org/matttproud/golang_instrumentation) [![Build Status](https://secure.travis-ci.org/matttproud/golang_instrumentation.png?branch=master)](http://travis-ci.org/matttproud/golang_instrumentation)

View File

@ -0,0 +1,46 @@
// Copyright (c) 2012, 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.
// main.go provides a simple example of how to use this instrumentation
// framework in the context of having something that emits values into
// its collectors.
package main
import (
"github.com/matttproud/golang_instrumentation"
"github.com/matttproud/golang_instrumentation/maths"
"github.com/matttproud/golang_instrumentation/metrics"
"math/rand"
"net/http"
"time"
)
func main() {
foo_rpc_latency := metrics.CreateHistogram(&metrics.HistogramSpecification{
Starts: metrics.EquallySizedBucketsFor(0, 200, 4),
BucketMaker: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(10, maths.Average), 50),
ReportablePercentiles: []float64{0.01, 0.5, 0.90, 0.99},
})
foo_rpc_calls := &metrics.GaugeMetric{}
metrics := registry.NewRegistry()
metrics.Register("foo_rpc_latency_ms_histogram", foo_rpc_latency)
metrics.Register("foo_rpc_call_count", foo_rpc_calls)
go func() {
for {
foo_rpc_latency.Add(rand.Float64() * 200)
foo_rpc_calls.Increment()
time.Sleep(500 * time.Millisecond)
}
}()
exporter := metrics.YieldExporter()
http.Handle("/metrics.json", exporter)
http.ListenAndServe(":8080", nil)
}