Example #1
0
        private void WriteHistogram(string context, string name, IDictionary <string, object> data,
                                    MetricTags tags, DateTime timestamp)
        {
            // Report Wavefront Histograms using an API that is specific to Wavefront Histograms.
            if (WavefrontHistogramOptions.IsWavefrontHistogram(tags))
            {
                name = Concat(context, name);

                // Wavefront Histograms are reported as a distribution, so we must extract the
                // distribution from a HistogramValue that is carrying it in a serialized format.
                string keyFieldName   = fields.Histogram[HistogramFields.UserMaxValue];
                string valueFieldName = fields.Histogram[HistogramFields.UserMinValue];

                if (data.ContainsKey(keyFieldName) && data.ContainsKey(valueFieldName))
                {
                    string key   = (string)data[keyFieldName];
                    string value = (string)data[valueFieldName];

                    // Deserialize the distributions into the right format for reporting.
                    var distributions = WavefrontHistogramImpl.Deserialize(
                        new KeyValuePair <string, string>(key, value));

                    foreach (var distribution in distributions)
                    {
                        wavefrontSender.SendDistribution(
                            name,
                            distribution.Centroids,
                            histogramGranularities,
                            distribution.Timestamp,
                            source,
                            FilterTags(tags)
                            );
                    }
                }
            }
            else
            {
                foreach (var field in fields.Histogram)
                {
                    // Do not report non-numerical metrics
                    if (field.Key == HistogramFields.UserLastValue ||
                        field.Key == HistogramFields.UserMaxValue ||
                        field.Key == HistogramFields.UserMinValue)
                    {
                        continue;
                    }

                    if (data.ContainsKey(field.Value))
                    {
                        WriteInternal(context, name, field.Value, data[field.Value], tags,
                                      timestamp);
                    }
                }
            }
        }
Example #2
0
        /// <inheritdoc />
        public void Write(string context, string name, IEnumerable <string> columns,
                          IEnumerable <object> values, MetricTags tags, DateTime timestamp)
        {
            // Do not report App Metrics' internal metrics (e.g., report_success counter)
            if (context == InternalMetricsContext)
            {
                return;
            }

            try
            {
                string metricTypeValue =
                    tags.Values[Array.IndexOf(tags.Keys, Pack.MetricTagsTypeKey)];
                var data = columns.Zip(values, (column, value) => new { column, value })
                           .ToDictionary(pair => pair.column, pair => pair.value);

                if (metricTypeValue == Pack.ApdexMetricTypeValue)
                {
                    WriteApdex(context, name, data, tags, timestamp);
                    apdexesReported.Inc();
                }
                else if (metricTypeValue == Pack.CounterMetricTypeValue)
                {
                    WriteCounter(context, name, data, tags, timestamp);
                    if (DeltaCounterOptions.IsDeltaCounter(tags))
                    {
                        deltaCountersReported.Inc();
                    }
                    else
                    {
                        countersReported.Inc();
                    }
                }
                else if (metricTypeValue == Pack.GaugeMetricTypeValue)
                {
                    WriteGauge(context, name, data, tags, timestamp);
                    gaugesReported.Inc();
                }
                else if (metricTypeValue == Pack.HistogramMetricTypeValue)
                {
                    WriteHistogram(context, name, data, tags, timestamp);
                    if (WavefrontHistogramOptions.IsWavefrontHistogram(tags))
                    {
                        wfHistogramsReported.Inc();
                    }
                    else
                    {
                        histogramsReported.Inc();
                    }
                }
                else if (metricTypeValue == Pack.MeterMetricTypeValue)
                {
                    WriteMeter(context, name, data, tags, timestamp);
                    metersReported.Inc();
                }
                else if (metricTypeValue == Pack.TimerMetricTypeValue)
                {
                    WriteMeter(context, name, data, tags, timestamp);
                    WriteHistogram(context, name, data, tags, timestamp);
                    timersReported.Inc();
                }
            }
            catch (Exception e)
            {
                writerErrors.Inc();
                throw e;
            }
        }