Prometheus+Grafana可视化监控【主机状态】

文章目录

    • 一、介绍
    • 二、安装Prometheus
    • 三、安装Grafana
    • 四、Pronetheus和Grafana相关联
    • 五、监控服务器状态
    • 六、常见问题

一、介绍

Prometheus是一个开源的系统监控和报警系统,现在已经加入到CNCF基金会,成为继k8s之后第二个在CNCF托管的项目,在kubernetes容器管理系统中,通常会搭配prometheus进行监控,同时也支持多种exporter采集数据,还支持pushgateway进行数据上报,Prometheus性能足够支撑上万台规模的集群。
Prometheus优点:

  • 通过PromQL实现多维度数据模型的灵活查询。
  • 定义了开放指标数据的标准,自定义探针(如Exporter等),编写简单方便。
  • PushGateway组件让这款监控系统可以接收监控数据。

Grafana是一个开源的可视化系统,使用Grafana展示页面更美观。

二、安装Prometheus

1、时间和时区同步
对于监控系统而言,时间不同步会严重导致采集数据失败,或采集数据不准确!

# 时区同步
timedatectl set-timezone Asia/Shanghai# 时间同步
yum -y install ntpdate
/usr/sbin/ntpdate -u ntp1.aliyun.com

2、针对时间做定时同步

# 每天凌晨5点进行时间同步
echo "0 5 * * * /usr/sbin/ntpdate -u ntp1.aliyun.com >/dev/null &" >> /var/spool/cron/root# 查看定时任务
crontab -l

3、安装Prometheus
prometheus官方下载地址:

wget https://github.com/prometheus/prometheus/releases/download/v2.42.0/prometheus-2.42.0.linux-amd64.tar.gztar zxf prometheus-2.42.0.linux-amd64.tar.gz 
mv prometheus-2.42.0.linux-amd64 /usr/local/prometheus
cd /usr/local/prometheus/# 修改配置监控自己的19090端口
sed -i  s/localhost:9090/localhost:19090/g prometheus.yml # 启动监听端口为19090,不加默认9090
./prometheus --config.file=prometheus.yml --web.listen-address=:19090

PS:上面命令指示测试是否可以启动,如果可以启动 ^C 停止掉即可!下面配置systemd管理

4、添加systemd管理

cat > /usr/lib/systemd/system/prometheus.service << EOF
[Unit][Service]
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:19090
ExecReload=/bin/kill -HUP \$MAINPID[Install]
WantedBy=multi-user.target
Alias=dbus-org.fedoraproject.FirewallD1.service
EOF

启动并加入开机自启动

systemctl start prometheus.service
systemctl enable prometheus.service

5、WEB页面验证
浏览器访问 IP:19090


如上图所示:监控自己状态为UP表示至此步骤无误!

三、安装Grafana

1、安装Grafana
Grafana官方下载地址

wget https://dl.grafana.com/enterprise/release/grafana-enterprise-9.4.1-1.x86_64.rpm
sudo yum install grafana-enterprise-9.4.1-1.x86_64.rpm -ysystemctl enable grafana-server.service --now

2、WEB页面验证
浏览器访问 IP:3000

第一次需要更改密码,正常操作即可。

四、Pronetheus和Grafana相关联

划到末端 点击"Save & test"

五、监控服务器状态

1、node_exporter组件安装
node_exporter是Prometheus指标收集组件,和传统的指标数据收集组件不同的是,它只负责收集数据,并不向Server端发送数据,而是等待Prometheus Server 主动抓取。

wget https://github.com/prometheus/node_exporter/releases/download/v1.5.0/node_exporter-1.5.0.linux-amd64.tar.gz
tar zxf node_exporter-1.5.0.linux-amd64.tar.gz 
mv node_exporter-1.5.0.linux-amd64 /usr/local/prometheus/node_exporter
cd /usr/local/prometheus/node_exporter/./node_exporter

2、配置systemd管理node_exporter

cat > /usr/lib/systemd/system/node_exporter.service << EOF
[Unit][Service]
ExecStart=/usr/local/prometheus/node_exporter/node_exporter
ExecReload=/bin/kill -HUP \$MAINPID[Install]
WantedBy=multi-user.target
Alias=dbus-org.fedoraproject.FirewallD1.service
EOF

启动并加入开机自启动

systemctl start node_exporter.service
systemctl enable node_exporter.service

默认监听9100端口

netstat -anput |grep 9100
tcp6       0      0 :::9100                 :::*                    LISTEN      3372/./node_exporte 

2、Prometheus添加监控主机配置

vim /usr/local/prometheus/prometheus.yml
# 末尾添加一下配置,注意缩进要遵守yml格式- job_name: "node-200"static_configs:- targets: ["localhost:9100"]


重启Prometheus

systemctl restart prometheus.service 

3、导入Node监控模板
模板地址:

打开Grafana平台进行如下配置:

最终效果如下:

六、常见问题

1、重启prometheus报 Error on ingesting samples that are too old or are too far into the future 问题解决

# 清空Prometheus data目录之后重启
mv data data_bak
mkdir data
systemctl restart prometheus.service 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/105822.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【pytest】tep环境变量、fixtures、用例三者之间的关系

tep是一款测试工具&#xff0c;在pytest测试框架基础上集成了第三方包&#xff0c;提供项目脚手架&#xff0c;帮助以写Python代码方式&#xff0c;快速实现自动化项目落地。 在tep项目中&#xff0c;自动化测试用例都是放到tests目录下的&#xff0c;每个.py文件相互独立&…

springboot项目配置flyway菜鸟级别教程

1、Flyway的工作原理 Flyway在第一次执行时&#xff0c;会创建一个默认名为flyway_schema_history的历史记录表&#xff0c;这张表会用来跟踪或记录数据库的状态&#xff0c;然后每次项目启动时都会自动扫描在resources/db/migration下的文件的版本号并且通过查询flyway_schem…

九安监控初始化后恢复案例

九安监控是国内一个十六线小安防品牌&#xff0c;目前CHS零壹视频恢复程序监控版、专业版、高级版是支持这个安防品牌的&#xff0c;不过下边这个案例比较特殊&#xff0c;具体情况如下。 故障存储:希捷4T监控专用硬盘 故障现象: 客户描述是使用了初始化操作&#xff0c;正常…

LeetCode //C - 114. Flatten Binary Tree to Linked List

114. Flatten Binary Tree to Linked List Given the root of a binary tree, flatten the tree into a “linked list”: The “linked list” should use the same TreeNode class where the right child pointer points to the next node in the list and the left child …

游戏发行平台都有什么服务和功能?

游戏发行平台通常提供一系列服务和功能&#xff0c;以帮助游戏开发商将游戏推向市场&#xff0c;并为玩家提供游戏。以下是一些常见的游戏发行平台服务和功能&#xff1a; 1、游戏发布 发行平台允许游戏开发商将游戏上传到平台上&#xff0c;以供玩家下载和安装。 2、游戏销售…

Redis7--基础篇1(概述,安装、卸载及配置)

1. Redis概述 1.1 什么是Redis Redis&#xff1a;REmote Dictionary Server&#xff08;远程字典服务器&#xff09; Remote Dictionary Server(远程字典服务)是完全开源的&#xff0c;使用ANSIC语言编写遵守BSD协议&#xff0c;是一个高性能的Key-Value数据库提供了丰富的数…

Python 操作 CSV

使用过 CSV 文件都知道&#xff1a;如果我们的电脑中装了 WPS 或 Microsoft Office 的话&#xff0c;.csv 文件默认是被 Excel 打开的&#xff0c;那么什么是 CSV 文件&#xff1f;CSV 文件与 Excel 文件有什么区别&#xff1f;如何通过 Python 来操作 CSV 文件呢&#xff1f;带…

mfc 浮动窗口

参考 MFC模拟360悬浮窗加速球窗口

Codeforces Round 895 (Div. 3) A ~ F

Dashboard - Codeforces Round 895 (Div. 3) - Codeforces A 问多少次能使a 和 b相等&#xff0c;就是abs(a - b) / 2除c向上取整&#xff0c;也就是abs(a - b)除2c向上取整。 #include<bits/stdc.h> #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #de…

卡尔曼滤波公式推导(总结)

假设 小车在t时刻的初始状态可以用Pt&#xff08;当前位置&#xff09;&#xff0c;Vt&#xff08;当前速度&#xff09;&#xff0c;Ut表示加速度&#xff1a; 预测&#xff1a; 利用上一个时刻的旧状态和系统的动量模型&#xff08;如加速度&#xff0c;速度等&#xff09;…

MySQL(六)

集群 单节点数据库 优点&#xff1a;适合数据量小的网站&#xff0c;如企业网站。 缺点&#xff1a;单个数据库无法满足日益增长的读写请求&#xff1b; 为什么要使用集群 高可用性&#xff1a;站点高可用&#xff0c;冗余站点&#xff1b;服务高可用&#xff0c;冗余服务…

分享一个基于SpringBoot+Vue的房屋在线装修预约系统源码

&#x1f495;&#x1f495;作者&#xff1a;计算机源码社 &#x1f495;&#x1f495;个人简介&#xff1a;本人七年开发经验&#xff0c;擅长Java、Python、PHP、.NET、微信小程序、爬虫、大数据等&#xff0c;大家有这一块的问题可以一起交流&#xff01; &#x1f495;&…