Пример #1
0
 public KafkaMessageConsumer(ILogger <KafkaMessageConsumer <TData> > logger,
                             IOptions <KafkaConsumerConfig <TData> > config,
                             IMetricsFactory <KafkaMessageConsumer <TData> >?metricsFactory,
                             IApplicationNameService applicationNameService,
                             ICloudEventFormatter cloudEventFormatter)
 {
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _applicationNameService = applicationNameService ?? throw new ArgumentNullException(nameof(config));
     _cloudEventFormatter    = cloudEventFormatter;
     _config             = config?.Value ?? throw new ArgumentNullException(nameof(config));
     _consumerLagSummary = metricsFactory?.CreateSummary("consumer_lag_distribution",
                                                         "Contains a summary of current consumer lag of each partition", new [] { "topic", "partition" });
     _consumerLagGauge = metricsFactory?.CreateGauge("consumer_lag",
                                                     "Contains current number consumer lag of each partition", false, "topic", "partition");
 }
Пример #2
0
        private void CreateMetrics(IMetricsFactory factory)
        {
            foreach (PropertyInfo property in typeof(MetricsImpl).GetProperties())
            {
                Type metricType = property.PropertyType;

                if (!typeof(ICounter).IsAssignableFrom(metricType) &&
                    !typeof(ITimer).IsAssignableFrom(metricType) &&
                    !typeof(IGauge).IsAssignableFrom(metricType))
                {
                    // Some frameworks dynamically add code that this reflection will pick up
                    // I only want this classes Stats based fields to be picked up.
                    continue;
                }

                StringBuilder metricBuilder      = new StringBuilder("jaeger:");
                Dictionary <string, string> tags = new Dictionary <string, string>();

                var metricAttributes = property.GetCustomAttributes <MetricAttribute>();
                foreach (MetricAttribute metricAttribute in metricAttributes)
                {
                    metricBuilder.Append(metricAttribute.Name);
                    foreach (var tag in metricAttribute.Tags)
                    {
                        tags[tag.Key] = tag.Value;
                    }
                }

                string metricName = metricBuilder.ToString();

                if (metricType == typeof(ICounter))
                {
                    property.SetValue(this, factory.CreateCounter(metricName, tags));
                }
                else if (metricType == typeof(IGauge))
                {
                    property.SetValue(this, factory.CreateGauge(metricName, tags));
                }
                else if (metricType == typeof(ITimer))
                {
                    property.SetValue(this, factory.CreateTimer(metricName, tags));
                }
                else
                {
                    throw new NotSupportedException($"'{metricType}' for metric '{property.Name}' is not supported.");
                }
            }
        }
Пример #3
0
 public BackgroundTaskQueue(IMetricsFactory <BackgroundTaskQueue <T> >?metricsFactory)
 {
     _elementsInQueue = metricsFactory?.CreateGauge("task_queue_enqueued_elements", "", false, "type")
                        ?.WithLabels(typeof(T).Name);
     _totalMessages = metricsFactory?.CreateCounter("total_messages", "", false, "type")?.WithLabels(typeof(T).Name);
 }