首页 > 其他分享 >prometheus

prometheus

时间:2023-02-28 12:14:33浏览次数:44  
标签:exporter prometheus usr 监控 mysql local

普罗米修斯原理架构图

image

一、环境准备

1、时间同步

systemctl restart ntpd
systemctl enable ntpd

2、关闭防火墙,selinux

systemctl stop firewalld
systemctl disable firewalld
iptables -F

二、安装prometheus

1、下载安装包

https://prometheus.io/download/ 下载相应版本,安装到服务器上,官网提供的是二进制版,解压就能用,不需要编译
tar xf prometheus-2.5.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/prometheus-2.5.0.linux-amd64/ /usr/local/prometheus
直接使用默认配置文件启动
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
确认端口(9090)
lsof -i:9090
prometheus界面
通过浏览器访问 http://服务器IP:9090 就可以访问到prometheus的主界面
image
默认只监控了本机一台,点Status -> 点Targets -> 可以看到只监控了本机
image
通过 http://服务器IP:9090/metrics 可以查看到监控的数据
在web主界面可以通过关键字查询监控项
image

2、监控远程linux主机

在远程linux主机(被监控端)上安装node_exporter组件,下载地址: https://prometheus.io/download/
tar xf node_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/node_exporter-0.16.0.linux-amd64/ /usr/local/node_exporter
里面就一个启动命令node_exporter,可以直接使用此命令启动
ls /usr/local/node_exporter/
nohup /usr/local/node_exporter/node_exporter &
确认端口(9100)
lsof -i:9100
通过浏览器访问 http://被监控端IP:9100/metrics 就可以查看到node_exporter在被监控端收集的监控信息
回到prometheus服务器的配置文件里添加被监控机器的配置段
vim /usr/local/prometheus/prometheus.yml

点击查看代码
#在主配置文件最后加上下面三行
 - job_name: 'agent1'  # 取一个job名称来代表被监控的机器
   static_configs:
   - targets: ['10.1.1.14:9100']  # 这里改成被监控机器的IP,后面端口接9100

改完配置文件后,重启服务
pkill prometheus
lsof -i:9090 #确认端口没有进程占用
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
lsof -i:9090 #确认端口被占用,说明重启成功
回到web管理界面 -> 点Status -> 点Targets -> 可以看到多了一台监控目标
image

3、监控远程mysql

在被监控端上安装mysqld_exporter组件,下载地址: https://prometheus.io/download/
tar xf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /usr/local/
mv /usr/local/mysqld_exporter-0.11.0.linux-amd64/ /usr/local/mysqld_exporter
ls /usr/local/mysqld_exporter/
链接进入数据库 mysql -u用户名 -p密码
mysql[none]> grant select,replication client,process ON *.* to 'mysql_monitor'@'localhost' identified by '123';
(注意:授权ip为localhost,因为不是prometheus服务器来直接找mysql获取数据,而是prometheus服务器找mysql_exporter,mysql_exporter再找mysql,所以这个localhost是指的mysql_exporter的IP)
mysql[none]> flush privileges;
mysql[none]> exit
创建一个mysql配置文件,写上连接的用户名与密码(和上面的授权的用户名和密码要对应)
vim /usr/local/mysqld_exporter/.my.cnf

点击查看代码
[client]
user=mysql_monitor
password=123

启动mysqld_exporter
nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf &
确认端口(9104)
lsof -i:9104
回到prometheus服务器的配置文件里添加被监控的mysql的配置段
vim /usr/local/prometheus/prometheus.yml

点击查看代码
#在主配置文件最后再加上下面三行
- job_name: 'agent1_mysql'  # 取一个job名称来代表被监控的mysql
   static_configs:
   - targets: ['10.1.1.14:9104']  # 这里改成被监控机器的IP,后面端口接9104

改完配置文件后,重启服务
pkill prometheus
lsof -i:9090
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" &
lsof -i:9090
回到web管理界面 -> 点Status -> 点Targets -> 可以看到监控mysql了
image
image

二、安装grafana

下载grafana包

下载地址:https://grafana.com/grafana/download
这里选择的rpm包,下载后直接rpm -ivh安装就OK
rpm -ivh /root/Desktop/grafana-5.3.4-1.x86_64.rpm
systemctl start grafana-server
systemctl enable grafana-server
确认端口(3000)
lsof -i:3000
通过浏览器访问 http://grafana服务器IP:3000 就到了登录界面,使用默认的admin用户,admin密码就可以登陆了
image
下面我们把prometheus服务器收集的数据做为一个数据源添加到grafana,让grafana可以得到prometheus的数据。
image
image
image
image
然后为添加好的数据源做图形显示
image
image
image
在prometheus页面查询想要监控的键值,复制到grafana的对应位置
image
image

保存
image
最后在dashboard可以查看到
image

grafana图形显示mysql监控数据

在grafana图形界面导入相关json文件
image
image
点import导入后,报prometheus数据源找不到,因为这些json文件里默认要找的就是叫Prometheus的数据源,但我们前面建立的数据源却是叫prometheus_data,那么请自行把原来的prometheus_data源改名为Prometheus即可(注意:第一个字母P是大写),然后再回去刷新,就有数据了(如下图所示)
image
过段时间再看,就会有数据了(如下图所示)
image

标签:exporter,prometheus,usr,监控,mysql,local
From: https://www.cnblogs.com/chunjeh/p/17163541.html

相关文章

  • Prometheus配置Alertmanager(钉钉告警)
    Prometheus配置Alertmanager(钉钉告警)简介Alertmanager主要用于接收Prometheus发送的告警信息,它支持丰富的告警通知渠道,例如邮件、微信、钉钉、Slack等常用沟通工具,......
  • Prometheus配置Grafana监控大屏
    简介Grafana是一个跨平台的开源的度量分析和可视化工具,可以通过将采集的数据查询然后可视化的展示,并及时通知。主要特点展示方式:快速灵活的客户端图表,面板插件有许......
  • Prometheus插件安装(NodeExporter)
    Prometheus插件安装(NodeExporter)一,下载安装包并解压下载地址:https://github.com/prometheus/node_exporter/releases同样物理机上下载,然后上传到服务器,本次安装使用的......
  • 9.【go-kit教程】go-kit集成Prometheus
    在Gokit中集成Prometheus进行API监控可以帮助开发人员更好地了解系统的性能和行为,提高系统的可观察性和可靠性。下面是一个简单的示例,演示如何在Gokit中集成P......
  • 使用docker-compose快速部署Prometheus+grafana环境
    由于最近公司服务频繁出问题,老板很生气,下面的人都很不好过,于是老大让加一下业务监控,来观察线上数据状态。但是由于qa环境数据量太少,所以自己搭建了一套环境做相关监控,并且......
  • 性能测试-grafana + prometheus + node_exporter
    1、grafana安装下载网址:https://grafana.com/grafana/download/7.4.3?platform=linux#下载wgethttps://dl.grafana.com/enterprise/release/grafana-enterprise-7.4.3......
  • 最易懂的Prometheus告警原理详解
    通俗易懂的一篇文章,主要介绍了Prometheus什么时候告警,什么时候不会告警。同时介绍了Prometheus告警原理。 警报是监控系统中必不可少的一块,当然了,也是最难......
  • Prometheus安装部署(主体)
    Prometheus安装部署一,下载安装包并解压下载地址:https://github.com/prometheus/prometheus/releases因为服务器上下载速度太慢,所以可以提前在物理机上下载上传到服务器,......
  • <<运维监控系统实战笔记>> 小记随笔 —— Prometheus 初识
    Prometheus简介Prometheusserver包含时序库、告警引擎、数据展示三大块,体系中最核心的组件Exporters采集数据的客户端,负载采集数据存在内存中,提供http接口,让......
  • Prometheus监控各类程序
    一、Prometheus安装github:https://github.com/prometheus/prometheus官网: https://prometheus.io#1下载prometheus-v2.40.7镜像https://hub.docker.com/r/prom/pro......