public async Task Counter_metrics_are_exposed_correctly_when_requested_without_timestamp() { var metrics = new PrometheusMetrics(); var counter = metrics.Counter() .Name("test_counter_total") .Help("This is the help") .Register(); counter.Increment(); var memstream = new MemoryStream(); await metrics.Expose(memstream, ExposeOptions.NoTimestamp); var lines = UTF8.GetString(memstream.ToArray()).Split('\n'); Assert.Equal(1, lines.Count(s => s == "# HELP test_counter_total This is the help")); Assert.Equal(1, lines.Count(s => s == "# TYPE test_counter_total counter")); Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_counter_total 1"))); }
public async Task Counter_metrics_are_exposed_correctly_in_cultures_with_non_point_decimal_separator() { var metrics = new PrometheusMetrics(); var counter = metrics.Counter() .Name("test_counter_total") .Help("Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur") .Register(); counter.Increment(3.14159); var memstream = new MemoryStream(); await metrics.Expose(memstream); var lines = UTF8.GetString(memstream.ToArray()).Split('\n'); Assert.Equal(1, lines.Count(s => s == "# HELP test_counter_total Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur")); Assert.Equal(1, lines.Count(s => s == "# TYPE test_counter_total counter")); Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_counter_total 3.14159 [0-9]+"))); }
public async Task Exposing_a_metric_includes_custom_metrics_without_timestamp() { var mh = new FakeMessageHandler(); using (var pgw = new PushGateway(new HttpClient(mh) { BaseAddress = new Uri("http://example.com/") })) { var m = new PrometheusMetrics(); var c = m.Counter().Name("test_counter").Help("This is the help text").Register(); c.Increment(); await pgw.PushAsync(m, "exampleapp"); mh.Content.Should().Contain("# HELP test_counter This is the help text\n"); mh.Content.Should().Contain("test_counter 1\n"); } }
public async Task LabelledCounter_metrics_are_exposed_correctly_in_cultures_with_non_point_decimal_separator() { var metrics = new PrometheusMetrics(); var counter = metrics.Counter() .Name("test_labelled_counter_total") .LabelNames("consectetur") .Help("Öt szép szűzlány őrült írót nyúz, avagy kínaiul: 五美麗的處女瘋狂作家去皮") .Register(); counter.Labels("adipiscing").Increment(2.71828); var memstream = new MemoryStream(); await metrics.Expose(memstream); var lines = UTF8.GetString(memstream.ToArray()).Split('\n'); Assert.Equal(1, lines.Count(s => s == "# HELP test_labelled_counter_total Öt szép szűzlány őrült írót nyúz, avagy kínaiul: 五美麗的處女瘋狂作家去皮")); Assert.Equal(1, lines.Count(s => s == "# TYPE test_labelled_counter_total counter")); Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_labelled_counter_total{consectetur=\"adipiscing\"} 2.71828 [0-9]+"))); }
public async Task LabelledCounter_metrics_are_exposed_correctly() { var metrics = new PrometheusMetrics(); var counter = metrics.Counter() .Name("test_counter_total") .Help("This is the help") .LabelNames("method") .Register(); counter.Labels("GET").Increment(); counter.Labels("POST").Increment(); counter.Labels("POST").Increment(); var memstream = new MemoryStream(); await metrics.Expose(memstream); var lines = UTF8.GetString(memstream.ToArray()).Split('\n'); Assert.Equal(1, lines.Count(s => s == "# HELP test_counter_total This is the help")); Assert.Equal(1, lines.Count(s => s == "# TYPE test_counter_total counter")); Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_counter_total{method=\"GET\"} 1 [0-9]+"))); Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_counter_total{method=\"POST\"} 2 [0-9]+"))); }
public static void Main(string[] args) { IMetrics metrics = new PrometheusMetrics(); var planningTime = metrics.Gauge() .Name("planning_time").Help("The processing time in seconds").LabelNames("solver").Register(); var planningCount = metrics.Counter() .Name("planning_count").Help("The count of planning").LabelNames("solver").Register(); var totalPlanningCount = metrics.Counter() .Name("plannning_count_total").Help("Total count of plannings").Register(); var totalRunning = metrics.Gauge() .Name("plannning_running_total").Help("Currently running plannings").Register(); var planningStartTime = metrics.Gauge() .Name("planning_start_time").Help("Start time of last planning").Register(); var planningTimeHistogram = metrics.Histogram() .LinearBuckets(0, 300, 10) .Name("planning_duration_times") .Help("Duration of plannings in ms") .Register(); var planningTimeHistogramForSolver = metrics.Histogram() .LinearBuckets(0, 300, 10) .Name("planning_duration_times_for_solver") .Help("Duration of plannings in ms for different solvers") .LabelNames("solver") .Register(); var pgw = new PushGateway( new Uri("http://127.0.0.1:9091"), "example_app", new List <Tuple <string, string> > { Tuple.Create("environment", "test") } ); Task.Run(async() => { var pm = metrics as PrometheusMetrics; var output = Console.OpenStandardOutput(); for (;;) { Console.WriteLine("# Waiting"); await Task.Delay(TimeSpan.FromSeconds(10)); Console.WriteLine("# Exposing"); await pm.Expose(output); Console.WriteLine("# Done"); try { await pgw.PushAsync(pm, "example_app:9000"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }); foreach (var solver in new[] { "Static", "Dynamic" }) { Task.Run(() => { var rnd = new Random(solver.GetHashCode()); for (;;) { using (planningTime.Labels(solver).Timer()) { totalPlanningCount.Increment(); planningCount.Labels(solver).Increment(); planningStartTime.SetToCurrentTime(); totalRunning.TrackInProgress(() => { var planningSleep = rnd.Next(5000); Thread.Sleep(planningSleep); planningTimeHistogram.Observe(planningSleep); planningTimeHistogramForSolver.Labels(solver).Observe(planningSleep); }); } } }); } Console.ReadLine(); }