Prometheus Forwarding Agent Example (4.0)

In this example, we have *.csv input files containing information about registered members and we want to produce metrics for the number of members from each country present in each processed file and forward the metrics to Prometheus to display them in a graph on a dashboard.

Below is a snippet of the input records, the corresponding Ultra Format Definition, and the graph that we want to produce.

promUS.png
*.csv file, Ultra Format Definition and graph

In this case it is recommended to use PrometheusUDRs (instead of MIMs) for the following reasons:

  • The labels of the metrics (countries in this case), is not known in advance.

  • The regularity of publishing the metrics needs to be decided by the user.

Designing the Workflow

The workflow handling the data in this example contains an Aggregation agent that consolidates the metrics for each country present in the input data since we do not want to publish metrics for each record processed. The consolidated metrics are then forwarded to an Analysis agent that maps the aggregated data to a PrometheusUDR before sending it to a Prometheus Agent.

promWF.png
Workflow design

Analysis Agent Configuration

The Analysis Agent is configured with the following code:

consume { debug(input); PrometheusUDR promUDR = udrCreate(PrometheusUDR); map<string,string> labels = mapCreate(string,string); mapSet(labels, "country", input.countryOfOrigin); promUDR.Description = "Sum of members' country of origin."; promUDR.Labels = labels; promUDR.MetricType = "GAUGE"; promUDR.Name = "NoOfMembersPerCountry"; promUDR.Value = input.count; debug(promUDR); udrRoute(promUDR); }

Debug Examples

The debug output from the Analysis agent for one of the countries (France) will look like this:

Field Values for: Prometheus.UFL_input.countryAggregate
countryOfOrigin: France
count: 1265

Field Values for: PrometheusUDR
Description: Sum of members' country of origin.
MetricType: GAUGE
Value: 1265.0
Labels: {country=France }
Name: NoOfMembersPerCountry

The first entry is the incoming aggregated UDR, and the second is the PrometheusUDR that is forwarded to the Prometheus Agent.