Sobes.tech
Senior

What type of Prometheus metric is best suited for a graph of order quantities?

sobes.tech AI

Answer from AI

The best way to display the number of orders is to use a Counter metric in Prometheus. A Counter is a monotonically increasing metric, which is ideal for counting events such as order creation.

Example of defining a counter in Java using the Prometheus client library:

import io.prometheus.client.Counter;

public class OrderService {
    static final Counter ordersCounter = Counter.build()
        .name("orders_total")
        .help("Total number of orders created.")
        .register();

    public void createOrder() {
        // order creation logic
        ordersCounter.inc(); // increment the counter by 1
    }
}

This counter can be used to plot the number of orders over time, and if needed, to calculate the rate of order creation using Prometheus functions.