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"); }
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; } }
/// <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}"); }