ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Liunx性能监控

2022-08-22 22:34:10  阅读:199  来源: 互联网

标签:node exporter 监控 数据源 性能 grafana prometheus Liunx https


场景:

  这几天项目做的差不多了,但是服务器经常崩掉,然后之前用c#写的性能监控模块也不准,于是放弃了。还是用别人的模块吧。这里我采用node export + prometheus + grafana的方案进行性能监控。

  prometheus是系统监控和报警系统,它可以通过监控系统的性能数据,获取并存储数据(默认是两个小时的数据)。同类型的软件有zabbix,但是我还没接触到。同时也有报警功能,可以配置告警规则,通过发送邮件,微信,钉钉等通知运维人员。它的Exporter就是用来收集数据的组件。node export就是prometheus在Liunx下的组件。prometheus自带可视化组件,但是不是很好用(本人没用过),于是大家都是用Grafana进行可视化的。

  grafana是一个用于数据展示的可视化工具,它可以接入很多的数据源,并把数据源的内容进行展示。注意,它不能进行数据的采集(指从原数据采集),只能用于显示。它可以适配很多数据源,比如Prometheus,Mysql,InfluxDB等,一般配合时序数据库(正好项目中是pg + timescaledb)。下图是部分可以做数据源的数据。

 

   然后它可以自己配置面板,配置里面的显示信息。也有官方网站上大家做好的模板,一般用大家做好的就够用了。下面讲一下怎么使用,针对的都是Liunx(centos)下的。

安装node export:

  下载,安装

wget https://github.com/prometheus/node_exporter/releases/download/v1.1.1/node_exporter-1.1.1.linux-amd64.tar.gz

// 解压
tar -zxvf node_exporter-1.1.1.linux-amd64.tar.gz
mv node_exporter-1.1.1.linux-amd64 /usr/local/node_exporter

  运行一下,去http://localhost:9100看看,这里:

./node_exporter

  

 

   点击Metrics就可以看它采集的数据了

  添加服务,设置启动:

// 创建
vim /usr/lib/systemd/system/node_exporter.service

// 内容如下
[Unit]
Description=node_export
Documentation=https://github.com/prometheus/node_exporter
After=network.target
 
[Service]
Type=simple
User=prometheus
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure
[Install]
WantedBy=multi-user.target

// 启动
systemctl daemon-reload
systemctl start node_exporter.service

 

安装prometheus:

  下载

wget https://github.com/prometheus/prometheus/releases/download/v2.27.1/prometheus-2.27.1.linux-amd64.tar.gz

  解压,并测试启动。这个.yml是配置文件,可以配置多个数据源。要是需要配置prometheus的端口,加上:--web.listen-address=:1888

tar -xzvf prometheus-2.27.2.linux-amd64.tar.gz
./prometheus --config.file=prometheus.yml

  

 

   如果是这样,则说明运行成功。

  打开localhost:9090看一下:可以看到这里的UP状态就是已经成功获取到node_export的数据了。如果是DOWN的话,需要看看有什么问题。

 

 

  然后做一个服务,使它可以后台运行

// 创建sh脚本
 vi prometheus.sh

// 添加以下内容
#!/bin/bash
路径/prometheus --web.enable-lifecycle --config.file=路径/prometheus.yml &>> 路径/prometheus.log

// 修改权限
chmod 755 prometheus.sh

// 创建服务
vi /usr/lib/systemd/system/prometheus.service

// 添加内容:
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
# 启动脚本
ExecStart=路径/prometheus.sh

[Install]
WantedBy=multi-user.target

  记得reload一下Unit,就可以使用了

systemctl daemon-reload

// 开机启动
systemctl enable prometheus.service  

// 启动
systemctl start prometheus.service  

// 关闭
systemctl stop prometheus.service  

 

配置Grafana:

  安装

// 下载
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-8.0.0-1.x86_64.rpm
sudo yum install grafana-enterprise-8.0.0-1.x86_64.rpm

  使用

// 启动
systemctl start  grafana-server

// 查看状态
systemctl status  grafana-server

  默认会在http://localhost:3000显示界面,可以在/etc/grafana/grafana.ini文件中,配置端口信息等。默认用户,密码为admin,进来之后要求改密码。

 

   添加数据源:

 

   这里URL填:http://localhost:9090,HTTP Method选Get,然后Save and Test,如果有错的话,慢慢排查。看看能访问到吗,会不会是防火墙的问题

  然后在create->import中,导入相应的模板。可以去https://grafana.com/grafana/dashboards/8919-1-node-exporter-for-prometheus-dashboard-cn-0413-consulmanager/,选一些模板,复制模板的id,保存模板的json文件。

  填如id,并且上传json文件,

 

   然后修改Name,选择数据源,最后import就可以了。

 

   大概的界面:

 

 

  本人水平有限,这里我就讲一下大概的使用,每个软件都很很多可以操作的空间,有不足之处请多指教。

参考文献:

  官方:

  https://grafana.com/

  https://github.com/prometheus/prometheus

  yml配置信息:

  https://blog.csdn.net/qq_32486597/article/details/110383388

  node_server数据意义:

  https://blog.csdn.net/m0_59207224/article/details/122342860

  介绍,安装

  https://blog.csdn.net/qq_34556414/article/details/113107269

  https://blog.csdn.net/A13581861752/article/details/124148803

  https://blog.csdn.net/cp3_zyh/article/details/124019043

  https://blog.csdn.net/qq_32415063/article/details/105607008

  https://blog.csdn.net/weixin_43258559/article/details/109767442

标签:node,exporter,监控,数据源,性能,grafana,prometheus,Liunx,https
来源: https://www.cnblogs.com/chenzibai/p/16614464.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有