Exemple #1
0
        private void WriteCounter(string context, string name, IDictionary <string, object> data,
                                  MetricTags tags, DateTime timestamp)
        {
            bool isDeltaCounter = DeltaCounterOptions.IsDeltaCounter(tags);

            foreach (var field in fields.Counter)
            {
                if (data.ContainsKey(field.Value))
                {
                    var suffix = field.Value.Equals("value") ? "count" : field.Value;
                    // Report delta counters using an API that is specific to delta counters.
                    if (isDeltaCounter)
                    {
                        wavefrontSender.SendDeltaCounter(
                            Concat(context, name, suffix),
                            Convert.ToDouble(data[field.Value]),
                            source,
                            FilterTags(tags)
                            );
                    }
                    else
                    {
                        WriteInternal(context, name, suffix, data[field.Value], tags, timestamp);
                    }
                }
            }
        }
Exemple #2
0
            /// <summary>
            ///     Creates a new <see cref="DeltaCounterOptions"/> instance. In order for the
            ///     delta counter to be reported correctly, the fields for the new instance
            ///     should not be changed after the instance is created.
            /// </summary>
            /// <returns>A new <see cref="DeltaCounterOptions"/></returns>
            public DeltaCounterOptions Build()
            {
                var options = new DeltaCounterOptions()
                {
                    Name             = name,
                    ResetOnReporting = resetOnReporting
                };

                if (context != null)
                {
                    options.Context = context;
                }

                options.MeasurementUnit = measurementUnit;

                if (reportItemPercentages.HasValue)
                {
                    options.ReportItemPercentages = reportItemPercentages.Value;
                }
                if (reportSetItems.HasValue)
                {
                    options.ReportSetItems = reportSetItems.Value;
                }

                options.Tags = MetricTags.Concat(tags, new MetricTags(
                                                     WavefrontConstants.WavefrontMetricTypeTagKey, WavefrontMetricTypeTagValue));

                return(options);
            }
Exemple #3
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;
            }
        }