Ejemplo n.º 1
0
        public async Task LinearHistogram_metrics_are_exposed_correctly()
        {
            var metrics = new PrometheusMetrics();

            var histogram = metrics.Histogram()
                            .LinearBuckets(-10, 10, 12)
                            .Name("test_histogram")
                            .Help("This is the help")
                            .Register();

            histogram.Observe(21);

            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_histogram This is the help"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_histogram histogram"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"-10\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"0\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"10\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"20\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"30\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"40\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"50\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"60\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"70\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"80\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"90\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"100\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"+Inf\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_sum 21"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_count 1"));

            histogram.Observe(51);

            memstream = new MemoryStream();
            await metrics.Expose(memstream);

            lines = UTF8.GetString(memstream.ToArray()).Split('\n');

            Assert.Equal(1, lines.Count(s => s == "# HELP test_histogram This is the help"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_histogram histogram"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"-10\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"0\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"10\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"20\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"30\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"40\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"50\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"60\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"70\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"80\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"90\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"100\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"+Inf\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_sum 72"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_count 2"));
        }
Ejemplo n.º 2
0
        public async Task LabelledHistogram_metrics_are_exposed_correctly_in_cultures_with_non_point_decimal_separator()
        {
            var metrics = new PrometheusMetrics();

            var histogram = metrics.Histogram()
                            .Name("test_histogram")
                            .Buckets(-1.1, 2.2, 3.14159, 9)
                            .LabelNames("dolor")
                            .Help("Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam")
                            .Register();

            histogram.Labels("sit amet").Observe(-0.3);
            histogram.Labels("sit amet").Observe(2.99);

            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_histogram Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_histogram histogram"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{dolor=\"sit amet\", le=\"-1.1\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{dolor=\"sit amet\", le=\"2.2\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{dolor=\"sit amet\", le=\"3.14159\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{dolor=\"sit amet\", le=\"9\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{dolor=\"sit amet\", le=\"+Inf\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_sum{dolor=\"sit amet\"} 2.69"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_count{dolor=\"sit amet\"} 2"));
        }
Ejemplo n.º 3
0
        public async Task Histogram_metrics_are_exposed_correctly_in_cultures_with_non_point_decimal_separator()
        {
            var metrics = new PrometheusMetrics();

            var histogram = metrics.Histogram()
                            .Name("test_histogram")
                            .Buckets(-1.1, 2.2, 3.14159, 9)
                            .Help("Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit")
                            .Register();

            histogram.Observe(-0.3);
            histogram.Observe(2.99);

            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_histogram Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_histogram histogram"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"-1.1\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"2.2\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"3.14159\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"9\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"+Inf\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_sum 2.69"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_count 2"));
        }
        public Task PublishFault <T>(PublishContext <T> context, Exception exception)
            where T : class
        {
            PrometheusMetrics.MeasurePublish <T>(exception);

            return(Task.CompletedTask);
        }
        public Task PostConsume <T>(ConsumeContext <T> context, TimeSpan duration, string consumerType)
            where T : class
        {
            PrometheusMetrics.MeasureConsume(context, duration, consumerType);

            return(Task.CompletedTask);
        }
Ejemplo n.º 6
0
        public async Task LabelledGauge_replacevalue_replaces_obsoleted_values_and_new_values_are_exposed_correctly()
        {
            var metrics = new PrometheusMetrics();

            var gauge = metrics.Gauge()
                        .Name("test_gauge_total")
                        .Help("This is the help")
                        .LabelNames("method")
                        .Register();

            gauge.Labels("GET").Value  = 974;
            gauge.Labels("POST").Value = 823;

            gauge.ReplaceMetricValues(new Dictionary <string[], double>()
            {
                { new[] { "POST" }, 151 },
                { new[] { "HEAD" }, 673 },
            });

            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_gauge_total This is the help"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_gauge_total gauge"));
            Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_gauge_total{method=\"POST\"} 151 [0-9]+")));
            Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_gauge_total{method=\"HEAD\"} 673 [0-9]+")));

            Assert.Equal(0, lines.Count(s => Regex.IsMatch(s, "test_gauge_total{method=\"GET\"} 974 [0-9]+")));
        }
        public Task PostPublish <T>(PublishContext <T> context)
            where T : class
        {
            PrometheusMetrics.MeasurePublish <T>();

            return(Task.CompletedTask);
        }
Ejemplo n.º 8
0
        public void ConfigureServices(IServiceCollection services)
        {
            PrometheusMetrics.TryConfigure(Environment.ApplicationName);
            EventMapping.Map();

            var esConnection = ConfigureEsConnection(
                Configuration["EventStore:ConnectionString"],
                Environment.ApplicationName);
            var documentStore = ConfigureRavenDb(
                Configuration["RavenDb:Server"],
                Configuration["RavenDb:Database"]
                );

            var ravenDbStore = new RavenDBProvider(documentStore);

            services.AddSingleton(c => (Func <IAsyncDocumentSession>)GetSession);
            services.AddSingleton <IHostedService>(
                new EventStoreService(
                    esConnection,
                    Props.FromProducer(() =>
                                       new SubscriptionActor(
                                           esConnection,
                                           new RavenDbCheckpointStore(GetSession, "readmodels"),
                                           "ravenDbSubscription",
                                           (Props.FromProducer(
                                                () => new CustomerVehiclesProjection(ravenDbStore)), "customerVehicles"),
                                           (Props.FromProducer(
                                                () => new VehicleItemProjection(ravenDbStore)), "vehicleItems")
                                           )
                                       )
                    )
                );

            IAsyncDocumentSession GetSession() => documentStore.OpenAsyncSession();
        }
        public async Task <ActionResult> Post()
        {
            var rng = new Random();

            var forecast = new WeatherForecast
            {
                Id           = Guid.NewGuid().ToString("N"),
                Date         = DateTime.Now.AddDays(1),
                TemperatureC = rng.Next(-20, 55),
                Summary      = Summaries[rng.Next(Summaries.Length)]
            };

            const string collectionName = "weather";

            // await _database.GetCollection<WeatherForecast>(collectionName).InsertOneAsync(forecast);

            #region Metrics

            await PrometheusMetrics.Measure(
                () => _database.GetCollection <WeatherForecast>(collectionName).InsertOneAsync(forecast),
                PrometheusMetrics.DbUpdateTimer(collectionName),
                PrometheusMetrics.DBUpdateErrorCounter(collectionName)
                );

            #endregion Metrics

            return(Ok());
        }
        public Task ConsumeFault <T>(ConsumeContext <T> context, TimeSpan duration, string consumerType, Exception exception)
            where T : class
        {
            PrometheusMetrics.MeasureConsume(context, duration, consumerType, exception);

            return(Task.CompletedTask);
        }
        public Task SendFault <T>(SendContext <T> context, Exception exception)
            where T : class
        {
            PrometheusMetrics.MeasureSend <T>(exception);

            return(Task.CompletedTask);
        }
        public Task PostSend <T>(SendContext <T> context)
            where T : class
        {
            PrometheusMetrics.MeasureSend <T>();

            return(Task.CompletedTask);
        }
        public Task CompensateFail <TActivity, TLog>(CompensateActivityContext <TActivity, TLog> context, Exception exception)
            where TActivity : class, ICompensateActivity <TLog>
            where TLog : class
        {
            PrometheusMetrics.MeasureCompensate(context, exception);

            return(Task.CompletedTask);
        }
        public Task PostCompensate <TActivity, TLog>(CompensateActivityContext <TActivity, TLog> context)
            where TActivity : class, ICompensateActivity <TLog>
            where TLog : class
        {
            PrometheusMetrics.MeasureCompensate(context);

            return(Task.CompletedTask);
        }
        public Task ExecuteFault <TActivity, TArguments>(ExecuteActivityContext <TActivity, TArguments> context, Exception exception)
            where TActivity : class, IExecuteActivity <TArguments>
            where TArguments : class
        {
            PrometheusMetrics.MeasureExecute(context, exception);

            return(Task.CompletedTask);
        }
        public Task PostExecute <TActivity, TArguments>(ExecuteActivityContext <TActivity, TArguments> context)
            where TActivity : class, IExecuteActivity <TArguments>
            where TArguments : class
        {
            PrometheusMetrics.MeasureExecute(context);

            return(Task.CompletedTask);
        }
Ejemplo n.º 17
0
        public static IServiceCollection AddTestServices(this IServiceCollection services)
        {
            var metrics = new PrometheusMetrics();

            services.AddSingleton <IMetrics>(metrics);
            services.AddSingleton <HttpMetrics>();
            return(services);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Configure DI for using the Prometheus Metrics library.
        /// </summary>
        /// <param name="services"></param>
        public static void AddPrometheus(this IServiceCollection services)
        {
            var prometheus = new PrometheusMetrics();

            services.AddSingleton <IMetrics>(prometheus);
            services.AddSingleton <IExposable>(prometheus);

            services.AddSingleton <HttpMetrics, HttpMetrics>();
        }
Ejemplo n.º 19
0
        public static IServiceCollection AddPrometheusServer(this IServiceCollection services, IConfiguration configuration = null)
        {
            var metrics = new PrometheusMetrics();

            return(services.Configure <PrometheusServerOptions>(configuration ?? new ConfigurationBuilder().Build())
                   .AddSingleton <IMetrics>(metrics)
                   .AddSingleton <IExposable>(metrics)
                   .AddHostedService <PrometheusServer>());
        }
Ejemplo n.º 20
0
        public async Task ExponentialHistogram_metrics_are_exposed_correctly()
        {
            var metrics = new PrometheusMetrics();

            var histogram = metrics.Histogram()
                            .ExponentialBuckets(1, 2, 8)
                            .Name("test_histogram")
                            .Help("This is the help")
                            .Register();

            histogram.Observe(21);

            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_histogram This is the help"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_histogram histogram"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"1\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"2\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"4\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"8\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"16\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"32\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"64\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"128\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"+Inf\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_sum 21"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_count 1"));

            histogram.Observe(51);

            memstream = new MemoryStream();
            await metrics.Expose(memstream);

            lines = UTF8.GetString(memstream.ToArray()).Split('\n');

            Assert.Equal(1, lines.Count(s => s == "# HELP test_histogram This is the help"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_histogram histogram"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"1\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"2\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"4\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"8\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"16\"} 0"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"32\"} 1"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"64\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"128\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_bucket{le=\"+Inf\"} 2"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_sum 72"));
            Assert.Equal(1, lines.Count(s => s == "test_histogram_count 2"));
        }
        public void Passing_null_to_PushAsync_throws_ArgumentNullException()
        {
            var mh = new FakeMessageHandler();

            using (var pushgateway = new PushGateway(new HttpClient(mh)
            {
                BaseAddress = new Uri("http://example.com/")
            }))
            {
                var m = new PrometheusMetrics();

                Assert.ThrowsAsync <ArgumentNullException>(() => pushgateway.PushAsync(null, "jobname"));
                Assert.ThrowsAsync <ArgumentNullException>(() => pushgateway.PushAsync(m, null));
            }
        }
Ejemplo n.º 22
0
        public void ConfigureServices(IServiceCollection services)
        {
            PrometheusMetrics.TryConfigure(Environment.ApplicationName);
            MapEvents();

            var esConnection = ConfigureEsConnection(
                Configuration["EventStore:ConnectionString"],
                Environment.ApplicationName);

            var store =
                new MeasuredStore(
                    new AggregateStore(esConnection));

            var customerService = new CustomerCommandService(store);

            var bus =
                MassTransitConfiguration.ConfigureBus(
                    "rabbitmq://localhost", "guest", "guest",
                    ("talk-customer", ep =>
            {
                ep.Handler <Messages.Customer.Commands.RegisterCustomer>(
                    ctx => customerService.Handle(ctx.Message));
            }));

            services.AddMassTransit(bus);

            var reactorsSubscriptionManager = new SubscriptionManager(
                esConnection,
                new EsCheckpointStore(esConnection, "reactors-checkpoint"),
                "commandsReactors",
                ConfigureReactors()
                );

            services.AddSingleton <IHostedService>(
                new EventStoreService(
                    esConnection,
                    reactorsSubscriptionManager)
                );

            Log.SetLoggerFactory(LoggerFactory);
            services.AddSingleton <IHostedService>(provider =>
                                                   new ProtoClusterHostedService(
                                                       new Uri(Configuration["Proto:ConsulUrl"]),
                                                       Configuration["Proto:ClusterName"],
                                                       "localhost",
                                                       Configuration.GetValue <int>("Proto:NodePort"),
                                                       esConnection));
        }
Ejemplo n.º 23
0
        public async Task Gauge_metrics_are_exposed_correctly()
        {
            var metrics = new PrometheusMetrics();

            var gauge = metrics.Gauge()
                        .Name("test_gauge_total")
                        .Help("This is the help")
                        .Register();

            gauge.Value = 9374;

            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_gauge_total This is the help"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_gauge_total gauge"));
            Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_gauge_total 9374 [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");
            }
        }
Ejemplo n.º 25
0
        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")));
        }
Ejemplo n.º 26
0
        public async Task Gauge_metrics_are_exposed_correctly_in_cultures_with_non_point_decimal_separator()
        {
            var metrics = new PrometheusMetrics();

            var gauge = metrics.Gauge()
                        .Name("test_gauge_total")
                        .Help("Duis aute irure dolor in reprehenderit in voluptate velit esse")
                        .Register();

            gauge.Value = 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_gauge_total Duis aute irure dolor in reprehenderit in voluptate velit esse"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_gauge_total gauge"));
            Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_gauge_total 3.14159 [0-9]+")));
        }
Ejemplo n.º 27
0
        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]+")));
        }
Ejemplo n.º 28
0
        public async Task LabelledGauge_metrics_are_exposed_correctly_in_cultures_with_non_point_decimal_separator()
        {
            var metrics = new PrometheusMetrics();

            var gauge = metrics.Gauge()
                        .Name("test_labelled_gauge_total")
                        .LabelNames("lorem")
                        .Help("Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium")
                        .Register();

            gauge.Labels("ipsum").Value = 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_gauge_total Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium"));
            Assert.Equal(1, lines.Count(s => s == "# TYPE test_labelled_gauge_total gauge"));
            Assert.Equal(1, lines.Count(s => Regex.IsMatch(s, "test_labelled_gauge_total{lorem=\"ipsum\"} 2.71828 [0-9]+")));
        }
Ejemplo n.º 29
0
        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]+")));
        }
Ejemplo n.º 30
0
        async Task EventAppeared(
            EventStoreCatchUpSubscription _,
            ResolvedEvent resolvedEvent)
        {
            if (resolvedEvent.Event.EventType.StartsWith("$"))
            {
                return;
            }

            var @event = resolvedEvent.Deserialze();

            _log.Debug("Projecting event {event}", @event.ToString());

            try
            {
                await PrometheusMetrics.Measure(async() =>
                {
                    await Task.WhenAll(_eventHandlers.Select(x => x(@event)));

                    await _checkpointStore.StoreCheckpoint(
                        resolvedEvent.OriginalPosition.Value
                        );
                }, PrometheusMetrics.SubscriptionTimer(_subscriptionName));

                PrometheusMetrics.ObserveLeadTime(
                    resolvedEvent.Event.EventType,
                    resolvedEvent.Event.Created,
                    _subscriptionName);
            }
            catch (Exception e)
            {
                _log.Error(
                    e,
                    "Error occured when projecting the event {event}",
                    @event
                    );
                throw;
            }
        }