prometheus linux下载_Prometheus+Grafana 监控MySQL

使用Prometheus和Grafana,可以快速的构建项目中性能测试绝大多数的监控模型场景:数据库监控、服务器监控、Jvm监控、Tomcat监控、Mq监控、Redis监控、Consul监控、Haproxy监控、Nginx监控、Elasticsearch等。

使用的组件

Mysqld_exporter 下载地址(https://prometheus.io/download/)node_exporter 下载地址(https://prometheus.io/download/)Prometheus  下载地址(https://prometheus.io/download/ 版本prometheus-2.18.1.linux-amd64.tar.gz)Grafana 下载地址(https://grafana.com/grafana/download?platform=linux) 或者docker安装

内网机器环境搭建

172.28.104.82   MySQL数据库(docker形式部署),在82上安装node_exporter,mysqld_exporter172.28.104.120  prometheus服务端和Grafana

在内网82上安装mysqld_exporter和node_exporter

tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gztar -zxvf node_exporter-1.0.0-rc.0.linux-amd64.tar.gz

编辑mysqld_exporter目录下的my.cnf

[client]user=rootpassword=123456ip=172.28.104.82port=3307

在82机器上mysqld_exporter目录下启动,启动成功后,如下图

nohup ./mysqld_exporter --config.my-cnf=my.cnf & > mysqld_exporter.log nohup ./node_exporter  > node_exporter.log 

c0557b68f460ad69a7c24581e8026143.png

在120机器上安装Prometheus和Grafana

# 安装 Prometheustar -zxvf prometheus-2.18.1.linux-amd64.tar.gz# 安装 Grafanatar -zxvf grafana-7.0.0-1.x86_64.tar.gz

编辑prometheus.yml

# my global configglobal:  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 configurationalerting:  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:  # The job name is added as a label `job=` to any timeseries scraped from this config.  - job_name: 'prometheus'    # metrics_path defaults to '/metrics'    # scheme defaults to 'http'.    static_configs:    - targets: ['localhost:9090']  - job_name: 'mysql'    static_configs:    - targets: ['172.28.104.82:9104']      labels:        instance: 172.28.104.82  - job_name: 'linux'    static_configs:    - targets: ['172.28.104.82:9100']      labels:        instance: 172.28.104.82

在 120机器上的usr/local/prometheus-2.18.1.linux-amd64目录下启动prometheus

#启动 prometheunohup ./prometheus  > prometheus.log

951b3f205066eacd964abafea8921a2b.png

在120机器上的usr/local/grafana-7.0.0/bin/目录下启动grafna

#启动 grafananohup ./grafana-server > grafana-server.log

2e32791bd9d0043c32abfa2eed3b0b15.png

在Grafana中添加Data source

60518ed3504838f9342e0576509c3fca.png

在Grafana中添加Data source——在列表中选择Prometheus

0420c78bbfb30149fbee858a2e088708.png

在Grafana中添加Data source——在列表中选择MySQL

d00c74cedb865b9afbe828b1c4734c29.png

导入Mysql仪表盘 https://grafana.com/grafana/dashboards/7362

40b247cb215cf105447417781db2817b.png

选择MySQL 仪表盘

078ae49bf2f748c0a0ce9f696bd90984.png

MySQL Overview 主页面

dee50162b3beb032bdd25b72c3b1124a.png

在Prometheus的默认页面,在Status菜单项找到Targets选项,UP为上线健康状态

a16f332ecdb8d165931a637929c936eb.png

慢查询性能

查询性能方面,慢查询也是查询告警的一个重要的指标。MySQL还提供了一个Slow_queries的计数器,当查询的执行时间超过long_query_time的值后,计数器就会+1,其默认值为10秒,可以通过以下指令在MySQL中查询当前long_query_time的设置

SHOW VARIABLES LIKE 'long_query_time';也可以修改时间(修改为3秒)SET GLOBAL long_query_time = 3;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值