全国旗舰校区

不同学习城市 同样授课品质

北京

深圳

上海

广州

郑州

大连

武汉

成都

西安

杭州

青岛

重庆

长沙

哈尔滨

南京

太原

沈阳

合肥

贵阳

济南

下一个校区
就在你家门口
+
当前位置:首页  >  技术干货

Prometheus+Grafana监控系统(01)

发布时间:2023-03-20 16:00:00
发布人:syq

  各组件功能:

  Prometheus作为数据源,采集中心,用于收集各node节点的监控数据。

  使用客户端使用node_exporter(其他的exporter)向Prometheus,或直接通过Pushgateway推送监控数据。

  Grafana用于图表展示监控数据

  Alertmanager用于告警。

31

  architecture.png

  1.下载并安装二进制版本

32

  1.1配置Systemd服务,实现开机自启动(Centos)

cat>/usr/lib/systemd/system/prometheus.service<<EOF[Unit]Description=PrometheusAfter=network.target[Service]Type=simpleUser=rootWorkingDirectory=/usr/local/prometheusExecStart=/usr/local/prometheus/prometheus --web.enable-lifecycle --config.file=/usr/local/prometheus/prometheus.yml --storage.tsdb.retention=7dRestart=on-failureLimitNOFILE=65536[Install]WantedBy=multi-user.targetEOFsystemctl daemon-reloadsystemctl enable prometheus.service && systemctl start prometheus.service

  1.2配置Systemd服务,实现开机自启动(Ubuntu)

cat>/lib/systemd/system/prometheus.service<<EOF[Unit]Description=PrometheusAfter=network.target[Service]Type=simpleUser=rootWorkingDirectory=/usr/local/prometheusExecStart=/usr/local/prometheus/prometheus --web.enable-lifecycle --config.file=/usr/local/prometheus/prometheus.ymlRestart=on-failureLimitNOFILE=65536[Install]WantedBy=multi-user.targetEOFsystemctl daemon-reloadsystemctl enable prometheus.service && systemctl start prometheus.service

  1.3查看工作端口9090

netstat -ntpl | grep 9090

  1.4web管理界面

  http://x.x.x.x:9090

35

  2.节点node_exporter 配置

  node_exporter的作用是用于机器系统数据收集。

  2.1下载并安装二进制版本

VERSION=1.5.0wget https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/node_exporter-${VERSION}.linux-amd64.tar.gztar xzvf node_exporter-${VERSION}.linux-amd64.tar.gz mv node_exporter-${VERSION}.linux-amd64 /usr/local/node_exporter/

  2.2配置Systemd服务,实现开机自启动(Centos)

37

  2.3配置Systemd服务,实现开机自启动(Ubuntu)

38

  2.4查看端口

39

  3.管理配置Prometheus信息

  3.1Prometheus管理API

  Prometheus提供了一套管理API来简化自动化和集成。

40

  3.2prometheus自动发现--基于静态配置,添加各node节点信息

  [root@es01 config]# cat prometheus.yml

  ##注意yaml排版格式,空2格对齐。

41

  重新加载配置文件,检查配置文件,并重新加载

  1检查配置文件

42

  3.3prometheus自动发现--基于文件发现配置添加各node节点信息

43

  #在创建好的nodes目录下创建 nodes.json文件,并写入下面内容

  [root@es01 config]# cat targets/nodes/nodes.json

44

  修改配置文件prometheus.yml如下:

45

  检查,重新加载配置文件

46

  进入http://192.168.1.6:9090,查看添加到的主机

47

  3.4简单总结:

  定义好对应的主配置文件prometheus.yml后,后续要添加新的node节点监控进来,只需要增加node.json内容即可,也不需要重载prometheus服务,相对比较简单的基于文件的自动发现。

  4.使用grafana展示监控效果

  4.1安装grafana

48

  4.2创建Systemd服务

49

  4.3服务开机自启

50

  /usr/local/grafana/conf/defaults.ini为默认配置文件

  工作端口,默认为3000,web管理页面http://x.x.x.x:3000

  4.4添加prometheus数据源,生成可视化图表

  登录web管理页面,添加数据源

51

  为prometheus数据源添加可视化面板

52

53

54

  4.5在nginx上为grafana配置反向代理

  nginx为grafana进行反代时,需要配置websocket跨域反向代理

55

相关文章

python写入json文件?

python写入json文件?

2023-11-02
vscode设置tab为4个空格?

vscode设置tab为4个空格?

2023-11-02
更新pycharm?

更新pycharm?

2023-11-02
anaconda每次打开都要安装?

anaconda每次打开都要安装?

2023-11-02

最新文章

武汉新媒体行业公司排名

武汉新媒体行业公司排名

2023-11-01
武汉新媒体就业现状好吗

武汉新媒体就业现状好吗

2023-11-01
武汉全媒体行业发展现状及趋势

武汉全媒体行业发展现状及趋势

2023-10-31
武汉全媒体现状

武汉全媒体现状

2023-10-31
在线咨询 免费试学 教程领取