There are many usages of the counter metric. We can measure the number of requests entering the system, the number of bytes sent through the network, the number of errors, and so on. Whenever we want to record an incremental value, a counter is a good choice.
We'll use counter to track errors produced by a service. With such a goal, a counter is usually put around code that handles errors.
The examples that follow are taken from Docker Flow Swarm Listener (http://swarmlistener.dockerflow.com/). The code is written in Go. Do not be afraid if that is not your language of choice. As you will see, examples are straightforward and can be easily extrapolated to any programming language.
Prometheus provides client libraries (https://prometheus.io/docs/instrumenting/clientlibs/) for a myriad of languages. Even if your favorite language is not...