예제 #1
0
        private void RegisterMetrics(CollectorRegistry registry)
        {
            var metrics = Metrics.WithCustomRegistry(registry);

            var collectionCountsParent = metrics.CreateCounter("dotnet_collection_count_total", "GC collection count", new[] { "generation" });

            for (var gen = 0; gen <= GC.MaxGeneration; gen++)
            {
                _collectionCounts.Add(collectionCountsParent.Labels(gen.ToString()));
            }

            // Metrics that make sense to compare between all operating systems
            // Note that old versions of pushgateway errored out if different metrics had same name but different help string.
            // This is fixed in newer versions but keep the help text synchronized with the Go implementation just in case.
            // See https://github.com/prometheus/pushgateway/issues/194
            // and https://github.com/prometheus-net/prometheus-net/issues/89
            _startTime = metrics.CreateGauge("process_start_time_seconds", "Start time of the process since unix epoch in seconds.");
            _cpuTotal  = metrics.CreateCounter("process_cpu_seconds_total", "Total user and system CPU time spent in seconds.");

            _virtualMemorySize = metrics.CreateGauge("process_virtual_bytes", "Process virtual memory size");
            _workingSet        = metrics.CreateGauge("process_working_set", "Process working set");
            _privateMemorySize = metrics.CreateGauge("process_private_bytes", "Process private memory size");
            _openHandles       = metrics.CreateGauge("process_open_handles", "Number of open handles");
            _numThreads        = metrics.CreateGauge("process_num_threads", "Total number of threads");
            _pid = metrics.CreateGauge("process_processid", "Process ID");

            // .net specific metrics
            _totalMemory = metrics.CreateGauge("dotnet_totalmemory", "Total known allocated memory");
            _perfErrors  = metrics.CreateCounter("dotnet_collection_errors_total", "Total number of errors that occured during collections");

            var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);

            _startTime.Set((_process.StartTime.ToUniversalTime() - epoch).TotalSeconds);
            _pid.Set(_process.Id);
        }
예제 #2
0
        public async Task GetMetricsAsync()
        {
            var           r = Metric.NewCustomRegistry();
            MetricFactory f = Metric.WithCustomRegistry(r);

            r.AddBeforeCollectCallback(() =>
            {
                f.CreateCounter("counter_v1", "").Inc(100);
            });
            Response.ContentType = PrometheusConstants.ExporterContentType;
            Response.StatusCode  = 200;
            await r.CollectAndExportAsTextAsync(Response.Body, HttpContext.RequestAborted);
        }
        protected GrpcRequestMiddlewareBase(GrpcMetricsOptionsBase?options, TCollector?customMetric)
        {
            MetricFactory = Metrics.WithCustomRegistry(options?.Registry ?? Metrics.DefaultRegistry);

            if (customMetric != null)
            {
                _metric = customMetric;
                ValidateNoUnexpectedLabelNames();
            }
            else
            {
                _metric = CreateMetricInstance(DefaultLabels);
            }
        }
예제 #4
0
        private EventCounterAdapter(EventCounterAdapterOptions options)
        {
            _options       = options;
            _metricFactory = Metrics.WithCustomRegistry(_options.Registry);

            _gauge = _metricFactory.CreateGauge("dotnet_gauge", "Values from .NET aggregating EventCounters (count per second).", new GaugeConfiguration
            {
                LabelNames = new[] { "source", "name", "display_name" }
            });
            _counter = _metricFactory.CreateCounter("dotnet_counter", "Values from .NET incrementing EventCounters.", new CounterConfiguration
            {
                LabelNames = new[] { "source", "name", "display_name" }
            });

            _listener = new Listener(OnEventSourceCreated, OnEventWritten);
        }
예제 #5
0
        private DiagnosticSourceAdapter(DiagnosticSourceAdapterOptions options)
        {
            _options = options;
            _metric  = Metrics.WithCustomRegistry(options.Registry)
                       .CreateCounter("diagnostic_events_total", "Total count of events received via the DiagnosticSource infrastructure.", new CounterConfiguration
            {
                LabelNames = new[]
                {
                    "source",   // Name of the DiagnosticSource
                    "event"     // Name of the event
                }
            });

            var newListenerObserver = new NewListenerObserver(OnNewListener);

            _newListenerSubscription = DiagnosticListener.AllListeners.Subscribe(newListenerObserver);
        }