public void Setup()
        {
            var factory = new MetricFactory(new CollectorRegistry());

            _summary = factory.CreateSummary("summary", string.Empty, "label1", "label2");
            _rnd     = new Random();
        }
        public void Setup()
        {
            var factory = new MetricFactory(new CollectorRegistry());

            _histogram = factory.CreateHistogram("histogram", string.Empty, "label1", "label2");
            _rnd       = new Random();
        }
Exemple #3
0
        public static void IncTo <TLabels>(this IMetricFamily <ICounter, TLabels> metricFamily, double value, DateTimeOffset timestamp)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.IncTo(value, timestamp);
        }
        public static void Set <TLabels>(this IMetricFamily <IUntyped, TLabels> metricFamily, double val, DateTimeOffset timestamp)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Set(val, timestamp);
        }
Exemple #5
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="options">Prometheus metrics options</param>
 public PrometheusMetricsMiddleware(IOptions <PrometheusMetricsOptions> options)
 {
     _options   = options;
     _histogram = Metrics.DefaultFactory
                  .CreateHistogram(
         "http_request_duration_seconds",
         "duration histogram of http responses labeled with: status_code, method, path",
         "status_code", "method", "path");
 }
Exemple #6
0
        public static void Inc <TLabels>(this IMetricFamily <ICounter <long>, TLabels> metricFamily, long increment = 1)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Inc(increment);
        }
        public static void DecTo <TLabels>(this IMetricFamily <IGauge <long>, TLabels> metricFamily, long value, long timestamp)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.DecTo(value, timestamp);
        }
        public static void Observe <TLabels>(this IMetricFamily <ISummary, TLabels> metricFamily, double val, DateTimeOffset timestamp)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Observe(val, timestamp.ToUnixTimeMilliseconds());
        }
        public static void Observe <TLabels>(this IMetricFamily <ISummary, TLabels> metricFamily, double val)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Observe(val);
        }
        /// <summary>
        ///     Constructor
        /// </summary>
        /// <param name="options">Options for PrometheusHealthCheckPublisher</param>
        public PrometheusHealthCheckPublisher(PrometheusHealthCheckPublisherOptions options)
        {
            var metricFactory = new MetricFactory(options.CollectorRegistry);

            _status = metricFactory.CreateGauge(options.StatusMetricName,
                                                "Shows raw health check status (0 = Unhealthy, 1 = Degraded, 2 = Healthy)", "name");
            _duration = metricFactory.CreateGauge(options.DurationMetricName,
                                                  "Shows duration of the health check execution in seconds", "name");
        }
Exemple #11
0
        public static void IncTo <TLabels>(this IMetricFamily <ICounter <long>, TLabels> metricFamily, long value)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.IncTo(value);
        }
        public static void Set <TLabels>(this IMetricFamily <IGauge <long>, TLabels> metricFamily, long value, DateTimeOffset timestamp)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Set(value, timestamp);
        }
        public static void Inc <TLabels>(this IMetricFamily <IGauge <long>, TLabels> metricFamily, long increment, long timestamp)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Inc(increment, timestamp);
        }
        public static void Dec <TLabels>(this IMetricFamily <IGauge <long>, TLabels> metricFamily, long decrement, DateTimeOffset timestamp)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Dec(decrement, timestamp);
        }
        public static void Dec <TLabels>(this IMetricFamily <IGauge, TLabels> metricFamily, double decrement = 1)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Dec(decrement);
        }
        public static void Inc <TLabels>(this IMetricFamily <IGauge, TLabels> metricFamily, double increment, DateTimeOffset timestamp)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Inc(increment, timestamp);
        }
        public static void Set <TLabels>(this IMetricFamily <IGauge, TLabels> metricFamily, double value)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Set(value);
        }
        public static void Observe <TLabels>(this IMetricFamily <IHistogram, TLabels> metricFamily, double val, long timestamp)
#if HasITuple
            where TLabels : struct, ITuple, IEquatable <TLabels>
#else
            where TLabels : struct, IEquatable <TLabels>
#endif
        {
            metricFamily.Unlabelled.Observe(val, timestamp);
        }
Exemple #19
0
 public KafkaMessageConsumer(ILogger <KafkaMessageConsumer <TData> > logger,
                             IOptions <KafkaConsumerConfig <TData> > config,
                             IMetricsFactory <KafkaMessageConsumer <TData> >?metricsFactory,
                             IApplicationNameService applicationNameService,
                             ICloudEventFormatter cloudEventFormatter)
 {
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _applicationNameService = applicationNameService ?? throw new ArgumentNullException(nameof(config));
     _cloudEventFormatter    = cloudEventFormatter;
     _config             = config?.Value ?? throw new ArgumentNullException(nameof(config));
     _consumerLagSummary = metricsFactory?.CreateSummary("consumer_lag_distribution",
                                                         "Contains a summary of current consumer lag of each partition", new [] { "topic", "partition" });
     _consumerLagGauge = metricsFactory?.CreateGauge("consumer_lag",
                                                     "Contains current number consumer lag of each partition", false, "topic", "partition");
 }
    public ServiceWithMetrics(IMetricsFactory <ServiceWithMetrics> metricFactory,
                              IServiceInDifferentNamespace serviceInDifferentNamespace)
    {
        _serviceInDifferentNamespace = serviceInDifferentNamespace;

        // Resulting label in Prometheus: metricsexample_emtpy_string_total
        _counter = metricFactory?.CreateCounter("empty_string_total",
                                                "Counts the total number of recieved empty strings.");

        // Resulting label in Prometheus: metricsexample_fancy_number
        _simpleSummary = metricFactory?.CreateSummary("fancy_number",
                                                      "Shows the distribution of fancy numbers.");

        // Resulting label in Prometheus: metricsexample_processing_time
        _labeledSummary = metricFactory?.CreateSummary("processing_time",
                                                       "Shows the processing time of fancy inputs.", new[] { "successful" });
    }
        public HttpRequestDurationsMiddleware(RequestDelegate next, HttpRequestDurationsOptions options)
        {
            _next    = next;
            _options = options;
            var metricFactory = new MetricFactory(options.CollectorRegistry);

            var labels = new List <string>();

            if (_options.IncludeStatusCode)
            {
                labels.Add("status_code");
            }

            if (_options.IncludeMethod)
            {
                labels.Add("method");
            }

#if HasRoutes
            if (_options.IncludeController)
            {
                labels.Add("controller");
            }

            if (_options.IncludeAction)
            {
                labels.Add("action");
            }
#endif

            if (_options.IncludePath)
            {
                labels.Add("path");
            }

            if (_options.IncludeCustomLabels)
            {
                labels.AddRange(_options.CustomLabels.Select(customLabel => customLabel.Key));
            }

            _metricHelpText += string.Join(", ", labels);
            _histogram       = metricFactory.CreateHistogram(options.MetricName, _metricHelpText, options.IncludeTimestamp, options.Buckets, labels.ToArray());
        }
 public ReverseStringConverter(ILogger <ReverseStringConverter> logger,
                               IMetricsFactory <ReverseStringConverter> metricsFactory)
 {
     _logger  = logger;
     _summary = metricsFactory.CreateSummary("summaryName", "summaryHelpString", new[] { "someLabel" });
 }
 public static void Observe(this IMetricFamily <IHistogram> metricFamily, double val, long timestamp)
 {
     metricFamily.Unlabelled.Observe(val, timestamp);
 }
 public static void Observe(this IMetricFamily <ISummary> metricFamily, double val)
 {
     metricFamily.Unlabelled.Observe(val);
 }
 public static void Observe(this IMetricFamily <ISummary> metricFamily, double val, DateTimeOffset timestamp)
 {
     metricFamily.Unlabelled.Observe(val, timestamp.ToUnixTimeMilliseconds());
 }
Exemple #26
0
 public PrometheusDelegatingHandler(IMetricsFactory <PrometheusDelegatingHandler> metricsFactory)
 {
     _requestTotal =
         metricsFactory.CreateCounter("request_total", "number of external request", false, "host", "status");
     _requestLatency = metricsFactory.CreateSummary("request_latency", "request duration in ms", new[] { "host" });
 }
Exemple #27
0
 public HistogramController(IMetricFactory metricFactory)
 {
     _histogram = metricFactory.CreateHistogram("test_hist", "help_text", "params1", "params2");
 }
        public void Setup()
        {
            var factory = new MetricFactory(new CollectorRegistry());

            _gauge = factory.CreateGauge("gauge", string.Empty, "label1", "label2");
        }
        public void Setup()
        {
            var factory = new MetricFactory(new CollectorRegistry());

            _counter = factory.CreateCounter("counter", string.Empty, "label1", "label2");
        }
 public static void Observe(this IMetricFamily <IHistogram> metricFamily, double val)
 {
     metricFamily.Unlabelled.Observe(val);
 }