Beispiel #1
0
        public MetricsCollector(IApmLogger logger, IPayloadSender payloadSender, IConfigurationSnapshotProvider configurationSnapshotProvider,
                                params IMetricsProvider[] metricsProvider
                                )
        {
            _logger        = logger.Scoped(nameof(MetricsCollector));
            _payloadSender = payloadSender;
            _configurationSnapshotProvider = configurationSnapshotProvider;

            var currentConfigSnapshot = configurationSnapshotProvider.CurrentSnapshot;

            var interval = currentConfigSnapshot.MetricsIntervalInMilliseconds;

            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (interval == 0)
            {
                _logger.Info()?.Log("Collecting metrics is disabled - the agent won't collect metrics");
                return;
            }

            MetricsProviders = new List <IMetricsProvider>();
            var disabledMetrics = configurationSnapshotProvider.CurrentSnapshot.DisableMetrics;

            if (metricsProvider != null)
            {
                foreach (var item in metricsProvider)
                {
                    if (item != null)
                    {
                        AddIfEnabled(item);
                    }
                }
            }

            AddIfEnabled(new ProcessTotalCpuTimeProvider(_logger));
            AddIfEnabled(new SystemTotalCpuProvider(_logger));
            AddIfEnabled(new ProcessWorkingSetAndVirtualMemoryProvider(disabledMetrics));
            AddIfEnabled(new FreeAndTotalMemoryProvider(disabledMetrics));
            try
            {
                // We saw some Exceptions in GcMetricsProvider.ctor, so we try-catch it
                AddIfEnabled(new GcMetricsProvider(_logger, disabledMetrics));
            }
            catch (Exception e)
            {
                _logger.Warning()?.LogException(e, "Failed loading {ProviderName}", nameof(GcMetricsProvider));
            }
            AddIfEnabled(new CgroupMetricsProvider(_logger, disabledMetrics));

            _logger.Info()?.Log("Collecting metrics in {interval} milliseconds interval", interval);
            _timer          = new Timer(interval);
            _timer.Elapsed += (sender, args) => { CollectAllMetrics(); };

            void AddIfEnabled(IMetricsProvider provider)
            {
                if (provider.IsEnabled(disabledMetrics))
                {
                    MetricsProviders.Add(provider);
                }
            }
        }
Beispiel #2
0
 public Tracer(
     IApmLogger logger,
     Service service,
     IPayloadSender payloadSender,
     IConfigurationSnapshotProvider configurationProvider,
     ICurrentExecutionSegmentsContainer currentExecutionSegmentsContainer,
     IApmServerInfo apmServerInfo,
     BreakdownMetricsProvider breakdownMetricsProvider
     )
 {
     _logger  = logger?.Scoped(nameof(Tracer));
     _service = service;
     _sender  = payloadSender.ThrowIfArgumentNull(nameof(payloadSender));
     _configurationProvider            = configurationProvider.ThrowIfArgumentNull(nameof(configurationProvider));
     CurrentExecutionSegmentsContainer = currentExecutionSegmentsContainer.ThrowIfArgumentNull(nameof(currentExecutionSegmentsContainer));
     DbSpanCommon              = new DbSpanCommon(logger);
     _apmServerInfo            = apmServerInfo;
     _breakdownMetricsProvider = breakdownMetricsProvider;
 }