Beispiel #1
0
        internal void PushEvents()
        {
            try
            {
                _listener?.Refresh();

                if (_enableProcessMetrics)
                {
                    ProcessHelpers.GetCurrentProcessRuntimeMetrics(out var newUserCpu, out var newSystemCpu, out var threadCount, out var memoryUsage);

                    var userCpu   = newUserCpu - _previousUserCpu;
                    var systemCpu = newSystemCpu - _previousSystemCpu;

                    _previousUserCpu   = newUserCpu;
                    _previousSystemCpu = newSystemCpu;

                    // Note: the behavior of Environment.ProcessorCount has changed a lot accross version: https://github.com/dotnet/runtime/issues/622
                    // What we want is the number of cores attributed to the container, which is the behavior in 3.1.2+ (and, I believe, in 2.x)
                    var maximumCpu = Environment.ProcessorCount * _delay.TotalMilliseconds;
                    var totalCpu   = userCpu + systemCpu;

                    _statsd.Gauge(MetricsNames.ThreadsCount, threadCount);

                    _statsd.Gauge(MetricsNames.CommittedMemory, memoryUsage);

                    // Get CPU time in milliseconds per second
                    _statsd.Gauge(MetricsNames.CpuUserTime, userCpu.TotalMilliseconds / _delay.TotalSeconds);
                    _statsd.Gauge(MetricsNames.CpuSystemTime, systemCpu.TotalMilliseconds / _delay.TotalSeconds);

                    _statsd.Gauge(MetricsNames.CpuPercentage, Math.Round(totalCpu.TotalMilliseconds * 100 / maximumCpu, 1, MidpointRounding.AwayFromZero));

                    Log.Debug("Sent the following metrics: {metrics}", ProcessMetrics);
                }

                if (!_exceptionCounts.IsEmpty)
                {
                    foreach (var element in _exceptionCounts)
                    {
                        _statsd.Increment(MetricsNames.ExceptionsCount, element.Value, tags: new[] { $"exception_type:{element.Key}" });
                    }

                    // There's a race condition where we could clear items that haven't been pushed
                    // Having an exact exception count is probably not worth the overhead required to fix it
                    _exceptionCounts.Clear();

                    Log.Debug("Sent the following metrics: {metrics}", MetricsNames.ExceptionsCount);
                }
                else
                {
                    Log.Debug("Did not send the following metrics: {metrics}", MetricsNames.ExceptionsCount);
                }
            }
            catch (Exception ex)
            {
                Log.Warning(ex, "Error while updating runtime metrics");
            }
        }
Beispiel #2
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);
        }
        private void TryUpdateGauge(string path, PerformanceCounterWrapper counter)
        {
            var value = counter.GetValue(_instanceName);

            if (value != null)
            {
                _statsd.Gauge(path, value);
            }
        }
Beispiel #4
0
 public void Publish(NamedPerformanceMetric metric)
 {
     if (metric != null)
     {
         dogStatsdService.Gauge(
             metric.FullyQualifiedName,
             metric.Value,
             sampleRate: 1,
             metric.Tags.Select(x => $"{x.Key}:{x.Value}").ToArray());
     }
 }
        private void UpdateGuildPopulationCounter(IGuild guild, string counterName)
        {
            if (!string.IsNullOrEmpty(guild?.Name))
            {
                var tags = new[] { "guild:" + guild.Name };

                _stats.Increment(counterName, tags: tags);

                if (guild is ISocketGuild socketGuild)
                {
                    _stats.Gauge("user_count", socketGuild.MemberCount, tags: tags);
                }
            }
        }
Beispiel #6
0
        public async Task FlushTracesAsync()
        {
            var traces = _tracesBuffer.Pop();

            if (_statsd != null)
            {
                var spanCount = traces.Sum(t => t.Length);

                _statsd.Increment(TracerMetricNames.Queue.DequeuedTraces, traces.Length);
                _statsd.Increment(TracerMetricNames.Queue.DequeuedSpans, spanCount);
                _statsd.Gauge(TracerMetricNames.Queue.MaxTraces, _tracesBuffer.MaxSize);
            }

            if (traces.Length > 0)
            {
                await _api.SendTracesAsync(traces).ConfigureAwait(false);
            }
        }
Beispiel #7
0
 public static void Gauge <T>(this IDogStatsd stats, string statsName, T value, double sampleRate = 1, List <string> tags = null)
 {
     stats?.Gauge(statsName, value, sampleRate, tags?.ToArray());
 }
        private void GcHeapHistory(HeapHistory heapHistory)
        {
            if (heapHistory.MemoryLoad != null)
            {
                _statsd.Gauge("runtime.dotnet.gc.memory_load", heapHistory.MemoryLoad.Value);
            }

            _statsd.Increment(GcCountMetricNames[heapHistory.Generation], 1, tags: heapHistory.Compacting ? CompactingGcTags : NotCompactingGcTags);
        }