This is a .NET library that parses Prometheus metrics output.
The library targets:
- .NET Standard 2.0
- .NET 5
Text payload:
# HELP kafka_consumer_lag Provides kafka consumer lag
# TYPE kafka_consumer_lag gauge
kafka_consumer_lag{groupId="gr0",topic="mytopic",partition="18"} 4
Parse metrics:
var payload = "...";
var metrics = Prometh.Metrics.Parse(payload);
Get particular metric value:
var payload = "...";
var name = "kafka_consumer_lag";
var labels = new Dictionary<string, string>
{
["groupId"] = "gr0",
["topic"] = "mytopic",
["partition"] = "18",
};
var value = Prometh.Metrics.Parse(payload, name, labels);
// value is 4
The library is available as a NuGet package.