internal static Sensor InvocationRateAndCountAndAvgAndMaxLatencySensor(string threadId,
                                                                               string metricName,
                                                                               string metricDescription,
                                                                               string descriptionOfRate,
                                                                               string descriptionOfCount,
                                                                               string descriptionOfAvg,
                                                                               string descriptionOfMax,
                                                                               MetricsRecordingLevel recordingLevel,
                                                                               StreamMetricsRegistry streamsMetrics)
        {
            Sensor sensor = streamsMetrics.ThreadLevelSensor(threadId, metricName, metricDescription, recordingLevel);
            var    tags   = streamsMetrics.ThreadLevelTags(threadId);

            SensorHelper.AddAvgAndMaxToSensor(sensor,
                                              StreamMetricsRegistry.THREAD_LEVEL_GROUP,
                                              tags,
                                              metricName + StreamMetricsRegistry.LATENCY_SUFFIX,
                                              descriptionOfAvg,
                                              descriptionOfMax);

            SensorHelper.AddInvocationRateAndCountToSensor(sensor,
                                                           StreamMetricsRegistry.THREAD_LEVEL_GROUP,
                                                           tags,
                                                           metricName,
                                                           descriptionOfRate,
                                                           descriptionOfCount);

            return(sensor);
        }
 /// <summary>
 /// Create stream metrics registry
 /// </summary>
 /// <param name="clientId">Client Id derived from <see cref="IStreamConfig.ApplicationId"/></param>
 /// <param name="metricsRecordingLevel">Metrics recording level derived from <see cref="IStreamConfig.MetricsRecording"/></param>
 public StreamMetricsRegistry(
     string clientId,
     MetricsRecordingLevel metricsRecordingLevel)
 {
     this.clientId  = clientId;
     recordingLevel = metricsRecordingLevel;
 }
        private static Sensor ThroughputAndLatencySensor(TaskId taskId,
                                                         string storeType,
                                                         string storeName,
                                                         string metricName,
                                                         string metricDescription,
                                                         string descriptionOfRate,
                                                         string descriptionOfAvg,
                                                         string descriptionOfMax,
                                                         MetricsRecordingLevel recordingLevel,
                                                         StreamMetricsRegistry streamsMetrics)
        {
            Sensor sensor;
            string latencyMetricName          = metricName + StreamMetricsRegistry.LATENCY_SUFFIX;
            IDictionary <string, string> tags =
                streamsMetrics.StoreLevelTags(GetThreadId(), taskId.ToString(), storeName, storeType);

            sensor = streamsMetrics.StoreLevelSensor(GetThreadId(), taskId, storeName, metricName, metricDescription, recordingLevel);
            SensorHelper.AddInvocationRateToSensor(sensor, StreamMetricsRegistry.STATE_STORE_LEVEL_GROUP, tags, metricName,
                                                   descriptionOfRate);

            SensorHelper.AddAvgAndMaxToSensor(
                sensor,
                StreamMetricsRegistry.STATE_STORE_LEVEL_GROUP,
                tags,
                latencyMetricName,
                descriptionOfAvg,
                descriptionOfMax
                );
            return(sensor);
        }
        private static Sensor SizeOrCountSensor(TaskId taskId,
                                                string storeType,
                                                string storeName,
                                                string metricName,
                                                string metricDescription,
                                                string descriptionOfAvg,
                                                string descriptionOfMax,
                                                MetricsRecordingLevel recordingLevel,
                                                StreamMetricsRegistry streamsMetrics)
        {
            Sensor sensor = streamsMetrics.StoreLevelSensor(
                GetThreadId(),
                taskId,
                storeName,
                metricName,
                metricDescription,
                recordingLevel);
            string group;
            IDictionary <string, string> tags;

            group = StreamMetricsRegistry.STATE_STORE_LEVEL_GROUP;
            tags  = streamsMetrics.StoreLevelTags(GetThreadId(), taskId.ToString(), storeName, storeType);

            SensorHelper.AddAvgAndMaxToSensor(sensor, group, tags, metricName, descriptionOfAvg, descriptionOfMax);

            return(sensor);
        }
예제 #5
0
        private static Sensor ThroughputSensor(string threadId,
                                               TaskId taskId,
                                               string processorNodeId,
                                               string metricNamePrefix,
                                               string metricDescription,
                                               string descriptionOfRate,
                                               string descriptionOfCount,
                                               MetricsRecordingLevel recordingLevel,
                                               StreamMetricsRegistry metricsRegistry)
        {
            Sensor sensor =
                metricsRegistry.NodeLevelSensor(threadId, taskId, processorNodeId, metricNamePrefix, metricDescription,
                                                recordingLevel);
            var tags = metricsRegistry.NodeLevelTags(threadId, taskId.ToString(), processorNodeId);

            SensorHelper.AddInvocationRateAndCountToSensor(
                sensor,
                StreamMetricsRegistry.PROCESSOR_NODE_LEVEL_GROUP,
                tags,
                metricNamePrefix,
                descriptionOfRate,
                descriptionOfCount
                );
            return(sensor);
        }
        private T GetSensor <T>(
            IDictionary <string, IList <string> > listSensors,
            string sensorName,
            string key,
            string description,
            MetricsRecordingLevel metricsRecordingLevel,
            params Sensor[] parents)
            where T : Sensor
        {
            string fullSensorName = FullSensorName(sensorName, key);
            T      sensor         = GetSensor <T>(fullSensorName, description, metricsRecordingLevel, parents);

            if (!listSensors.ContainsKey(key))
            {
                listSensors.Add(key, new List <string> {
                    fullSensorName
                });
            }
            else if (!listSensors[key].Contains(fullSensorName))
            {
                listSensors[key].Add(fullSensorName);
            }

            return(sensor);
        }
예제 #7
0
 public MetricConfig()
 {
     Samples        = 2;
     EventWindow    = long.MaxValue;
     TimeWindowMs   = (long)TimeSpan.FromSeconds(30).TotalMilliseconds;
     Tags           = new Dictionary <string, string>();
     RecordingLevel = MetricsRecordingLevel.INFO;
 }
 private Sensor GetSensor(
     IDictionary <string, IList <string> > listSensors,
     string sensorName,
     string key,
     string description,
     MetricsRecordingLevel metricsRecordingLevel,
     params Sensor[] parents)
 => GetSensor <Sensor>(listSensors, sensorName, key, description, metricsRecordingLevel, parents);
 internal Sensor LibrdKafkaSensor(
     string threadId,
     string librdKafkaClientId,
     string sensorName,
     string description,
     MetricsRecordingLevel metricsRecordingLevel,
     params Sensor[] parents)
 => LibrdKafkaSensor <Sensor>(threadId, librdKafkaClientId, sensorName, description, metricsRecordingLevel,
                              parents);
예제 #10
0
 internal Sensor(
     string name,
     string description,
     MetricsRecordingLevel metricsRecording)
 {
     Name             = name;
     Description      = description;
     MetricsRecording = metricsRecording;
     metrics          = new Dictionary <MetricName, StreamMetric>();
     stats            = new List <IMeasurableStat>();
     config.SetRecordingLevel(MetricsRecording);
 }
 internal Sensor ThreadLevelSensor(
     string threadId,
     string sensorName,
     string description,
     MetricsRecordingLevel metricsRecordingLevel,
     params Sensor[] parents)
 {
     lock (threadLevelSensors)
     {
         threadId ??= UNKNOWN_THREAD;
         string key    = ThreadSensorPrefix(threadId);
         var    sensor = GetSensor(threadLevelSensors, sensorName, key, description, metricsRecordingLevel, parents);
         AddSensorThreadScope(threadId, sensor.Name);
         return(sensor);
     }
 }
 internal Sensor ClientLevelSensor(
     string sensorName,
     string description,
     MetricsRecordingLevel metricsRecordingLevel,
     params Sensor[] parents)
 {
     lock (clientLevelSensors)
     {
         string fullSensorName = $"{CLIENT_LEVEL_GROUP}{SENSOR_NAME_DELIMITER}{sensorName}";
         Sensor sensor         = GetSensor(fullSensorName, description, metricsRecordingLevel, parents);
         if (!clientLevelSensors.Contains(fullSensorName))
         {
             clientLevelSensors.Add(fullSensorName);
         }
         return(sensor);
     }
 }
 internal Sensor NodeLevelSensor(
     string threadId,
     TaskId taskId,
     string processorName,
     string sensorName,
     string description,
     MetricsRecordingLevel metricsRecordingLevel,
     params Sensor[] parents)
 {
     lock (nodeLevelSensors)
     {
         threadId ??= UNKNOWN_THREAD;
         string key    = NodeSensorPrefix(threadId, taskId.ToString(), processorName);
         var    sensor = GetSensor(nodeLevelSensors, sensorName, key, description, metricsRecordingLevel, parents);
         AddSensorThreadScope(threadId, sensor.Name);
         return(sensor);
     }
 }
 internal T LibrdKafkaSensor <T>(
     string threadId,
     string librdKafkaClientId,
     string sensorName,
     string description,
     MetricsRecordingLevel metricsRecordingLevel,
     params Sensor[] parents)
     where T : Sensor
 {
     lock (librdkafkaSensors)
     {
         threadId ??= UNKNOWN_THREAD;
         string key    = LibrdKafkaSensorPrefix(librdKafkaClientId);
         var    sensor = GetSensor <T>(librdkafkaSensors, sensorName, key, description, metricsRecordingLevel, parents);
         AddSensorThreadScope(threadId, sensor.Name);
         return(sensor);
     }
 }
        internal static Sensor InvocationRateAndCountSensor(string threadId,
                                                            string metricName,
                                                            string metricDescription,
                                                            string descriptionOfRate,
                                                            string descriptionOfCount,
                                                            MetricsRecordingLevel recordingLevel,
                                                            StreamMetricsRegistry streamsMetrics)
        {
            Sensor sensor = streamsMetrics.ThreadLevelSensor(threadId, metricName, metricDescription, recordingLevel);

            SensorHelper.AddInvocationRateAndCountToSensor(
                sensor,
                StreamMetricsRegistry.THREAD_LEVEL_GROUP,
                streamsMetrics.ThreadLevelTags(threadId),
                metricName,
                descriptionOfRate,
                descriptionOfCount
                );
            return(sensor);
        }
        private T GetSensor <T>(
            string name,
            string description,
            MetricsRecordingLevel metricsRecordingLevel,
            params Sensor[] parents)
            where T : Sensor
        {
            if (sensors.ContainsKey(name) && sensors[name] is T)
            {
                return((T)sensors[name]);
            }
            else
            {
                T sensor = (T)(typeof(T)
                               .GetConstructor(
                                   BindingFlags.NonPublic | BindingFlags.Instance,
                                   null,
                                   new Type[]
                {
                    typeof(string),
                    typeof(string),
                    typeof(MetricsRecordingLevel)
                }, null)
                               ?.Invoke(new object[] { name, description, metricsRecordingLevel }));

                if (sensor == null)
                {
                    throw new StreamsException($"{typeof(T)} has no constructor with string, string, MetricsRecordingLevel parameters !");
                }

                if (!TestMetricsRecordingLevel(metricsRecordingLevel))
                {
                    sensor.NoRunnable = true;
                }

                sensors.Add(name, sensor);
                return(sensor);
            }
        }
예제 #17
0
        private static Sensor InvocationRateAndCountSensor(string threadId,
                                                           TaskId taskId,
                                                           string metricName,
                                                           string metricDescription,
                                                           string descriptionOfRate,
                                                           string descriptionOfCount,
                                                           MetricsRecordingLevel recordingLevel,
                                                           StreamMetricsRegistry streamsMetrics)
        {
            Sensor sensor =
                streamsMetrics.TaskLevelSensor(threadId, taskId, metricName, metricDescription, recordingLevel);

            SensorHelper.AddInvocationRateAndCountToSensor(
                sensor,
                StreamMetricsRegistry.TASK_LEVEL_GROUP,
                streamsMetrics.TaskLevelTags(threadId, taskId.ToString()),
                metricName,
                descriptionOfRate,
                descriptionOfCount
                );

            return(sensor);
        }
예제 #18
0
        private static Sensor AvgAndMaxSensor(string threadId,
                                              TaskId taskId,
                                              string metricName,
                                              string metricDescription,
                                              string descriptionOfAvg,
                                              string descriptionOfMax,
                                              MetricsRecordingLevel recordingLevel,
                                              StreamMetricsRegistry streamsMetrics)
        {
            Sensor sensor =
                streamsMetrics.TaskLevelSensor(threadId, taskId, metricName, metricDescription, recordingLevel);
            var tags = streamsMetrics.TaskLevelTags(threadId, taskId.ToString());

            SensorHelper.AddAvgAndMaxToSensor(
                sensor,
                StreamMetricsRegistry.TASK_LEVEL_GROUP,
                tags,
                metricName,
                descriptionOfAvg,
                descriptionOfMax
                );

            return(sensor);
        }
예제 #19
0
 public MetricConfig SetRecordingLevel(MetricsRecordingLevel level)
 {
     RecordingLevel = level;
     return(this);
 }
 private Sensor GetSensor(
     string name,
     string description,
     MetricsRecordingLevel metricsRecordingLevel,
     params Sensor[] parents)
 => GetSensor <Sensor>(name, description, metricsRecordingLevel, parents);
예제 #21
0
 internal NoRunnableSensor(string name, string description, MetricsRecordingLevel metricsRecording)
     : base(name, description, metricsRecording)
 {
     NoRunnable = true;
 }
 private bool TestMetricsRecordingLevel(MetricsRecordingLevel metricsRecordingLevel)
 => recordingLevel.CompareTo(metricsRecordingLevel) >= 0;