internal void SetSdkMetricsRegistry(WavefrontSdkMetricsRegistry sdkMetricsRegistry)
        {
            this.sdkMetricsRegistry = sdkMetricsRegistry;

            // init internal metrics
            this.sdkMetricsRegistry.Gauge("reporter.queue.size", () => spanBuffer.Count);
            this.sdkMetricsRegistry.Gauge("reporter.queue.remaining_capacity",
                                          () => spanBuffer.BoundedCapacity - spanBuffer.Count);
            spansReceived = this.sdkMetricsRegistry.Counter("reporter.spans.received");
            spansDropped  = this.sdkMetricsRegistry.Counter("reporter.spans.dropped");
            reportErrors  = this.sdkMetricsRegistry.Counter("reporter.errors");
        }
Example #2
0
        protected internal ProxyConnectionHandler(string host, int port,
                                                  WavefrontSdkMetricsRegistry sdkMetricsRegistry, string entityPrefix,
                                                  ILoggerFactory loggerFactory)
        {
            this.host          = host;
            this.port          = port;
            this.loggerFactory = loggerFactory;
            reconnectingSocket = null;

            this.sdkMetricsRegistry = sdkMetricsRegistry;
            this.entityPrefix       = string.IsNullOrWhiteSpace(entityPrefix) ? "" : entityPrefix + ".";
            errors        = this.sdkMetricsRegistry.Counter(this.entityPrefix + "errors");
            connectErrors = this.sdkMetricsRegistry.Counter(this.entityPrefix + "connect.errors");
        }
Example #3
0
        private void InternalFlush(BlockingCollection <string> buffer, string format,
                                   string entityPrefix, WavefrontSdkCounter dropped, WavefrontSdkCounter reportErrors)
        {
            var batch = GetBatch(buffer);

            if (batch.Count == 0)
            {
                return;
            }

            try
            {
                using (var stream = BatchToStream(batch))
                {
                    int statusCode = directService.Report(format, stream);
                    sdkMetricsRegistry.Counter(entityPrefix + ".report." + statusCode).Inc();
                    if (statusCode >= 400 && statusCode < 600)
                    {
                        logger.LogWarning("Error reporting points, respStatus=" + statusCode);
                        int numAddedBackToBuffer = 0;
                        foreach (var item in batch)
                        {
                            if (buffer.TryAdd(item))
                            {
                                numAddedBackToBuffer++;
                            }
                            else
                            {
                                dropped.Inc(batch.Count - numAddedBackToBuffer);
                                logger.LogWarning("Buffer full, dropping attempted points");
                                return;
                            }
                        }
                    }
                }
            }
            catch (IOException e) {
                dropped.Inc(batch.Count);
                reportErrors.Inc();
                throw e;
            }
        }
        internal WavefrontSpan(
            WavefrontTracer tracer, string operationName, WavefrontSpanContext spanContext,
            DateTime startTimestampUtc, IList <Reference> parents, IList <Reference> follows,
            IList <KeyValuePair <string, string> > tags)
        {
            this.tracer            = tracer;
            this.operationName     = operationName;
            this.spanContext       = spanContext;
            this.startTimestampUtc = startTimestampUtc;
            this.parents           = parents;
            this.follows           = follows;
            this.spanLogs          = new List <SpanLog>();

            IList <KeyValuePair <string, string> > globalTags = tracer.Tags;

            if ((globalTags == null || globalTags.Count == 0) && (tags == null || tags.Count == 0))
            {
                this.tags = null;
            }
            else
            {
                this.tags = new List <KeyValuePair <string, string> >();
            }
            this.singleValuedTags = null;
            if (globalTags != null)
            {
                foreach (var tag in globalTags)
                {
                    SetTagObject(tag.Key, tag.Value);
                }
            }
            if (tags != null)
            {
                foreach (var tag in tags)
                {
                    SetTagObject(tag.Key, tag.Value);
                }
            }

            spansDiscarded = tracer.SdkMetricsRegistry?.Counter("spans.discarded");
        }
Example #5
0
        public MetricSnapshotWavefrontWriter(
            IWavefrontSender wavefrontSender,
            string source,
            IDictionary <string, string> globalTags,
            ISet <HistogramGranularity> histogramGranularities,
            WavefrontSdkMetricsRegistry sdkMetricsRegistry,
            MetricFields fields)
        {
            this.wavefrontSender        = wavefrontSender;
            this.source                 = source;
            this.globalTags             = globalTags;
            this.histogramGranularities = histogramGranularities;
            this.fields                 = fields;

            gaugesReported        = sdkMetricsRegistry.Counter("gauges.reported");
            deltaCountersReported = sdkMetricsRegistry.Counter("delta_counters.reported");
            countersReported      = sdkMetricsRegistry.Counter("counters.reported");
            wfHistogramsReported  = sdkMetricsRegistry.Counter("wavefront_histograms.reported");
            histogramsReported    = sdkMetricsRegistry.Counter("histograms.reported");
            metersReported        = sdkMetricsRegistry.Counter("meters.reported");
            timersReported        = sdkMetricsRegistry.Counter("timers.reported");
            apdexesReported       = sdkMetricsRegistry.Counter("apdexes.reported");
            writerErrors          = sdkMetricsRegistry.Counter("writer.errors");
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="T:Wavefront.SDK.CSharp.Common.ReconnectingSocket"/> class.
        /// </summary>
        /// <param name="host">The hostname of the Wavefront proxy.</param>
        /// <param name="port">The port number of the Wavefront proxy to connect to.</param>
        /// <param name="loggerFactory">The logger factory used to create a logger.</param>
        public ReconnectingSocket(string host, int port,
                                  WavefrontSdkMetricsRegistry sdkMetricsRegistry, string entityPrefix,
                                  ILoggerFactory loggerFactory)
        {
            this.host = host;
            this.port = port;
            logger    = loggerFactory.CreateLogger <ReconnectingSocket>() ??
                        throw new ArgumentNullException(nameof(loggerFactory));

            entityPrefix   = string.IsNullOrWhiteSpace(entityPrefix) ? "" : entityPrefix + ".";
            writeSuccesses = sdkMetricsRegistry.Counter(entityPrefix + "write.success");
            writeErrors    = sdkMetricsRegistry.Counter(entityPrefix + "write.errors");
            flushSuccesses = sdkMetricsRegistry.Counter(entityPrefix + "flush.success");
            flushErrors    = sdkMetricsRegistry.Counter(entityPrefix + "flush.errors");
            resetSuccesses = sdkMetricsRegistry.Counter(entityPrefix + "reset.success");
            resetErrors    = sdkMetricsRegistry.Counter(entityPrefix + "reset.errors");

            client = new TcpClient
            {
                ReceiveTimeout = serverReadTimeoutMillis
            };
            // Block while attempting to establish a connection
            ConnectAsync(false).GetAwaiter().GetResult();
        }
        public WavefrontReporter(MetricsReportingWavefrontOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (options.WavefrontSender == null)
            {
                throw new ArgumentNullException(
                          nameof(MetricsReportingWavefrontOptions.WavefrontSender));
            }

            wavefrontSender = options.WavefrontSender;

            source = options.Source;

            if (options.ApplicationTags != null)
            {
                globalTags = new Dictionary <string, string>(options.ApplicationTags.ToPointTags());
            }
            else
            {
                globalTags = new Dictionary <string, string>();
            }

            histogramGranularities = new HashSet <HistogramGranularity>();
            if (options.WavefrontHistogram.ReportMinuteDistribution)
            {
                histogramGranularities.Add(HistogramGranularity.Minute);
            }
            if (options.WavefrontHistogram.ReportHourDistribution)
            {
                histogramGranularities.Add(HistogramGranularity.Hour);
            }
            if (options.WavefrontHistogram.ReportDayDistribution)
            {
                histogramGranularities.Add(HistogramGranularity.Day);
            }

            if (options.FlushInterval < TimeSpan.Zero)
            {
                throw new InvalidOperationException(
                          $"{nameof(MetricsReportingWavefrontOptions.FlushInterval)} " +
                          "must not be less than zero");
            }

            Filter = options.Filter;

            FlushInterval = options.FlushInterval > TimeSpan.Zero
                ? options.FlushInterval
                : AppMetricsConstants.Reporting.DefaultFlushInterval;

            // Formatting will be handled by the Wavefront sender.
            Formatter = null;

            metricFields = options.MetricFields ?? new MetricFields();

            var registryBuilder = new WavefrontSdkMetricsRegistry.Builder(wavefrontSender)
                                  .Prefix(Constants.SdkMetricPrefix + ".app_metrics")
                                  .Source(source)
                                  .Tags(globalTags);

            if (options.LoggerFactory != null)
            {
                registryBuilder.LoggerFactory(options.LoggerFactory);
            }
            sdkMetricsRegistry = registryBuilder.Build();

            reporterErrors = sdkMetricsRegistry.Counter("reporter.errors");

            double sdkVersion = Utils.GetSemVer(Assembly.GetExecutingAssembly());

            sdkMetricsRegistry.Gauge("version", () => sdkVersion);

            Logger.Info($"Using Wavefront Reporter {this}. FlushInterval: {FlushInterval}");
        }