Skip to content

Commit

Permalink
Lint issues and re-add the properties; not sure if we need them or not
Browse files Browse the repository at this point in the history
  • Loading branch information
hananiel committed Jan 26, 2022
1 parent b11b0b6 commit cfb4d0f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,22 @@ private void ExtractAndPostMetric(string eventSourceName, IDictionary<string, ob
}
}
}
else if (key.Equals("Metadata", StringComparison.OrdinalIgnoreCase))
{
var metadata = payload.Value.ToString();
if (!string.IsNullOrEmpty(metadata))
{
var keyValuePairStrings = metadata.Split(',');
foreach (var keyValuePairString in keyValuePairStrings)
{
var keyValuePair = keyValuePairString.Split(':');
if (!metricTelemetry.Properties.ContainsKey(keyValuePair[0]))
{
metricTelemetry.Properties.Add(keyValuePair[0], keyValuePair[1]);
}
}
}
}
}

if (calculateRate)
Expand All @@ -254,6 +270,11 @@ private void ExtractAndPostMetric(string eventSourceName, IDictionary<string, ob
metricTelemetry.DisplayName = string.IsNullOrEmpty(counterDisplayName) ? counterName : counterDisplayName;
metricTelemetry.EventSource = eventSourceName;

if (!string.IsNullOrEmpty(counterDisplayUnit))
{
metricTelemetry.Properties.Add("DisplayUnits", counterDisplayUnit);
}

metricTelemetry.Count = actualCount;
this.telemetryPublisher.Publish(metricTelemetry);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ internal class MetricTelemetry
/// </summary>
public string EventSource { get; set; }

/// <summary>
/// Gets a dictionary of application-defined property names and values providing additional information about this metric.
/// </summary>
public Dictionary<string, string> Properties { get; } = new Dictionary<string, string>();

/// <summary>
/// Gets or sets sum of the values of the metric samples.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ namespace DotnetMetrics
using var meterprovider = Sdk.CreateMeterProviderBuilder()
.AddEventCounters(options =>
{
options.AddEventSource("Microsoft-AspNetCore-Server-Kestrel")
.WithCounters("total-connections", "connections-per-second")
.With(
"connections-per-second",
"The number of connections per update interval to the web server",
MetricType.LongSum);
options.AddEventSource("Microsoft-AspNetCore-Server-Kestrel")
.WithCounters("total-connections", "connections-per-second")
.With(
"connections-per-second",
"The number of connections per update interval to the web server",
MetricType.LongSum);
})
.AddConsoleExporter()
.Build();
Expand Down Expand Up @@ -105,7 +105,7 @@ builder.Services.AddOpenTelemetryMetrics(
.AddPrometheusExporter()
.AddEventCounters(options =>
{
builder.Configuration.GetSection("Telemetry").Bind(options);
builder.Configuration.GetSection("Telemetry").Bind(options);
}));

var app = builder.Build();
Expand Down

0 comments on commit cfb4d0f

Please sign in to comment.