通过grafana+prometheus监控业务的运行状态
通过grafana+prometheus监控业务的运行状态
本文介绍了如何通过grafana+prometheus监控业务的运行状态。可以通过grafana的web界面监控业务进程的内存占用和cpu耗时,并且通过在业务中集成prometheus-cpp开源库,监控业务的各项指标,既可以显示实时曲线,也可以是直方图。方便业务运行过程中的状态检测、趋势分析和告警。
版本信息
属性 | 值 |
---|---|
操作系统 | CentOS Linux release 7.6.1810 |
grafana | 9.5.2 |
prometheus | 2.45.3 |
prometheus-cpp | commit 4e0814ee3f93b796356a51a4795a332568940a72 |
操作步骤
准备工作
编译prometheus-cpp
git clone https://github.com/jupp0r/prometheus-cpp.git --recursive
cd prometheus-cpp
git checkout 4e0814ee3f93b796356a51a4795a332568940a72
git submodule update --recursive
rm build -rf
mkdir build
cd build/
cmake -DCMAKE_INSTALL_PREFIX=`pwd`/_install ..
make -j
make install
在业务中集成prometheus-cpp
#include <unistd.h>
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include <string.h>
#include <math.h>
#include <random>
#include <prometheus/counter.h>
#include <prometheus/exposer.h>
#include <prometheus/registry.h>
using namespace prometheus;
using namespace std;
std::map<unsigned int, prometheus::Gauge *> counterMap;
int main(int argc, char *argv[])
{
Exposer exposer{"0.0.0.0:8007"};
auto registry = std::make_shared<Registry>();
auto &packet_counter = BuildGauge()
.Name("service_metric")
.Help("service_metric")
.Register(*registry);
exposer.RegisterCollectable(registry);
{
auto &counter = packet_counter.Add({
{"metric", "fps"}});
auto ret = counterMap.insert(std::map<unsigned int, prometheus::Gauge *>::value_type(0, &counter));
}
{
auto &counter = packet_counter.Add({
{&#
原文地址:https://blog.csdn.net/m0_61864577/article/details/136235214
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!