/// <inheritdoc /> public Task WriteAsync( Stream output, MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { if (output == null) { throw new ArgumentNullException(nameof(output)); } var serializer = new MetricSnapshotSerializer(); using (var streamWriter = new StreamWriter(output)) { using (var textWriter = new MetricSnapshotGraphitePlainTextProtocolWriter( streamWriter, _options.MetricPointTextWriter, _options.MetricNameMapping)) { serializer.Serialize(textWriter, metricsData); } } #if !NETSTANDARD1_6 return(AppMetricsTaskHelper.CompletedTask()); #else return(Task.CompletedTask); #endif }
/// <inheritdoc /> public Task WriteAsync( Stream output, MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { if (output == null) { throw new ArgumentNullException(nameof(output)); } var serializer = new MetricSnapshotSerializer(); using (var streamWriter = new StreamWriter(output, _options.Encoding, bufferSize: 1024, leaveOpen: true)) { using (var textWriter = new MetricSnapshotTextWriter( streamWriter, _options.Separator, _options.Padding, _options.MetricNameFormatter)) { serializer.Serialize(textWriter, metricsData, MetricFields); } } #if NETSTANDARD1_6 return(Task.CompletedTask); #else return(AppMetricsTaskHelper.CompletedTask()); #endif }
public Task WriteAsync(Stream output, MetricsDataValueSource metricsData, CancellationToken cancellationToken = default(CancellationToken)) { if (output == null) { throw new ArgumentNullException(nameof(output)); } var serilizerJson = JsonSerializer.Create(); //using (var streamWriter = new StreamWriter(output)) //{ // // TODO: #251 should apply metric field names // using (var textWriter = new JsonTextWriter(streamWriter)) // { // serilizerJson.Serialize(textWriter, metricsData); // } //} var serializer = new MetricSnapshotSerializer(); using (var streamWriter = new StreamWriter(output)) { using (var textWriter = new MetricSnapshotAliTSDBLineProtocolWriter(streamWriter, _options.MetricNameFormatter)) { serializer.Serialize(textWriter, metricsData); } } #if !NETSTANDARD1_6 return(AppMetricsTaskHelper.CompletedTask()); #else return(Task.CompletedTask); #endif }
private async Task <string> Serialize( IEnumerable <MetricsDataValueSource> dataValueSource, double sampleRate = 1.0) { var settings = new MetricsStatsDOptions { DefaultSampleRate = sampleRate, MetricNameFormatter = new DefaultDogStatsDMetricStringSerializer() }; var serializer = new MetricSnapshotSerializer(); var fields = new MetricFields(); await using (var ms = new MemoryStream()) { await using (var packer = new MetricSnapshotStatsDStringWriter( ms, new StatsDPointSampler(settings), settings)) { foreach (var source in dataValueSource) { serializer.Serialize(packer, source, fields); } } return(Encoding.UTF8.GetString(ms.ToArray())); } }
/// <inheritdoc /> public Task WriteAsync( Stream output, MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { if (output == null) { throw new ArgumentNullException(nameof(output)); } var serializer = new MetricSnapshotSerializer(); using (var streamWriter = new StreamWriter(output)) { using (var textWriter = new MetricSnapshotHostedMetricsJsonWriter( streamWriter, _flushInterval, _options.MetricNameFormatter)) { serializer.Serialize(textWriter, metricsData, MetricFields); } } #if !NETSTANDARD1_6 return(AppMetricsTaskHelper.CompletedTask()); #else return(Task.CompletedTask); #endif }
public MetricsStatsDStringOutputFormatter( MetricsStatsDOptions options, MetricFields metricFields) { _options = options ?? throw new ArgumentNullException(nameof(options)); MetricFields = metricFields ?? new MetricFields(); _samplers = new StatsDPointSampler(_options); _nullWriter = new MetricSnapshotStatsDStringWriter(null, _samplers, _options); _serializer = new MetricSnapshotSerializer(); }
private async Task WriteAsync( MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { var serializer = new MetricSnapshotSerializer(); await using var writer = new MetricSnapshotWavefrontWriter(wavefrontSender, source, globalTags, histogramGranularities, sdkMetricsRegistry, metricFields); serializer.Serialize(writer, metricsData, metricFields); }
/// <inheritdoc /> public Task WriteAsync(Stream output, MetricsDataValueSource metricsData, CancellationToken cancellationToken = new CancellationToken()) { var serializer = new MetricSnapshotSerializer(); using (var streamWriter = new StreamWriter(output)) { using (var writer = new MetricSnapshotDatadogWriter(streamWriter, _options)) serializer.Serialize(writer, metricsData); } return(Task.CompletedTask); }
private async Task AssertExpectedLineProtocolString(MetricsDataValueSource dataValueSource, TimeSpan flushInterval, string expected) { var settings = new DatadogOptions(); var serializer = new MetricSnapshotSerializer(); var fields = new MetricFields(); await using var ms = new MemoryStream(); await using (var packer = new MetricSnapshotDatadogJsonWriter(ms, flushInterval)) { serializer.Serialize(packer, dataValueSource, fields); } Encoding.UTF8.GetString(ms.ToArray()).Should().Be(expected); }
/// <summary> /// Writes the specified <see cref="MetricsDataValueSource" /> to the configured /// <see cref="IWavefrontSender" />. /// </summary> /// <param name="metricsData"> /// The <see cref="MetricsDataValueSource" /> being written. /// </param> /// <param name="cancellationToken">The <see cref="CancellationToken" /></param> /// <returns>A <see cref="Task" /> representing the asynchronous write operation.</returns> #if NET452 private Task WriteAsync( MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { var serializer = new MetricSnapshotSerializer(); using (var writer = new MetricSnapshotWavefrontWriter(wavefrontSender, source, globalTags, histogramGranularities, sdkMetricsRegistry, metricFields)) { serializer.Serialize(writer, metricsData, metricFields); } return(AppMetricsTaskHelper.CompletedTask()); }
private async Task AssertExpectedLineProtocolString(MetricsDataValueSource dataValueSource, string expected) { var settings = new MetricsInfluxDbLineProtocolOptions(); var serializer = new MetricSnapshotSerializer(); var fields = new MetricFields(); await using var sw = new StringWriter(); await using (var packer = new MetricSnapshotInfluxDbLineProtocolWriter(sw, settings.MetricNameFormatter)) { serializer.Serialize(packer, dataValueSource, fields); } sw.ToString().Should().Be(expected); }
/// <inheritdoc /> public async Task WriteAsync( Stream output, MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { if (output == null) { throw new ArgumentNullException(nameof(output)); } var serializer = new MetricSnapshotSerializer(); await using var writer = new MetricSnapshotStatsDStringWriter(output, _samplers, _options); serializer.Serialize(writer, metricsData, MetricFields); }
private void AssertExpectedLineProtocolString(MetricsDataValueSource dataValueSource, string expected) { var settings = new MetricsGraphitePlainTextProtocolOptions(); var serializer = new MetricSnapshotSerializer(); using (var sw = new StringWriter()) { using (var packer = new MetricSnapshotGraphitePlainTextProtocolWriter(sw, settings.MetricPointTextWriter, settings.MetricNameMapping)) { serializer.Serialize(packer, dataValueSource); } sw.ToString().Should().Be(expected); } }
private async Task AssertExpectedLineProtocolString(MetricsDataValueSource dataValueSource, string expected) { var settings = new MetricsGraphitePlainTextProtocolOptions(); var serializer = new MetricSnapshotSerializer(); var fields = new MetricFields(); fields.DefaultGraphiteMetricFieldNames(); await using var sw = new StringWriter(); await using (var packer = new MetricSnapshotGraphitePlainTextProtocolWriter(sw, settings.MetricPointTextWriter)) { serializer.Serialize(packer, dataValueSource, fields); } sw.ToString().Should().Be(expected); }
/// <inheritdoc/> public async Task WriteAsync( Stream output, MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { if (output == null) { throw new ArgumentNullException(nameof(output)); } var serializer = new MetricSnapshotSerializer(); await using var streamWriter = new StreamWriter(output, Encoding, bufferSize: 1024, leaveOpen: true); await using var textWriter = new MetricSnapshotInfluxDbLineProtocolWriter( streamWriter, _options.MetricNameFormatter); serializer.Serialize(textWriter, metricsData, MetricFields); }
/// <inheritdoc /> public async Task WriteAsync( Stream output, MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { if (output == null) { throw new ArgumentNullException(nameof(output)); } var serializer = new MetricSnapshotSerializer(); await using var jsonWriter = new MetricSnapshotHostedMetricsJsonWriter( output, _flushInterval, _options.MetricNameFormatter); serializer.Serialize(jsonWriter, metricsData, MetricFields); }
/// <inheritdoc /> public async Task WriteAsync( Stream output, MetricsDataValueSource metricsData, CancellationToken cancellationToken = default) { if (output == null) { throw new ArgumentNullException(nameof(output)); } var serializer = new MetricSnapshotSerializer(); await using (var streamWriter = new StreamWriter(output)) { await using var textWriter = new MetricSnapshotGraphitePlainTextProtocolWriter(streamWriter, _options.MetricPointTextWriter); serializer.Serialize(textWriter, metricsData, MetricFields); } return; }
public async Task Can_apply_ascii_metric_formatting() { // Arrange var counter = new CounterOptions { Context = "test", Name = "counter1" }; var serializer = new MetricSnapshotSerializer(); var fields = new MetricFields(); // Act _fixture.Metrics.Measure.Counter.Increment(counter); await using var sw = new StringWriter(); await using (var writer = new MetricSnapshotTextWriter(sw)) { serializer.Serialize(writer, _fixture.Metrics.Snapshot.Get(), fields); } // Assert sw.ToString().Should().Be( "# TIMESTAMP: 0\n# MEASUREMENT: [test] counter1\n# TAGS:\n mtype = counter\n unit = none\n# FIELDS:\n value = 1\n--------------------------------------------------------------\n"); }
public void Can_apply_ascii_metric_formatting_with_custom_name_formatter() { // Arrange var counter = new CounterOptions { Context = "test", Name = "counter1" }; var serializer = new MetricSnapshotSerializer(); // Act _fixture.Metrics.Measure.Counter.Increment(counter); using (var sw = new StringWriter()) { using (var packer = new MetricSnapshotTextWriter(sw, metricNameFormatter: (context, name) => $"{context}---{name}")) { serializer.Serialize(packer, _fixture.Metrics.Snapshot.Get()); } // Assert sw.ToString().Should().Be( "# TIMESTAMP: 0\n# MEASUREMENT: test---counter1\n# TAGS:\n mtype = counter\n unit = none\n# FIELDS:\n value = 1\n--------------------------------------------------------------\n"); } }