使用计数器,服务器崩溃后如何继续计数?

I wrote a naive client Prometheus in Go.

It just create a counter and increment it 3 times:

counter = prometheus.NewCounter(prometheus.CounterOpts {
    Name: "test_count_0",
    Help: "Just a test man, no worries",
})

counter.Inc() 
counter.Inc() 
counter.Inc()

In Prometheus tab I can see "3" on graph, using query "test_count_0", after run it. All good.

But, if I run client again, will appear another "3" on graph.

I was expecting "6" (I thought that using same name will automatically update previous counter).

How can I increment counter that already exists? I just can't find the way to do it.

The rate() function and friends automatically handle counter resets. It would be very rare that you would use the value of a counter directly in PromQL.