Skip to content

.NET implementation of generating queries in Prometheus Query Language

Notifications You must be signed in to change notification settings

caunt/PromQL.NET

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PromQL.NET

NuGet version (PromQL.NET)

PromQL has two basic types of data on which you can select and aggregate time series data in real time.

So were going to talk about instant vector and range vector.

Example #1:

Create InstantVector and apply "sum" aggregation operator on it: https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators

var query = InstantVector
    .WithString("http_requests_total")
    .Sum();

Console.WriteLine(query);
// OUTPUT: sum(http_requests_total)

Example #2:

For now were using RangeVector instead of InstantVector, selecting http requests count per instance, and sorting it in descending order:

var query = RangeVector
    .WithString("http_requests_total", TimeSpan.FromSeconds(15))
    .SumOverTime()  // Same "sum" aggregation operator as in InstantVector, but applies to RangeVector and returns as result InstantVector (!) instead of RangeVector
    .SumWithFilter(
        LabelFilter.Create()
            .WithType(LabelFilterType.By)
            .AddField("instance"))
    .SortDescending();

Console.WriteLine(query);
// OUTPUT: sort_desc(sum by (instance) (sum_over_time(http_requests_total[15s])))

Our goal is to make everything to work as expected and prevent wrong syntax in generated prometheus queries.

About

.NET implementation of generating queries in Prometheus Query Language

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages