Example #1
0
        /// <summary>
        /// Constructs a new instance of <see cref="AspNetMetricSource" />.
        /// </summary>
        public AspNetMetricSource(IDiagnosticsCollector diagnosticsCollector, MetricSourceOptions options) : base(options)
        {
            const string MicrosoftAspNetCoreHostingEventSourceName = "Microsoft.AspNetCore.Hosting";

            diagnosticsCollector.AddSource(
                new EventPipeProvider(
                    MicrosoftAspNetCoreHostingEventSourceName,
                    EventLevel.Informational,
                    arguments: new Dictionary <string, string>()
            {
                { "EventCounterIntervalSec", "5" }
            }
                    )
                );

            void AddCounterCallback(string eventName, string name, string unit, string description)
            {
                var counter = AddCounter(name, unit, description);

                diagnosticsCollector.AddCounterCallback(MicrosoftAspNetCoreHostingEventSourceName, eventName, counter.Increment);
            }

            void AddGaugeCallback(string eventName, string name, string unit, string description)
            {
                var gauge = AddSamplingGauge(name, unit, description);

                diagnosticsCollector.AddGaugeCallback(MicrosoftAspNetCoreHostingEventSourceName, eventName, gauge.Record);
            }

            AddCounterCallback("requests-per-sec", "dotnet.kestrel.requests.per_sec", "requests/sec", "Requests per second");
            AddGaugeCallback("total-requests", "dotnet.kestrel.requests.total", "requests", "Total requests");
            AddGaugeCallback("current-requests", "dotnet.kestrel.requests.current", "requests", "Currently executing requests");
            AddGaugeCallback("failed-requests", "dotnet.kestrel.requests.failed", "requests", "Failed requests");
        }
        /// <inheritdoc/>
        public void Initialize(IMetricsCollector collector)
        {
            const string MicrosoftAspNetCoreHostingEventSourceName = "Microsoft.AspNetCore.Hosting";

            _diagnosticsCollector.AddSource(
                new EventPipeProvider(
                    MicrosoftAspNetCoreHostingEventSourceName,
                    EventLevel.Informational,
                    arguments: new Dictionary <string, string>()
            {
                { "EventCounterIntervalSec", collector.ReportingInterval.TotalSeconds.ToString() }
            }
                    )
                );

            void AddCounterCallback(string name, Counter counter) => _diagnosticsCollector.AddCounterCallback(MicrosoftAspNetCoreHostingEventSourceName, name, counter.Increment);
            void AddGaugeCallback(string name, SamplingGauge gauge) => _diagnosticsCollector.AddGaugeCallback(MicrosoftAspNetCoreHostingEventSourceName, name, gauge.Record);

            var requestsPerSec  = collector.CreateMetric <Counter>("dotnet.kestrel.requests.per_sec", "requests/sec", "Requests per second", includePrefix: false);
            var totalRequests   = collector.CreateMetric <SamplingGauge>("dotnet.kestrel.requests.total", "requests", "Total requests", includePrefix: false);
            var currentRequests = collector.CreateMetric <SamplingGauge>("dotnet.kestrel.requests.current", "requests", "Currently executing requests", includePrefix: false);
            var failedRequests  = collector.CreateMetric <SamplingGauge>("dotnet.kestrel.requests.failed", "requests", "Failed requests", includePrefix: false);

            AddCounterCallback("requests-per-sec", requestsPerSec);
            AddGaugeCallback("total-requests", totalRequests);
            AddGaugeCallback("current-requests", currentRequests);
            AddGaugeCallback("failed-requests", failedRequests);
        }
        /// <inheritdoc/>
        public void Initialize(IMetricsCollector collector)
        {
            const string SystemRuntimeEventSourceName = "System.Runtime";

            _diagnosticsCollector.AddSource(
                new EventPipeProvider(
                    SystemRuntimeEventSourceName,
                    EventLevel.Informational,
                    arguments: new Dictionary <string, string>()
            {
                { "EventCounterIntervalSec", collector.ReportingInterval.TotalSeconds.ToString() }
            }
                    )
                );

            void AddCounterCallback(string name, Counter counter) => _diagnosticsCollector.AddCounterCallback(SystemRuntimeEventSourceName, name, counter.Increment);
            void AddGaugeCallback(string name, SamplingGauge gauge) => _diagnosticsCollector.AddGaugeCallback(SystemRuntimeEventSourceName, name, gauge.Record);

            var cpuUsage   = collector.CreateMetric <SamplingGauge>("dotnet.cpu.usage", "percent", "% CPU usage", includePrefix: false);
            var workingSet = collector.CreateMetric <SamplingGauge>("dotnet.mem.working_set", "bytes", "Working set for the process", includePrefix: false);

            AddGaugeCallback("cpu-usage", cpuUsage);
            AddGaugeCallback("working-set", workingSet);

            // GC
            var gen0      = collector.CreateMetric <Counter>("dotnet.mem.collections.gen0", "collections", "Number of gen-0 collections", includePrefix: false);
            var gen1      = collector.CreateMetric <Counter>("dotnet.mem.collections.gen1", "collections", "Number of gen-1 collections", includePrefix: false);
            var gen2      = collector.CreateMetric <Counter>("dotnet.mem.collections.gen2", "collections", "Number of gen-2 collections", includePrefix: false);
            var gen0Size  = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.gen0", "bytes", "Total number of bytes in gen-0", includePrefix: false);
            var gen1Size  = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.gen1", "bytes", "Total number of bytes in gen-1", includePrefix: false);
            var gen2Size  = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.gen2", "bytes", "Total number of bytes in gen-2", includePrefix: false);
            var heapSize  = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.heap", "bytes", "Total number of bytes across all heaps", includePrefix: false);
            var lohSize   = collector.CreateMetric <SamplingGauge>("dotnet.mem.size.loh", "bytes", "Total number of bytes in the LOH", includePrefix: false);
            var allocRate = collector.CreateMetric <Counter>("dotnet.mem.allocation_rate", "bytes/sec", "Allocation Rate (Bytes / sec)", includePrefix: false);

            AddGaugeCallback("gc-heap-size", heapSize);
            AddGaugeCallback("gen-0-size", gen0Size);
            AddGaugeCallback("gen-1-size", gen1Size);
            AddGaugeCallback("gen-2-size", gen2Size);
            AddCounterCallback("gen-0-gc-count", gen0);
            AddCounterCallback("gen-1-gc-count", gen1);
            AddCounterCallback("gen-2-gc-count", gen2);
            AddGaugeCallback("loh-size", lohSize);
            AddCounterCallback("alloc-rate", allocRate);

            // thread pool
            var threadPoolCount       = collector.CreateMetric <SamplingGauge>("dotnet.threadpool.count", "threads", "Number of threads in the threadpool", includePrefix: false);
            var threadPoolQueueLength = collector.CreateMetric <SamplingGauge>("dotnet.threadpool.queue_length", "workitems", "Number of work items queued to the threadpool", includePrefix: false);
            var timerCount            = collector.CreateMetric <SamplingGauge>("dotnet.timers.count", "timers", "Number of active timers", includePrefix: false);

            AddGaugeCallback("threadpool-thread-count", threadPoolCount);
            AddGaugeCallback("threadpool-queue-length", threadPoolQueueLength);
            AddGaugeCallback("active-timer-count", timerCount);
        }
Example #4
0
        /// <summary>
        /// Constructs a new instance of <see cref="RuntimeMetricSource" />.
        /// </summary>
        public RuntimeMetricSource(IDiagnosticsCollector diagnosticsCollector, MetricSourceOptions options) : base(options)
        {
            const string SystemRuntimeEventSourceName = "System.Runtime";

            diagnosticsCollector.AddSource(
                new EventPipeProvider(
                    SystemRuntimeEventSourceName,
                    EventLevel.Informational,
                    arguments: new Dictionary <string, string>()
            {
                { "EventCounterIntervalSec", "5" }
            }
                    )
                );

            void AddCounterCallback(string eventName, string name, string unit, string description)
            {
                var counter = AddCounter(name, unit, description);

                diagnosticsCollector.AddCounterCallback(SystemRuntimeEventSourceName, eventName, counter.Increment);
                Add(counter);
            }

            void AddGaugeCallback(string eventName, string name, string unit, string description)
            {
                var gauge = AddSamplingGauge(name, unit, description);

                diagnosticsCollector.AddGaugeCallback(SystemRuntimeEventSourceName, eventName, gauge.Record);
                Add(gauge);
            }

            AddGaugeCallback("cpu-usage", "dotnet.cpu.usage", "percent", "% CPU usage");
            AddGaugeCallback("working-set", "dotnet.mem.working_set", "bytes", "Working set for the process");

            // GC
            AddCounterCallback("gen-0-gc-count", "dotnet.mem.collections.gen0", "collections", "Number of gen-0 collections");
            AddCounterCallback("gen-1-gc-count", "dotnet.mem.collections.gen1", "collections", "Number of gen-1 collections");
            AddCounterCallback("gen-2-gc-count", "dotnet.mem.collections.gen2", "collections", "Number of gen-2 collections");
            AddGaugeCallback("gen-0-size", "dotnet.mem.size.gen0", "bytes", "Total number of bytes in gen-0");
            AddGaugeCallback("gen-1-size", "dotnet.mem.size.gen1", "bytes", "Total number of bytes in gen-1");
            AddGaugeCallback("gen-2-size", "dotnet.mem.size.gen2", "bytes", "Total number of bytes in gen-2");
            AddGaugeCallback("gc-heap-size", "dotnet.mem.size.heap", "bytes", "Total number of bytes across all heaps");
            AddGaugeCallback("loh-size", "dotnet.mem.size.loh", "bytes", "Total number of bytes in the LOH");
            AddCounterCallback("alloc-rate", "dotnet.mem.allocation_rate", "bytes/sec", "Allocation Rate (Bytes / sec)");

            // thread pool
            AddGaugeCallback("threadpool-thread-count", "dotnet.threadpool.count", "threads", "Number of threads in the threadpool");
            AddGaugeCallback("threadpool-queue-length", "dotnet.threadpool.queue_length", "workitems", "Number of work items queued to the threadpool");
            AddGaugeCallback("active-timer-count", "dotnet.timers.count", "timers", "Number of active timers");
        }