.net client for prometheus.io
C# Batchfile
Latest commit 50a40f9 Jan 16, 2017 @andrasm committed on GitHub Merge pull request #38 from lakario/master
Added .NET 4.5 Support with Reactive 3.x - .NET 4.0 targeting Rx 2.2.5
Permalink
Failed to load latest commit information.
packages sorting out packages Mar 25, 2015
prometheus-net.NET40.tests Refactored main project to .shared project with .NET 4.5 and .NET 4.0… Jan 13, 2017
prometheus-net.NET40 Refactored main project to .shared project with .NET 4.5 and .NET 4.0… Jan 13, 2017
prometheus-net.NET45.tests Refactored main project to .shared project with .NET 4.5 and .NET 4.0… Jan 13, 2017
prometheus-net.NET45
prometheus-net.shared Refactored main project to .shared project with .NET 4.5 and .NET 4.0… Jan 13, 2017
prometheus-net.sharedtests Refactored main project to .shared project with .NET 4.5 and .NET 4.0… Jan 13, 2017
tester Refactored main project to .shared project with .NET 4.5 and .NET 4.0… Jan 13, 2017
.gitattributes initial commit Mar 25, 2015
.gitignore sorting out packages Mar 25, 2015
.travis.yml Updated travis build Jan 13, 2017
GlobalAssemblyInfo.cs Adjusted nuspec definition to include dependencies per target Jan 14, 2017
LICENSE
README.md added pushgateway support. refactored MetricServer and tester.fixes #19 Jul 24, 2016
deploy_nuget.bat Refactored main project to .shared project with .NET 4.5 and .NET 4.0… Jan 13, 2017
prometheus-net.nuspec Adjusted nuspec definition to include dependencies per target Jan 14, 2017
prometheus-net.sln Adjusted nuspec definition to include dependencies per target Jan 14, 2017

README.md

Prometheus .NET Client

Build Status

This is an experimental version (unofficial)

It's tested on Windows/.NET4 and Ubuntu/Mono 3.12.1.

See prometheus here

Installation

Nuget package: prometheus-net

Install-Package prometheus-net

Instrumenting

Four types of metric are offered: Counter, Gauge, Summary and Histogram. See the documentation on metric types and instrumentation best practices on how to use them.

Counter

Counters go up, and reset when the process restarts.

var counter = Metrics.CreateCounter("myCounter", "some help about this");
counter.Inc(5.5);

Gauge

Gauges can go up and down.

var gauge = Metrics.CreateGauge("gauge", "help text");
gauge.Inc(3.4);
gauge.Dec(2.1);
gauge.Set(5.3);

Summary

Summaries track the size and number of events.

var summary = Metrics.CreateSummary("mySummary", "help text");
summary.Observe(5.3);

Histogram

Histograms track the size and number of events in buckets. This allows for aggregatable calculation of quantiles.

var hist = Metrics.CreateHistogram("my_histogram", "help text", buckets: new[] { 0, 0.2, 0.4, 0.6, 0.8, 0.9 });
hist.Observe(0.4);

The default buckets are intended to cover a typical web/rpc request from milliseconds to seconds. They can be overridden passing in the buckets argument.

Labels

All metrics can have labels, allowing grouping of related time series.

See the best practices on naming and labels.

Taking a counter as an example:

var counter = Metrics.CreateCounter("myCounter", "help text", labelNames: new []{ "method", "endpoint"});
counter.Labels("GET", "/").Inc();
counter.Labels("POST", "/cancel").Inc();

HTTP handler

Metrics are usually exposed over HTTP, to be read by the Prometheus server.

var metricServer = new MetricServer(port: 1234);
metricServer.Start();

Pushgateway support

Metrics can be posted to a Pushgateway server over HTTP.

var metricServer = new MetricPusher(endpoint: "http://pushgateway.example.org:9091/metrics", job: "some_job");
metricServer.Start();

Unit testing

For simple usage the API uses static classes, which - in unit tests - can cause errors like this: "A collector with name '' has already been registered!"

To address this you can add this line to your test setup:

DefaultCollectorRegistry.Instance.Clear();