Example #1
0
        public void Refresh()
        {
            // Can't use a Timing because Dogstatsd doesn't support local aggregation
            // It means that the aggregations in the UI would be wrong
            _statsd.Gauge(MetricsNames.ContentionTime, _contentionTime.Clear());
            _statsd.Counter(MetricsNames.ContentionCount, Interlocked.Exchange(ref _contentionCount, 0));

            _statsd.Gauge(MetricsNames.ThreadPoolWorkersCount, ThreadPool.ThreadCount);
        }
        public static void Warning(this IDogStatsd statsd, string source, string message, string[] tags = null)
        {
            if (statsd != null)
            {
                string[] warningTags =
                {
                    $"source:{source}",
                    $"message:{message}"
                };

                string[] allTags = warningTags.Concat(tags ?? Enumerable.Empty <string>()).ToArray();

                statsd.Counter(TracerMetricNames.Health.Warnings, value: 1, sampleRate: 1, allTags);
            }
        }
        public static void Exception(this IDogStatsd statsd, Exception exception, string source, string message, string[] tags = null)
        {
            if (statsd != null)
            {
                string[] exceptionTags =
                {
                    $"source:{source}",
                    $"message:{message}",
                    $"exception-type:{exception.GetType().FullName}",
                    $"exception-message:{exception.Message}",
                };

                string[] allTags = exceptionTags.Concat(tags ?? Enumerable.Empty <string>()).ToArray();

                statsd.Counter(TracerMetricNames.Health.Exceptions, value: 1, sampleRate: 1, allTags);
            }
        }
        private void TryUpdateCounter(string path, PerformanceCounterWrapper counter, ref long?lastValue)
        {
            var value = counter.GetValue(_instanceName);

            if (value == null)
            {
                return;
            }

            if (lastValue == null)
            {
                lastValue = value;
                return;
            }

            _statsd.Counter(path, value - lastValue);
            lastValue = value;
        }
        private void PushEvents()
        {
            try
            {
                if (_enableProcessMetrics)
                {
                    ProcessHelpers.GetCurrentProcessRuntimeMetrics(out var newUserCpu, out var newSystemCpu, out var threadCount, out var memoryUsage);

                    // Get the CPU time per second
                    var userCpu   = (newUserCpu - _previousUserCpu).TotalMilliseconds / (_delay / 1000.0);
                    var systemCpu = (newSystemCpu - _previousSystemCpu).TotalMilliseconds / (_delay / 1000.0);

                    _previousUserCpu   = newUserCpu;
                    _previousSystemCpu = newSystemCpu;

                    _statsd.Gauge("runtime.dotnet.threads.count", threadCount);

                    _statsd.Gauge("runtime.dotnet.mem.committed", memoryUsage);
                    _statsd.Gauge("runtime.dotnet.cpu.user", userCpu);
                    _statsd.Gauge("runtime.dotnet.cpu.system", systemCpu);
                }

                // Can't use a Timing because Dogstatsd doesn't support local aggregation
                // It means that the aggregations in the UI would be wrong
                _statsd.Gauge("runtime.dotnet.threads.contention_time", _contentionTime.Clear());
                _statsd.Counter("runtime.dotnet.threads.contention_count", Interlocked.Exchange(ref _contentionCount, 0));

#if NETCOREAPP
                _statsd.Gauge("runtime.dotnet.threads.workers_count", ThreadPool.ThreadCount);
#endif
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "Error while updating runtime metrics");
            }
        }