Prometheus#Prometheus+Grafana部署云监控利器
Prometheus介绍和部署
时间序列收集和处理服务器
prometheus官网:https://prometheus.io/
Prometheus是一套开源的监控、报警、时间序列数据库的组合,起始是由SoundCloud公司开发的
Grafana官网:https://grafana.com/
Grafana支持查询Prometheus。从Grafana 2.5.0(2015-10-28)开始包含Prometheus的Grafana数据
一、Prometheus简单对比Zabbix
Zabbix:后端用C开发,前端用PHP开发、适合监控物理机环境、简单成熟、图形化配置完爆Prometheus
Prometheus:前端用Glang开发、前端用Grafana开发、适合云环境监控、Kubernetes的官方监控方案
二、Prometheus下载、部署、测试
1、官网下载安装包、解压安装
[[email protected] ~]# wget https://github.com/prometheus/prometheus/releases/download/v2.22.0/prometheus-2.22.0.linux-amd64.tar.gz
[[email protected] ~]# tar -xvf prometheus-2.22.0.linux-amd64.tar.gz -C /usr/local/
[[email protected] ~]# cd /usr/local/
[[email protected] local]# mv prometheus-2.22.0.linux-amd64/ prometheus
[[email protected] local]# cd prometheus/
2、启动访问9090端口测试
启动命令路径+配置文件路径方式启动:
[[email protected] ~]# /usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
Server is ready to receive web requests==>说明启动成功,过滤9090端口,已经存在
[[email protected] ~]# ss -ntal | grep 9090
LISTEN 0 128 :::9090 ::????
浏览器访问测试
关闭命令:
[[email protected] ~]# killall -9 prometheus
三、安装Grafana(前端监控页面)(端口号3000)
普罗米修斯默认的页面可能没有那么直观,我们可以安装grafana使监控看起来更直观
默认情况下,Grafana将在http:// localhost:3000上监听 。默认登录名是“ admin” /“ admin”
[[email protected] ~]# wget https://dl.grafana.com/oss/release/grafana-7.3.1-1.x86_64.rpm
[[email protected] ~]# yum -y install grafana-7.3.1-1.x86_64.rpm
[[email protected] ~]# systemctl enable grafana-server
[[email protected] ~]# systemctl start grafana-server
[[email protected] ~]# ss -ntal | grep -E “(9090|3000)”
LISTEN 0 128 :::3000 ::????
LISTEN 0 128 :::9090 ::????
浏览器览器访问测试
http://10.11.67.85:3000
四、Grafana添加Prometheus数据源
1、创建Prometheus数据源
2、在Grafana中创建Prometheus数据源:
3、单击边栏中的“齿轮”以打开“配置”菜单
4、单击“数据源”。
5、点击“添加数据源”。
6、选择“ Prometheus”作为类型。
7、设置适当的Prometheus服务器网址(例如,http://localhost:9090/)
8、根据需要调整其他数据源设置(例如,选择正确的访问方法)。
9、单击“保存并测试”以保存新的数据源。
五、创建Prometheus图形
1、单击图形标题,然后单击“编辑”。
2、在“指标”选项卡下,选择Prometheus数据源(右下方)。
3、在“查询”字段中输入任何Prometheus表达式,同时使用“指标”字段通过自动补全查找指标。
4、要格式化时间序列的图例名称,请使用“图例格式”输入。例如,要仅显示返回的查询结果的method和status标签,并用破折号分隔,可以使用图例格式字符串 {{method}} - {{status}}。
5、调整其他图形设置,直到可以使用图形为止。
六、监控linux机器举例
六、监控Linux机器举例
1、被监控的机器10.11.67.31安装node-exporter
node-exporter端口为9100
node-exporter用于采集服务器层面的运行指标,包括机器的loadavg、filesystem、meminfo等基础监控,类似于传统主机监控维度的zabbix-agent
[[email protected] ~]# wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-amd64.tar.gz
[[email protected] ~]# tar -xvf node_exporter-1.0.1.linux-amd64.tar.gz -C /usr/local/
2、启动node-exporter
[[email protected] ~]# /usr/local/node_exporter-1.0.1.linux-amd64/node_exporter &
[[email protected] ~]# ss -ntal | grep 9100
LISTEN 0 128 :::9100 ::????
3、普罗米修斯配置文件添加监控项
4、重启普罗米修斯
5、Grafana配置插件下载
如果没有任何显示,是grafana缺少相关显示需要用到的插件piechart,grafana的默认插件目录是/var/lib/grafana/plugins,可以将下载好的插件解压到这个目录,重启grafana即可
[[email protected] ~]# unzip /mnt/grafana-piechart-panel-5f249d5.zip -d /var/lib/grafana/plugins/
[[email protected] ~]# systemctl restart grafana-server
[[email protected] ~]# /usr/sbin/grafana-cli plugins ls
installed plugins:
grafana-piechart-panel @ 1.3.3
查看已安装插件