Exemple #1
0
        protected override IEnumerable <ITelemetry> Transform(IEnumerable <ITelemetry> items)
        {
            try
            {
                return(MetricsAggregator.AggregateToEventTelemetry(items));
            }
            catch (Exception e)
            {
                _logger?.LogError(0, e, $"{nameof(AppInsightAggMetricSink)}.{nameof(Transform)} Failed");
            }

            return(null);
        }
Exemple #2
0
        protected override IList <string> Transform(IEnumerable <ITelemetry> evts)
        {
            var contentList = new List <string>();

            try
            {
                // Aggregate MetricTelemetry with same Metric "Name"
                //	==> returns EventTelemetry which contains Metrics and Properties
                var eventTelemetry = MetricsAggregator.AggregateToEventTelemetry(evts);

                foreach (var e in eventTelemetry)
                {
                    var me = e as EventTelemetry;
                    if (me != null)
                    {
                        // Build the metric name for Graphite using EventTelemetryProperties
                        // NOTE: properties are used in default order (specified in config file)
                        StringBuilder sbMetricName = new StringBuilder();
                        foreach (var propName in graphiteTelemetryProperties.EventTelemetryProperties)
                        {
                            if (sbMetricName.Length > 0)
                            {
                                sbMetricName.Append(".");
                            }
                            sbMetricName.Append($"{me.GetProperty(propName, propName)}");
                        }
                        sbMetricName.Append($".{me.Name}");

                        var metricName = GraphiteFormat(sbMetricName.ToString());

                        contentList.Add(GraphiteEntry(metricName, MetricProps.Avg, $"{me.Metrics[MetricProps.Avg]}", me.Timestamp));
                        contentList.Add(GraphiteEntry(metricName, MetricProps.Min, $"{me.Metrics[MetricProps.Min]}", me.Timestamp));
                        contentList.Add(GraphiteEntry(metricName, MetricProps.Max, $"{me.Metrics[MetricProps.Max]}", me.Timestamp));
                        contentList.Add(GraphiteEntry(metricName, MetricProps.Count, $"{me.Metrics[MetricProps.Count]}", me.Timestamp));
                        contentList.Add(GraphiteEntry(metricName, MetricProps.StdDev, $"{me.Metrics[MetricProps.StdDev]}", me.Timestamp));
                        contentList.Add(GraphiteEntry(metricName, MetricProps.P50, $"{me.Metrics[MetricProps.P50]}", me.Timestamp));
                        contentList.Add(GraphiteEntry(metricName, MetricProps.P90, $"{me.Metrics[MetricProps.P90]}", me.Timestamp));
                        contentList.Add(GraphiteEntry(metricName, MetricProps.P95, $"{me.Metrics[MetricProps.P95]}", me.Timestamp));
                        contentList.Add(GraphiteEntry(metricName, MetricProps.P99, $"{me.Metrics[MetricProps.P99]}", me.Timestamp));
                    }
                }
            }
            catch (Exception e)
            {
                _logger?.LogError(0, e, "AppInsightGraphiteSink.GeContent Failed");
            }

            return(contentList);
        }