监控(普罗米修斯)

监控(普罗米修斯)本文介绍了 Prometheus 一个由 Go 语言开发的开源监控 报警和时间序列数据库系统 重点讲解了其在监控 Docker 容器和 Kubernetes 中的应用 以及如何与 MySQL Grafana 和

大家好,欢迎来到IT知识分享网。

普罗米修斯概述

链接地址

时间序列数据

1、什么是序列数据

时间序列数据(TimeSeries Data) : 按照时间顺序记录系统、设备状态变化
的数据被称为时序数据。

应用的场景很多, 如:

2、时间序列数据特点

性能好

3、Prometheus的主要特征

4、普罗米修斯原理架构图

在这里插入图片描述

安装

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的主界面

在这里插入图片描述
在这里插入图片描述

监控Mysql

安装mysqld_exporter组件

下载地址: https://prometheus.io/download/

tar xf mysqld_exporter-0.11.0.linuxamd64.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服务,创建账号并授权 mysql -uroot -p grant select,replication client,process ON *.* to 'mysql_monitor'@'%' identified by '123'; #刷新权限 flush privileges; 
配置mysqld_exporter
vim /usr/local/mysqld_exporter/.my.cnf #新增内容 [client] user=mysql_monitor password=123 
启动
nohup /usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf & 
修改prometheus配置文件
 vim /usr/local/prometheus/prometheus.yml #新增如下内容 - job_name: 'agent1_mariadb' # 取一个job #名称来代表被监控的mariadb static_configs: - targets: ['10.1.1.14:9104'] # 这里改成 #被监控机器的IP,后面端口接9104 
修改完成后重启prometheus
/usr/local/prometheus/prometheus --config.file="/usr/local/prometheus/prometheus.yml" & 
Grafana可视化图形
安装grafana
我这里选择的rpm包,下载后直接rpm -ivh安装就OK [root@grafana ~]# rpm -ivh /root/Desktop/grafana-5.3.4- 1.x86_64.rpm 启动服务 [root@grafana ~]# systemctl start grafana-server [root@grafana ~]# systemctl enable grafana-server 确认端口(3000) [root@grafana ~]# lsof -i:3000 

下面我们把prometheus服务器收集的数据做为一个数据源添加到grafana,让grafana可以得到prometheus的数据。

创建数据源

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
然后为添加好的数据源做图形显示

导入json文件

在这里插入图片描述在这里插入图片描述

点import导入后,报prometheus数据源找不到,因为这些json文件里默认要找的就是叫Prometheus的数据源,但我们前面建立的数据源却是叫prometheus_data(坑啊)

那么请自行把原来的prometheus_data源改名为Prometheus即可(注意: 第一个字母P是大写)

监控SpringBoot

添加依赖
 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <version>1.1.3</version> </dependency> 
修改配置文件

配置文件中加入配置,这里就只进行一些简单配置,management.metrics.tags.application属性是本文配合Grafana的Dashboard设置的,如下所示:

spring.application.name=springboot_prometheus management.endpoints.web.exposure.include=* management.metrics.tags.application=${spring.application.name} 
设置application
@SpringBootApplication public class Springboot2PrometheusApplication { 
    public static void main(String[] args) { 
    SpringApplication.run(Springboot2PrometheusApplication.class, args); } @Bean MeterRegistryCustomizer<MeterRegistry> configurer( @Value("${spring.application.name}") String applicationName) { 
    return (registry) -> registry.config().commonTags("application", applicationName); } } 
Prometheus配置
配置应用

在prometheus配置监控我们的SpringBoot应用,完整配置如下所示。

# my global config global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. 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_name: 'prometheus' static_configs: - targets: ['127.0.0.1:9090'] 以下内容为SpringBoot应用配置 - job_name: 'springboot_prometheus' scrape_interval: 5s metrics_path: '/actuator/prometheus' static_configs: - targets: ['127.0.0.1:8080'] 复制代码 
启动Prometheus
Grafana配置

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/112782.html

(0)
上一篇 2026-01-16 09:20
下一篇 2026-01-16 09:33

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信