Table of Contents
Question content
Workaround
Home Java Prometheus /metrics page is not updated after calling counter

Prometheus /metrics page is not updated after calling counter

Feb 11, 2024 pm 05:09 PM

php editor Zimo encountered a problem when using the Prometheus monitoring tool: after calling the counter, the Prometheus /metrics page was not updated. The occurrence of this problem may lead to inaccurate monitoring data and cause certain problems to the operation of the system. In order to solve this problem, we need to find out the cause and take corresponding measures. In the following content, we will step by step analyze the possible causes and provide solutions to help readers solve this problem.

Question content

I have a spring bean in which the instrument is initialized like this:

@postconstruct
    public void initgauge() {
        paymentstriedgauge = gauge.build().name("payments_tried").help("how many payments was sent to paymentservices to be created").register(registry.getprometheusregistry());
        paymentscreated = gauge.build().name("payments_created").help("how many payments sent to paymentservices were created").register(registry.getprometheusregistry());
    }
Copy after login

Where does the registry come from

@autowired
prometheusmeterregistry registry;
Copy after login

Then I use a method:

paymentstriedgauge.inc();
Copy after login

But then I didn't receive any updates on promtheus's /metrics page:

# HELP payments_tried How many payments was sent to PaymentServices to be created
# TYPE payments_tried gauge
payments_tried 0.0
Copy after login

Workaround

Use prometheus instrumentation directly for your use case. The micrometer itself can be used with its own meter. (no spring boot required)

For example:

// maintain a reference to myGauge
AtomicInteger myGauge = registry.gauge("numberGauge", new AtomicInteger(0));

// ... elsewhere you can update the value it holds using the object reference
myGauge.set(27);
myGauge.set(11);
Copy after login

Please note that the variable mygauge is actually an atomicinteger and micrometer simply reports the value of that instance. atomicinteger There is also an increment() method that you can use nicely.

The above is the detailed content of Prometheus /metrics page is not updated after calling counter. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)