Prometheus+Grafana监控

Prometheus是一种开源监控系统,可用于收集指标和统计数据,并提供强大的查询语言,以便分析和可视化这些数据。它被广泛用于云原生和容器化环境中,可以嵌入到Kubernetes集群中,并与其他Kubernetes工具进行集成。

Grafana是一种开源的面向数据的仪表板和可视化工具,可与Prometheus等数据源一起使用。它提供了各种可视化选项和插件,可以可视化数据和指标以便于分析。Grafana还支持警报和通知机制,以便在指标达到特定条件时通知用户。

结合使用Prometheus和Grafana可以实现实时监控应用程序的运行状况,帮助开发人员迅速发现和解决问题。通过可视化和分析指标数据,可以对系统性能和稳定性进行深入了解,并且可以根据警告和通知及时采取行动。

实验部署

IP角色系统规格
192.168.231.233Prometheus 服务端CentOS 74c8g
192.168.231.232node_exporter 客户端CentOS 74c8g

在服务端部署prometheus

由于本地有包 因此直接上传rz  
选择这个prometheus-2.47.2.linux-amd64.tar.gz解压
[root@prometheus opt]# tar xvfz prometheus-2.47.2.linux-amd64.tar.gz -C /usr/local/
[root@prometheus opt]# cd /usr/local/改名
[root@prometheus local]# mv prometheus-2.47.2.linux-amd64 prometheus
[root@prometheus local]# cd prometheus
[root@prometheus prometheus]# ls
console_libraries  consoles  data  LICENSE  NOTICE  prometheus  prometheus.yml  promtool# 查看版本信息
[root@prometheus prometheus]# ./prometheus --version
prometheus, version 2.47.2 (branch: HEAD, revision: 3f3172cde1ee37f1c7b3a5f3d9b031190509b3ad)build user:       root@79f2ad339b75build date:       20231012-16:07:10go version:       go1.21.3platform:         linux/amd64tags:             netgo,builtinassets,stringlabels
# 查看帮助
[root@prometheus prometheus]# ./prometheus --help
prometheus, version 2.47.2 (branch: HEAD, revision: 3f3172cde1ee37f1c7b3a5f3d9b031190509b3ad)build user:       root@79f2ad339b75build date:       20231012-16:07:10go version:       go1.21.3platform:         linux/amd64tags:             netgo,builtinassets,stringlabels…………

prometheus.yml配置文件详细解释

[root@prometheus prometheus]# cat prometheus.yml
# my global config
global:# 默认情况下,每15s拉取一次目标采样点数据。scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.# 每15秒评估一次规则。默认值为每1分钟。evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.# scrape_timeout is set to the global default (10s).# Alertmanager configuration
alerting:alertmanagers:- static_configs:- targets:# - alertmanager:9093# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:# - "first_rules.yml"# - "second_rules.yml"# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:# job名称会增加到拉取到的所有采样点上,同时还有一个instance目标服务的host:port标签也会增加到采样点上- job_name: 'prometheus'# 覆盖global的采样点,拉取时间间隔5sscrape_interval: 5sstatic_configs:- targets: ['localhost:9090']

启动Prometheus

[root@prometheus prometheus]# ./prometheus --config.file=prometheus.yml

相关启动参数

# 指定配置文件
--config.file="prometheus.yml"
# 默认指定监听地址端口,可修改端口
--web.listen-address="0.0.0.0:9090" 
# 最大连接数
--web.max-connections=512
# tsdb数据存储的目录,默认当前data/
--storage.tsdb.path="data/"
# premetheus 存储数据的时间,默认保存15天
--storage.tsdb.retention=15d 
# 通过命令热加载无需重启 curl -XPOST 192.168.2.45:9090/-/reload
--web.enable-lifecycle
# 可以启用 TLS 或 身份验证 的配置文件的路径
--web.config.file=""启动选项了解:./prometheus --help

web端访问

192.168.231.233:9090

将Prometheus配置为system管理

# 配置Prometheus启动文件
[root@prometheus opt]# vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=https://prometheus.io[Service]
Restart=on-failure
ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.listen-address=:9090[Install]                      
WantedBy=multi-user.target

重新加载system配置

[root@prometheus opt]# systemctl daemon-reload
[root@prometheus opt]# systemctl start prometheus查看端口
[root@prometheus opt]# ss -tlanp |grep 9090
LISTEN     0      1024      [::]:9090                  [::]:*                   users:(("prometheus",pid=9318,fd=7))

客户端,配置服务发现linux主机及相关服务

# 安装node_exporter

传包
rz   #node_exporter-1.7.0.linux-amd64.tar.gz解压
[root@node ~]# tar -xr node_exporter-1.7.0.linux-amd64.tar.gz -C /usr/local/
[root@node ~]# cd /usr/local/
[root@node local]# mv node_exporter-1.7.0.linux-amd64/ node_exporter进入目录,查看有哪些文件
[root@node local]# cd node_exporter/
[root@node node_exporter]# ls
LICENSE  node_exporter  NOTICE后台运行并启动
[root@node node_exporter]# ./node_exporter &…………
ts=2023-11-16T09:52:04.979Z caller=tls_config.go:274 level=info msg="Listening on" address=[::]:9100
ts=2023-11-16T09:52:04.979Z caller=tls_config.go:277 level=info msg="TLS is disabled." http2=false address=[::]:9100

查看端口

[root@node node_exporter]# ss -tlnp  | grep 9100
LISTEN     0      1024      [::]:9100                  [::]:*                   users:(("node_exporter",pid=8414,fd=3))

配置node——exporter为systemd管理

[root@node node_exporter]# vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
After=network.target [Service]
ExecStart=/usr/local/node_exporter/node_exporter
Restart=on-failure[Install]
WantedBy=multi-user.target

重新加载配置,并查看端口

[root@node node_exporter]# systemctl daemon-reload
[root@node node_exporter]# systemctl start node_exporter
[root@node node_exporter]# ss -tlnp  | grep 9100
LISTEN     0      1024      [::]:9100                  [::]:*                   users:(("node_exporter",pid=8675,fd=3))

普罗米修斯服务端配置文件添加监控项

vim  /usr/local/prometheus/prometheus.yml最后一行添加- job_name: "node_exporter"static_configs:- targets: ["192.168.231.232:9100"]# 如果有多个机器,用','分开

重启prometheus服务

[root@prometheus prometheus]# systemctl restart prometheus

监控mysql(mysqld-exported)

安装mysqld-exported

rz  上传包解压
[root@node ~]# tar xf mysqld_exporter-0.15.0.linux-amd64.tar.gz -C /usr/local/
改名
[root@node /usr/local]# mv mysqld_exporter-0.15.0.linux-amd64 mysqld_exporter
编辑文件
[root@node /usr/local/mysqld_exporter]# vim .my.cnf
[client]
user=root
password=123   #登录系统用户的密码

启动mysqld-exported

后台运行
[root@node /usr/local/mysqld_exporter]# ./mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter/.my.cnf" &查看进程
[root@node /usr/local/mysqld_exporter]# ps -ef |grep mysqld_exporter
root       3447   3398  0 01:31 pts/1    00:00:02 ./node_exporter
root       4647   3398  0 02:13 pts/1    00:00:00 ./mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf查看端口
[root@node /usr/local/mysqld_exporter]# ss -lntp |grep 4647
LISTEN     0      128         :::9104                    :::*                   users:(("mysqld_exporter",pid=4647,fd=3))
[root@VM_2-44 /usr/local/mysqld_exporter]# 
# 启动后会监听9104端口

普罗米修斯服务端配置文件添加监控项

[root@prometheus prometheus]# vim prometheus.yml - job_name: "mysql-exporter"static_configs:- targets: ["192.168.231.232:9104"]

重启服务

[root@prometheus prometheus]# systemctl restart prometheus

使用grafana展示Prometheus数据,在服务端安装

上传grafana-10.0.0-1.x86_64.rpm 
rz安装
[root@prometheus ~]# yum install initscripts fontconfig -y
[root@prometheus ~]# yum install -y grafana-10.0.0-1.x86_64.rpm启动服务
[root@prometheus ~]# systemctl start grafana-server.service 查看端口
[root@prometheus ~]# ss -tlanp |grep grafana |grep LISTEN
LISTEN     0      1024      [::]:3000                  [::]:*                   users:(("grafana",pid=10629,fd=11))

# 启动后访问地址:ip:3000
# 初始用户名和密码都是admin

浏览器访问 http://192.168.231.233:3000

看不懂英文改中文

添加数据源

成功的提示

添加仪表盘

选择新建导入

dashboards查找地址,去官方找模板

https://grafana.com/grafana/dashboards/
 

找到点击copy,会复制id

选择普罗米修斯

成功

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

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

相关文章

优卡特脸爱云一脸通智慧管理平台权限绕过漏洞复现(CVE-2023-6099)

0x01 产品简介 脸爱云一脸通智慧管理平台是一套功能强大,运行稳定,操作简单方便,用户界面美观,轻松统计数据的一脸通系统。无需安装,只需在后台配置即可在浏览器登录。 功能包括:系统管理中心、人员信息管理…

单片机课程设计——基于C51电子密码锁(源代码)

本设计是基于AT89C51单片机的电子密码锁设计,实现电子密码锁的基本功能。我们这里实现的是硬件仿真,关于软件仿真可以参考其他人的文章。 单片机课程设计--基于C51电子密码锁 效果展示 我们先来看效果展示,公主王子请看视频: 课…

jbase打印完善

上一篇实现了粗略的打印元素绘制协议,并且写了打印示例和导出示例,趁着空隙时间完善一下打印。 首先元素构造函数默认初始化每个字段值 package LIS.Core.Dto;/*** 打印约定元素*/ public class PrintElement {/*** 元素类型*/public String PrintType…

凸包的学习之路

5.算法策略5:Graham Scan Algorithm 算法思路: 给定二维点集,求其凸包 1)presorting: (1)先找到 ltl点 ,也就是y值最小的点,若是存在y值相等的点,再取x值…

WSA子系统(一)

WSA子系统安装教程 Windows Subsystem for Android (WSA) 是微软推出的一项功能,它允许用户在 Windows 11 上运行 Android 应用程序。通过在 Windows 11 上引入 WSA,用户可以在其 PC 上轻松运行 Android 应用程序,从而扩展了用户的应用程序选…

【【SOC设计之 数据回路从 DMA到 FIFO再到BRAM 再到FIFO 再写回DMA】】

SOC设计之 数据回路从 DMA到 FIFO再到BRAM 再到FIFO 再写回DMA 基本没问题的回路设计 从 DMA出发将数据传递到 FIFO 再 写到 自定义的 RTL文件中 再写到 BRAM 再到 自定义的RTL文件 再到 FIFO 再写回DMA block design 的 设计连接 可以参考我上一个文件的设计 下面介绍两个c…

kubenetes-Service和EndpointSlice

一、Service 二、Endpoint Endpoint记录一个 Service 对应一组 Pod 的访问地址,一个 Service 只有一个 Endpoint资源。Endpoint资源会去监测Pod 集合,只要服务中的某个 Pod 发生变更,Endpoint 就会进行同步更新。 三、Service、Endpoint和 P…

算法设计与分析复习--求解最大子段和问题(分支法、动态规划)

文章目录 问题描述分治法动态规划法 问题描述 最大子段和问题; 洛谷P1115.最大子段和 分治法 利用归并排序的方法,但是由于是算最大子段和所以,并不能将它变成有序的,左边和右边的最大子段和通过调用函数,而中间的要…

安装第三方包报错 error: Microsoft Visual C++ 14.0 or greater is required——解决办法

1、问题描述 手动安装第三方软件时,可以使用setup.py,来安装已经下载的第三方包。一般文件下会存在setup,在所要安装库的目录下的cmd执行:python setup.py install报错:error: Microsoft Visual C 14.0 or greater i…

cad提示由于找不到mfc140u.dll,无法继续执行代码怎么修复

在Windows操作系统中,mfc140u.dll是一个重要的文件,很多软件运行都需要它,它属于Microsoft Visual C库的一部分。许多基于C的开发项目都依赖于这个文件,如果在使用过程中出现丢失现象,可能导致相关软件或游戏无法正常运…

第八部分:JSP

目录 JSP概述 8.1:什么是JSP,它有什么作用? 8.2:JSP的本质是什么? 8.3:JSP的三种语法 8.3.1:jsp头部的page指令 8.3.2:jsp中的常用脚本 ①声明脚本(极少使用&#xf…

医疗项目的需求分析以及开发流程

一.项目的背景以及需求 1.项目背景 1.政策层面来看,近年来我国政府相关部门陆续颁发了支持数字医疗行业发展的相关政策,“互联网医疗”政策逐渐明确完善,为数字医疗行业发展提供支持,行业迎来政策福利期。 其次,从经济…