在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
prometheus通过exporter监控mysql,并用grafana图表展示概述: prometheus是由SoundCloud开发的开源监控告警系统并且自带时序数据库,基于Go语言。Prometheus根据配置的任务(job)以周期性pull的方式获取指定目标(target)上的指标(metric)。 Prometheus 生态圈中包含了多个组件:
接下来开始演示 1、测试机器prometheus-server 192.168.56.140 MySQL host01 192.168.56.103 MySQL host02 192.168.56.104 2、配置mysql host01MySQL使用版本: 8.0.25 MySQL Community Server 3、创建exporter帐号mysqld_exporter通过查询mysql的状态表及状态命令获取数据。所以,需要先在mysql内,创建相应帐号 create user 'exporter'@'%' identified by 'Xiaopang*803'; GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'exporter'@'%'; GRANT SELECT ON performance_schema.* TO 'exporter'@'%'; flush privileges; 4、下载,安装mysqld_exporterwget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz 4.1 编辑文件输入密码编缉如下文件,输入exporter用户句与密码(与前面mysql内创建的帐号密码一致) [root@host01 mysqld_exporter]# vi .my.cnf [client] user=exporter password=Xiaopang*803 4.2 添加启动服务文件[root@host01 ~]# vi /etc/systemd/system/mysqld_exporter.service [Unit] Description=mysqld_exporter After=network.target [Service] Type=simple ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf Restart=on-failure [Install] WantedBy=multi-user.target 4.3 启动mysqld_exporterservice mysqld_exporter start 4.4 测试验证mysqld_exporter默认使用9104端口,我们可以在浏览器内输入如下地址。查看是否有数据输出。 输入 http://192.168.56.103:9104/metrics 输出信息类似如下: # HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile="0"} 2.5395e-05 go_gc_duration_seconds{quantile="0.25"} 3.5372e-05 go_gc_duration_seconds{quantile="0.5"} 3.9393e-05 go_gc_duration_seconds{quantile="0.75"} 5.5068e-05 go_gc_duration_seconds{quantile="1"} 0.062537624 go_gc_duration_seconds_sum 0.453204071 go_gc_duration_seconds_count 2131 # HELP go_goroutines Number of goroutines that currently exist. # TYPE go_goroutines gauge 5、下载,安装node_exporter如果只安装mysqld_exporter则无法监控OS相关的数据,所以需要安装node_exporter进行OS监控。 wget https://github.com/prometheus/node_exporter/releases/download/v1.2.2/node_exporter-1.2.2.linux-amd64.tar.gz tar xvzf node_exporter-1.2.2.linux-amd64.tar.gz -C /usr/local/. cd /usr/local && ln -s node_exporter-1.2.2.linux-amd64/ node_exporter 5.1 添加启动服务文件[root@host01 ~]# vi /etc/systemd/system/node_exporter.service [Unit] Description=node_export Documentation=https://github.com/prometheus/node_exporter After=network.target [Service] Type=simple User=root Group=root ExecStart=/usr/local/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target 5.2 启动node_exporterservice node_exporter start 5.3 测试验证node_exporter默认使用9100端口,我们可以在浏览器内输入如下地址。查看是否有数据输出。 输入 http://192.168.56.103:9100/metrics 输出结果类似如下: # HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles. # TYPE go_gc_duration_seconds summary go_gc_duration_seconds{quantile="0"} 2.5934e-05 go_gc_duration_seconds{quantile="0.25"} 4.0072e-05 go_gc_duration_seconds{quantile="0.5"} 4.7616e-05 go_gc_duration_seconds{quantile="0.75"} 6.726e-05 go_gc_duration_seconds{quantile="1"} 0.228887598 go_gc_duration_seconds_sum 0.550266258 go_gc_duration_seconds_count 793 # HELP go_goroutines Number of goroutines that currently exist. # TYPE go_goroutines gauge 6、安装prometheus+grafana 使用版本: prometheus 2.28 grafana 6.7.6 6.1 安装下载软件包 wget https://github.com/prometheus/prometheus/releases/download/v2.28.1/prometheus-2.28.1.linux-amd64.tar.gz 6.2 解压并添加软链接tar xvzf prometheus-2.28.1.linux-amd64.tar.gz -C /usr/local/. cd /usr/local/ ln -s prometheus-2.28.1.linux-amd64/ prometheus 6.3 增加启动服务[root@prometheus-server prometheus]# vi /etc/systemd/system/prometheus.service [Unit] Description=Prometheus Monitoring System Documentation=Prometheus Monitoring System [Service] Type=simple User=root Group=root ExecStart=/usr/local/prometheus/prometheus \ --config.file=/usr/local/prometheus/prometheus.yml \ --storage.tsdb.path="data/" \ --storage.tsdb.retention.time=15d \ --web.max-connections=512 \ --web.listen-address=:9090 6.4 添加mysql监控vi /usr/local/prometheus/prometheus.yml scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'mysql' static_configs: - targets: ['192.168.56.103:9104'] labels: instance: mysql_instance1 - job_name: 'linux' static_configs: - targets: ['192.168.56.103:9100'] labels: instance: mysql_instance1 6.5 启动prometheusservice prometheus start 6.7 查看prometheusprometheus默认监控端口 http://192.168.56.140:9090/ 点击status->target。如果一切正常,可以看到如下mysql/linux的state为UP 7、下载,安装grafana
|
请发表评论