How to Call Prometheus API to Get CPU Utilization and Memory Utilization

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 如何调用 prometheus api 接口获取CPU利用率和内存利用率

| username: HPDONG

Hello everyone, I want to call the Prometheus API in Java code to get the CPU and memory utilization at a specific point in time, and then perform subsequent logic processing. The examples given in the official documentation are somewhat brief, and I don’t understand exactly how to call the URL, plus I noticed that the URL changes from time to time. So, I would like to ask how to call this URL.

The related post I found is this: Best Practices for Monitoring TiDB with Grafana | PingCAP Documentation Center in tip 7.

| username: DBAER | Original post link

Similar to this
Python calls Prometheus monitoring data and calculates - Iron Man’s Knowledge Base - cnblogs.com

| username: TiDBer_JUi6UvZm | Original post link

Please post the official link.

| username: HPDONG | Original post link

Okay, thank you! I’ll look into it.

| username: HPDONG | Original post link

Okay, I have re-edited it.

| username: 小龙虾爱大龙虾 | Original post link

Just follow the standard, TiDB comes with the standard Prometheus.

| username: 像风一样的男子 | Original post link

Prometheus data is stored in a time-series database, and you can directly query it to obtain monitoring data.

| username: zhaokede | Original post link

Directly access the Prometheus API to obtain the relevant information?

| username: shigp_TIDBER | Original post link

I also want to learn more…

| username: stephanie | Original post link

I see that TiDB directly uses Prometheus, so you can refer to the Prometheus documentation to learn how to call the API. For example, the following link might be helpful:
client_java (prometheus.github.io)

| username: 洪七表哥 | Original post link

You can directly query in the Prometheus library, but you need to study the documentation for specific usage.

| username: zhang_2023 | Original post link

Just call the Prometheus API directly.

| username: DBRE | Original post link

Prometheus API documentation

| username: wangkk2024 | Original post link

Learned.

| username: 不想干活 | Original post link

Just call it directly.

| username: TiDBer_QYr0vohO | Original post link

Check the official Prometheus API documentation, it should be there.

| username: xiaoqiao | Original post link

Prometheus API has