SlideShare a Scribd company logo
MySQL Monitoring
using Prometheus & Grafana
2
dba.kim@gmail.com
https://kr.linkedin.com/in/youngheon-roy-kim-23a11181
About me
MySQL Monitoring Dashboard
3
Alert using slack
Grafana Dashboard
Architecture
4
DB Servers
Monitoring Server
node_exporter
mysql_exporter
prometheus
alert manager
playbook
node_exporter
mysql_exporter
•
•
•
Deploy Server
Install & config prometheus on monitoring server
5
1. Install Prometheus
Download .tar file
https://prometheus.io/download/
$tar –xvf prometheus-0.17.0rc2.linux-amd64.tar.gz –C /opt
$mv prometheus-0.17.0rc2.linux-amd64 prometheus
Install & config prometheus on monitoring server
6
2. Config prometheus.yml file
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_configs:
- job_name: linux_hostname1
target_groups:
- targets: [‘ip_addr:9100']
labels:
alias: hostname1
- job_name: mysql_hostname1
target_groups:
- targets: [‘ip_addr:9104']
labels:
alias: hostname1
/opt/prometheus/prometheus.yml
continue right side…
scrape_configs :
you can add server information.
It can be added automatically using ansible playbook.
Install & config alertmanager on monitoring server
7
1. Install alertmanager
Download .tar file
https://prometheus.io/download/
$tar –xvf alertmanager-0.1.1.linux-amd64.tar.gz –C /opt
$mv alertmanager-0.1.1.linux-amd64 alertmanager
2. make a slack Webhook url
You can make a slack webhook url for sending a alert message.
https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
Install & config alertmanager on monitoring server
8
3. Config simple.yml
/opt/alertmanager/simple.yml
global:
slack_api_url: {{ webhook url}}
route:
receiver: 'slack-notifications'
group_by: ['alertname', 'cluster', 'service']
group_wait: 30s
group_interval: 1m
repeat_interval: 3m
receivers:
- name: 'slack-notifications'
slack_configs:
- channel: {{ slack channel name}}
continue right side…
9
4. Config rule file(1/4)
/opt/alertmanager/alert.rules
ALERT LinuxLoad1m
IF node_load1 >15
FOR 1m
ANNOTATIONS {summary="Linux Load is at 10"}
ALERT LinuxMemory
IF ((node_memory_MemTotal - (node_memory_MemFree + node_memory_Buffers +
node_memory_Cached))/node_memory_MemTotal) * 100 >85
FOR 1m
ANNOTATIONS {summary="Linux Memory Usage is at 85%"}
continue next page…
Set a alert rule file
Install & config alertmanager on monitoring server
10
4. Config rule file(2/4)
/opt/alertmanager/alert.rules
ALERT LinuxDiskUsage
IF ((node_filesystem_size{fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs"} -
node_filesystem_avail{fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs"})
/node_filesystem_size{ fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs"}) * 100 > 90
FOR 5m
ANNOTATIONS {summary="Linux Disk Usage over 90%"}
ALERT MySQLSlaveLag
IF mysql_slave_lag_seconds > 300
FOR 1m
LABELS { severity = "warning" }
ANNOTATIONS { summary = "Slave lag is too high.", severity="warning" }
Set a alert rule file
Install & config alertmanager on monitoring server
continue next page…
11
4. Config rule file(3/4)
/opt/alertmanager/alert.rules
ALERT MySQLReplicationSQLThreadStatus
IF mysql_slave_status_slave_sql_running==0
FOR 1m
LABELS { severity = "warning" }
ANNOTATIONS { summary = "SQL thread stop", severity="warning"}
ALERT MySQLReplicationIOThreadStatus
IF mysql_slave_status_slave_io_running==0
FOR 1m
LABELS { severity = "warning" }
ANNOTATIONS { summary = "IO thread stop", severity="warning"}
continue next page…
Set a alert rule file
Install & config alertmanager on monitoring server
12
4. Config rule file(4/4)
/opt/alertmanager/alert.rules
ALERT MySQLstatus
IF mysql_up==0
FOR 30s
LABELS { severity = "warning" }
ANNOTATIONS { summary = "Mysql Process Down" }
continue next page…
Set a alert rule file
Install & config alertmanager on monitoring server
13
5. Add rule file information on prometheus.yml
/opt/prometheus/prometheus.yml
You can add following information between global and scrape_configs section.
global:
rule_files:
- /opt/alertmanager/alert.rules
scrape_configs:
Set a alert rule file
Install & config alertmanager on monitoring server
14
6. Start alertmanager and prometheus
Alertmanager start
#./alertmanager –config.file=simple.yml
Prometheus start
#./prometheus –config.file prometheus.yml –alertmanager.url=http://10.xxx.xxx.xxx:9093
start alertmanager and prometheus
Install & config alertmanager on monitoring server
Install & config alertmanager on monitoring server
15
7. Check status of alertmanager and prometheus
Prometheus status
http://10.xxx.xxx.xxx:9090/status
Install & config alertmanager on monitoring server
16
7. Check status of alertmanager and prometheus
Alertmanager status
http://10.xxx.xxx.xxx:9093/#/status
Auto install & config exporters using Ansible
17
1. Install Ansible
On iOS
$brew install ansible
On Linux
$yum install ansible
1818
2. Consist of Directory & Files
- /etc/hosts
- ~/ansible_hosts
- ~/ansible/playbooks/prometheus_exporter.yml
- ~/ansible/playbooks/files/prometheus/node_exporter-0.12.0.linux-amd64.tar.gz
- ~/ansible/playbooks/files/prometheus/mysqld_exporter-0.8.1.linux-amd64.tar.gz
- ~/ansible/playbooks/files/prometheus/start_node_exporter.sh
- ~/ansible/playbooks/files/prometheus/start_mysqld_exporter.sh
- ~/ansible/playbooks/files/prometheus/.my.cnf
- ~/ansible/playbooks/files/prometheus/prometheus.yml.temp
Auto install & config exporters using Ansible
19
/etc/hosts
~/ansible_hosts
#DB server lists
10.xxx.xxx.xxx dbhost01
10.xxx.xxx.xxx dbhost02
10.xxx.xxx.xxx dbhost03
[Group1]
dbhost01
dbhost02
dbhost03
system hosts file
ansible hosts file
You should set following information on profile.
export ANSIBLE_INVENTORY=~/ansible_hosts
Auto install & config exporters using Ansible
20
~/ansible/playbooks/prometheus_exporter.yml
- name: Prometheus Install and Configuration
user : user1
hosts: Group1
sudo: yes
tasks:
- name: make directory
file: path=/opt/prometheus_exporters/ state=directory
- name: Copy tar.gz files
copy: src=files/prometheus/{{ item }} dest=/opt/prometheus_exporters/{{ item }}
with_items:
- node_exporter-0.12.0.linux-amd64.tar.gz
- mysqld_exporter-0.8.1.linux-amd64.tar.gz
continue next page…
ansible playbook file
for install and config
prometheus exporter
Auto install & config exporters using Ansible
21
~/ansible/playbooks/prometheus_exporter.yml
- name: Uncompress gz files
command: tar -xzvf /opt/prometheus_exporters/{{ item }} -C /opt/prometheus_exporters
with_items:
- node_exporter-0.12.0.linux-amd64.tar.gz
- mysqld_exporter-0.8.1.linux-amd64.tar.gz
- name: Rename node_exporter Directory name
command: mv /opt/prometheus_exporters/node_exporter-0.12.0.linux-amd64 /opt/prometheus_exporters/node_exporter
- name: Rename mysqld_exporter Directory name
command: mv /opt/prometheus_exporters/mysqld_exporter-0.8.1.linux-amd64 /opt/prometheus_exporters/mysqld_exporter
- name: change directory owner
file: path=/opt/prometheus_exporters/{{ item }} state=directory owner=root group=root mode=640
with_items:
- node_exporter
- mysqld_exporter
continue next page…
Auto install & config exporters using Ansible
22
~/ansible/playbooks/prometheus_exporter.yml
- name: Copy start_mysqld_exporter.sh
copy: src=files/prometheus/{{ item }} dest=/opt/prometheus_exporters/mysqld_exporter
with_items:
- start_mysqld_exporter.sh
- name: Copy start_node_exporter.sh
copy: src=files/prometheus/{{ item }} dest=/opt/prometheus_exporters/node_exporter
with_items:
- start_node_exporter.sh
- name: .my.cnf coyp
template: src=files/prometheus/.my.cnf dest=/opt/prometheus_exporters/mysqld_exporter
owner=root group=root mode=640
Auto install & config exporters using Ansible
continue next page…
23
~/ansible/playbooks/prometheus_exporter.yml
- name: .my.cnf coyp
template: src=files/prometheus/.my.cnf dest=/opt/prometheus_exporters/mysqld_exporter
owner=root group=root mode=640
- name: Execute node exporter
command: /bin/sh /opt/prometheus_exporters/node_exporter/start_node_exporter.sh
- name: Execute mysql exporter
command: /bin/sh /opt/prometheus_exporters/mysqld_exporter/start_mysqld_exporter.sh
- name: move new host info on prometheus server
template: src=files/prometheus/prometheus.yml.temp dest=/opt/prometheus/prometheus.yml.{{ansible_hostname}}
owner=root group=root mode=640
delegate_to: monitoring_server_hostname
- name: add new host info on prometheus.yml
shell: cat /opt/prometheus/prometheus.yml.{{ansible_hostname}} >> /opt/prometheus/prometheus.yml
delegate_to: monitoring_server_hostname
Auto install & config exporters using Ansible
24
~/ansible/playbooks/files/prometheus/
node_exporter-0.12.0.linux-amd64.tar.gz
mysqld_exporter-0.8.1.linux-amd64.tar.gz
start_node_exporter.sh
start_mysqld_exporter.sh
: node_exporter install file
: mysqld_exporter install file
: node_exporter start script
nohup /opt/prometheus_exporters/node_exporter/node_exporter &
nohup /opt/prometheus_exporters/mysqld_exporter/mysqld_exporter
-config.my-cnf="/opt/prometheus_exporters/mysqld_exporter/.my.cnf" &
Auto install & config exporters using Ansible
: mysqld_exporter start script
25
~/ansible/playbooks/files/prometheus/
.my.cnf
[client]
host= {{ansible_default_ipv4.address}}
user=mon_user # db user for monitoring
password=mon_user_passwd # db user password
Auto install & config exporters using Ansible
: mysqld_exporter config file
mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO ‘mon_user'@'127.0.0.1' identified by ‘mon_user_passwd';
mysql> GRANT SELECT ON performance_schema.* TO ‘mon_user'@'127.0.0.1';
You have to add db user for monitoring on db server
26
~/ansible/playbooks/files/prometheus/
prometheus.yml.temp
- job_name: linux_{{ansible_hostname}}
target_groups:
- targets: ['{{ansible_default_ipv4.address}}:9100']
labels:
alias: {{ansible_hostname}}
- job_name: mysql_{{ansible_hostname}}
target_groups:
- targets: ['{{ansible_default_ipv4.address}}:9104']
labels:
alias: {{ansible_hostname}}
Auto install & config exporters using Ansible
: prometheus config information
Install & config grafana on monitoring server
27
1. Install Grafana
Download rpm file
http://grafana.org/download/
#rpm –ivh grafana-3.1.1-1470047149.x86_64.rpm
#/etc/init.d/grafana start
2. Grafana connect on web browser
http://10.xxx.xxx.xxx:3000/
28
Make grafana dashboard
CPU Usage
Disk
Bandwidth
Disk space
MySQL
Active
Threads
Load
Average
MySQL QPS
Network
Traffic
Memory
Make grafana dashboard
29
1. Register Datasource
Make grafana dashboard
30
2. Create new dashboard and templating
31
Make grafana dashboard
3. Create a templating
32
Make grafana dashboard
4. Add Graph-Load average(1)
33
Make grafana dashboard
4. Add Graph-Load average(2)
34
Make grafana dashboard
4. Add Graph-Load average(3)
35
Make grafana dashboard
4. Add Graph-Load average(4)
36
Make grafana dashboard
4. Add Graph-Load average(5)
37
Make grafana dashboard
4. Add Graph-Load average(6)
38
Make grafana dashboard
4. Add Graph-Load average(7)
39
Make grafana dashboard
5. Add Graph-CPU Usage
6. Add Graph-Disk Bandwidth
40
Make grafana dashboard
7. Add Graph-Disk space
Query Detail
((node_filesystem_size{fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs",alias="$host"} -
node_filesystem_avail{fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs",alias="$host"})
/node_filesystem_size{ fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs",alias="$host"}) * 100
41
Make grafana dashboard
8. Add Graph-MySQL Active Threads
9. Add Graph-MySQL QPS
42
Make grafana dashboard
10. Add Graph-Network Traffic
43
Make grafana dashboard
11. Add Graph-Memory
44
Make grafana dashboard
You can get more various kinds of dashboard.
https://github.com/percona/grafana-dashboards
Thank You

More Related Content

PPTX
Prometheus and Grafana
PDF
Redis cluster
PDF
Explore your prometheus data in grafana - Promcon 2018
PPTX
Prometheus - Intro, CNCF, TSDB,PromQL,Grafana
PDF
Getting Started Monitoring with Prometheus and Grafana
PDF
PostgreSQL replication
PDF
Kubernetes
PDF
Prometheus and Grafana
Redis cluster
Explore your prometheus data in grafana - Promcon 2018
Prometheus - Intro, CNCF, TSDB,PromQL,Grafana
Getting Started Monitoring with Prometheus and Grafana
PostgreSQL replication
Kubernetes

What's hot (20)

PDF
Hands-On Introduction to Kubernetes at LISA17
PPTX
Grafana optimization for Prometheus
PPTX
Introduction to Docker - 2017
PDF
OpenShift 4, the smarter Kubernetes platform
ODP
Kubernetes Architecture
PDF
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
PDF
Real Time Test Data with Grafana
PDF
Prometheus Overview
PPTX
Gatekeeper: API gateway
PPTX
An Introduction to Prometheus (GrafanaCon 2016)
PDF
Scale Kubernetes to support 50000 services
PDF
What is new in PostgreSQL 14?
PDF
Kubernetes Introduction
PDF
Introducing Vault
PPTX
Elastic - ELK, Logstash & Kibana
PPTX
Docker introduction
PDF
Grafana Loki: like Prometheus, but for Logs
PPTX
PPTX
PostgreSQL Database Slides
PDF
Cloud Monitoring tool Grafana
Hands-On Introduction to Kubernetes at LISA17
Grafana optimization for Prometheus
Introduction to Docker - 2017
OpenShift 4, the smarter Kubernetes platform
Kubernetes Architecture
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Real Time Test Data with Grafana
Prometheus Overview
Gatekeeper: API gateway
An Introduction to Prometheus (GrafanaCon 2016)
Scale Kubernetes to support 50000 services
What is new in PostgreSQL 14?
Kubernetes Introduction
Introducing Vault
Elastic - ELK, Logstash & Kibana
Docker introduction
Grafana Loki: like Prometheus, but for Logs
PostgreSQL Database Slides
Cloud Monitoring tool Grafana
Ad

Similar to MySQL Monitoring using Prometheus & Grafana (20)

PDF
Infrastructure & System Monitoring using Prometheus
PDF
OSMC 2017 | Monitoring MySQL with Prometheus and Grafana by Julien Pivotto
PPTX
Monitoring_with_Prometheus_Grafana_Tutorial
PDF
OSDC 2018 | Hardware-level data-center monitoring with Prometheus by Conrad H...
PDF
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
PDF
Dbdeployer, the universal installer
PDF
Script it
PDF
Modern MySQL Monitoring and Dashboards.
PDF
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...
PDF
DevOps Braga #15: Agentless monitoring with icinga and prometheus
PDF
System monitoring
PPTX
Prometheus Training
PDF
Prometheus course
PDF
How Ansible Tower and Prometheus can help automate continuous deployments
PDF
Dbdeployer
PDF
Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...
PDF
Percona Cluster Installation with High Availability
PDF
Test complex database systems in your laptop with dbdeployer
PDF
Prometheus Course from beginners to expert course
PDF
[OpenInfra Days Korea 2018] Day 2 - E6 - OpenInfra monitoring with Prometheus
Infrastructure & System Monitoring using Prometheus
OSMC 2017 | Monitoring MySQL with Prometheus and Grafana by Julien Pivotto
Monitoring_with_Prometheus_Grafana_Tutorial
OSDC 2018 | Hardware-level data-center monitoring with Prometheus by Conrad H...
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
Dbdeployer, the universal installer
Script it
Modern MySQL Monitoring and Dashboards.
Jacopo Nardiello - Monitoring Cloud-Native applications with Prometheus - Cod...
DevOps Braga #15: Agentless monitoring with icinga and prometheus
System monitoring
Prometheus Training
Prometheus course
How Ansible Tower and Prometheus can help automate continuous deployments
Dbdeployer
Webinar Slides : Migrating to MySQL, MariaDB Galera and/or Percona XtraDB Clu...
Percona Cluster Installation with High Availability
Test complex database systems in your laptop with dbdeployer
Prometheus Course from beginners to expert course
[OpenInfra Days Korea 2018] Day 2 - E6 - OpenInfra monitoring with Prometheus
Ad

More from YoungHeon (Roy) Kim (6)

PPTX
Query logging with proxysql
PPTX
My sql failover test using orchestrator
PPTX
Airflow를 이용한 데이터 Workflow 관리
PPTX
ProxySQL & PXC(Query routing and Failover Test)
PPTX
MySQL Slow Query log Monitoring using Beats & ELK
PPTX
MySQL Audit using Percona audit plugin and ELK
Query logging with proxysql
My sql failover test using orchestrator
Airflow를 이용한 데이터 Workflow 관리
ProxySQL & PXC(Query routing and Failover Test)
MySQL Slow Query log Monitoring using Beats & ELK
MySQL Audit using Percona audit plugin and ELK

Recently uploaded (20)

PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Electronic commerce courselecture one. Pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation theory and applications.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
A Presentation on Artificial Intelligence
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Empathic Computing: Creating Shared Understanding
PDF
Approach and Philosophy of On baking technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Electronic commerce courselecture one. Pdf
cuic standard and advanced reporting.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
MYSQL Presentation for SQL database connectivity
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation theory and applications.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
A Presentation on Artificial Intelligence
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Understanding_Digital_Forensics_Presentation.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Empathic Computing: Creating Shared Understanding
Approach and Philosophy of On baking technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025

MySQL Monitoring using Prometheus & Grafana

  • 3. MySQL Monitoring Dashboard 3 Alert using slack Grafana Dashboard
  • 4. Architecture 4 DB Servers Monitoring Server node_exporter mysql_exporter prometheus alert manager playbook node_exporter mysql_exporter • • • Deploy Server
  • 5. Install & config prometheus on monitoring server 5 1. Install Prometheus Download .tar file https://prometheus.io/download/ $tar –xvf prometheus-0.17.0rc2.linux-amd64.tar.gz –C /opt $mv prometheus-0.17.0rc2.linux-amd64 prometheus
  • 6. Install & config prometheus on monitoring server 6 2. Config prometheus.yml file global: scrape_interval: 5s evaluation_interval: 5s scrape_configs: - job_name: linux_hostname1 target_groups: - targets: [‘ip_addr:9100'] labels: alias: hostname1 - job_name: mysql_hostname1 target_groups: - targets: [‘ip_addr:9104'] labels: alias: hostname1 /opt/prometheus/prometheus.yml continue right side… scrape_configs : you can add server information. It can be added automatically using ansible playbook.
  • 7. Install & config alertmanager on monitoring server 7 1. Install alertmanager Download .tar file https://prometheus.io/download/ $tar –xvf alertmanager-0.1.1.linux-amd64.tar.gz –C /opt $mv alertmanager-0.1.1.linux-amd64 alertmanager 2. make a slack Webhook url You can make a slack webhook url for sending a alert message. https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
  • 8. Install & config alertmanager on monitoring server 8 3. Config simple.yml /opt/alertmanager/simple.yml global: slack_api_url: {{ webhook url}} route: receiver: 'slack-notifications' group_by: ['alertname', 'cluster', 'service'] group_wait: 30s group_interval: 1m repeat_interval: 3m receivers: - name: 'slack-notifications' slack_configs: - channel: {{ slack channel name}} continue right side…
  • 9. 9 4. Config rule file(1/4) /opt/alertmanager/alert.rules ALERT LinuxLoad1m IF node_load1 >15 FOR 1m ANNOTATIONS {summary="Linux Load is at 10"} ALERT LinuxMemory IF ((node_memory_MemTotal - (node_memory_MemFree + node_memory_Buffers + node_memory_Cached))/node_memory_MemTotal) * 100 >85 FOR 1m ANNOTATIONS {summary="Linux Memory Usage is at 85%"} continue next page… Set a alert rule file Install & config alertmanager on monitoring server
  • 10. 10 4. Config rule file(2/4) /opt/alertmanager/alert.rules ALERT LinuxDiskUsage IF ((node_filesystem_size{fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs"} - node_filesystem_avail{fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs"}) /node_filesystem_size{ fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs"}) * 100 > 90 FOR 5m ANNOTATIONS {summary="Linux Disk Usage over 90%"} ALERT MySQLSlaveLag IF mysql_slave_lag_seconds > 300 FOR 1m LABELS { severity = "warning" } ANNOTATIONS { summary = "Slave lag is too high.", severity="warning" } Set a alert rule file Install & config alertmanager on monitoring server continue next page…
  • 11. 11 4. Config rule file(3/4) /opt/alertmanager/alert.rules ALERT MySQLReplicationSQLThreadStatus IF mysql_slave_status_slave_sql_running==0 FOR 1m LABELS { severity = "warning" } ANNOTATIONS { summary = "SQL thread stop", severity="warning"} ALERT MySQLReplicationIOThreadStatus IF mysql_slave_status_slave_io_running==0 FOR 1m LABELS { severity = "warning" } ANNOTATIONS { summary = "IO thread stop", severity="warning"} continue next page… Set a alert rule file Install & config alertmanager on monitoring server
  • 12. 12 4. Config rule file(4/4) /opt/alertmanager/alert.rules ALERT MySQLstatus IF mysql_up==0 FOR 30s LABELS { severity = "warning" } ANNOTATIONS { summary = "Mysql Process Down" } continue next page… Set a alert rule file Install & config alertmanager on monitoring server
  • 13. 13 5. Add rule file information on prometheus.yml /opt/prometheus/prometheus.yml You can add following information between global and scrape_configs section. global: rule_files: - /opt/alertmanager/alert.rules scrape_configs: Set a alert rule file Install & config alertmanager on monitoring server
  • 14. 14 6. Start alertmanager and prometheus Alertmanager start #./alertmanager –config.file=simple.yml Prometheus start #./prometheus –config.file prometheus.yml –alertmanager.url=http://10.xxx.xxx.xxx:9093 start alertmanager and prometheus Install & config alertmanager on monitoring server
  • 15. Install & config alertmanager on monitoring server 15 7. Check status of alertmanager and prometheus Prometheus status http://10.xxx.xxx.xxx:9090/status
  • 16. Install & config alertmanager on monitoring server 16 7. Check status of alertmanager and prometheus Alertmanager status http://10.xxx.xxx.xxx:9093/#/status
  • 17. Auto install & config exporters using Ansible 17 1. Install Ansible On iOS $brew install ansible On Linux $yum install ansible
  • 18. 1818 2. Consist of Directory & Files - /etc/hosts - ~/ansible_hosts - ~/ansible/playbooks/prometheus_exporter.yml - ~/ansible/playbooks/files/prometheus/node_exporter-0.12.0.linux-amd64.tar.gz - ~/ansible/playbooks/files/prometheus/mysqld_exporter-0.8.1.linux-amd64.tar.gz - ~/ansible/playbooks/files/prometheus/start_node_exporter.sh - ~/ansible/playbooks/files/prometheus/start_mysqld_exporter.sh - ~/ansible/playbooks/files/prometheus/.my.cnf - ~/ansible/playbooks/files/prometheus/prometheus.yml.temp Auto install & config exporters using Ansible
  • 19. 19 /etc/hosts ~/ansible_hosts #DB server lists 10.xxx.xxx.xxx dbhost01 10.xxx.xxx.xxx dbhost02 10.xxx.xxx.xxx dbhost03 [Group1] dbhost01 dbhost02 dbhost03 system hosts file ansible hosts file You should set following information on profile. export ANSIBLE_INVENTORY=~/ansible_hosts Auto install & config exporters using Ansible
  • 20. 20 ~/ansible/playbooks/prometheus_exporter.yml - name: Prometheus Install and Configuration user : user1 hosts: Group1 sudo: yes tasks: - name: make directory file: path=/opt/prometheus_exporters/ state=directory - name: Copy tar.gz files copy: src=files/prometheus/{{ item }} dest=/opt/prometheus_exporters/{{ item }} with_items: - node_exporter-0.12.0.linux-amd64.tar.gz - mysqld_exporter-0.8.1.linux-amd64.tar.gz continue next page… ansible playbook file for install and config prometheus exporter Auto install & config exporters using Ansible
  • 21. 21 ~/ansible/playbooks/prometheus_exporter.yml - name: Uncompress gz files command: tar -xzvf /opt/prometheus_exporters/{{ item }} -C /opt/prometheus_exporters with_items: - node_exporter-0.12.0.linux-amd64.tar.gz - mysqld_exporter-0.8.1.linux-amd64.tar.gz - name: Rename node_exporter Directory name command: mv /opt/prometheus_exporters/node_exporter-0.12.0.linux-amd64 /opt/prometheus_exporters/node_exporter - name: Rename mysqld_exporter Directory name command: mv /opt/prometheus_exporters/mysqld_exporter-0.8.1.linux-amd64 /opt/prometheus_exporters/mysqld_exporter - name: change directory owner file: path=/opt/prometheus_exporters/{{ item }} state=directory owner=root group=root mode=640 with_items: - node_exporter - mysqld_exporter continue next page… Auto install & config exporters using Ansible
  • 22. 22 ~/ansible/playbooks/prometheus_exporter.yml - name: Copy start_mysqld_exporter.sh copy: src=files/prometheus/{{ item }} dest=/opt/prometheus_exporters/mysqld_exporter with_items: - start_mysqld_exporter.sh - name: Copy start_node_exporter.sh copy: src=files/prometheus/{{ item }} dest=/opt/prometheus_exporters/node_exporter with_items: - start_node_exporter.sh - name: .my.cnf coyp template: src=files/prometheus/.my.cnf dest=/opt/prometheus_exporters/mysqld_exporter owner=root group=root mode=640 Auto install & config exporters using Ansible continue next page…
  • 23. 23 ~/ansible/playbooks/prometheus_exporter.yml - name: .my.cnf coyp template: src=files/prometheus/.my.cnf dest=/opt/prometheus_exporters/mysqld_exporter owner=root group=root mode=640 - name: Execute node exporter command: /bin/sh /opt/prometheus_exporters/node_exporter/start_node_exporter.sh - name: Execute mysql exporter command: /bin/sh /opt/prometheus_exporters/mysqld_exporter/start_mysqld_exporter.sh - name: move new host info on prometheus server template: src=files/prometheus/prometheus.yml.temp dest=/opt/prometheus/prometheus.yml.{{ansible_hostname}} owner=root group=root mode=640 delegate_to: monitoring_server_hostname - name: add new host info on prometheus.yml shell: cat /opt/prometheus/prometheus.yml.{{ansible_hostname}} >> /opt/prometheus/prometheus.yml delegate_to: monitoring_server_hostname Auto install & config exporters using Ansible
  • 24. 24 ~/ansible/playbooks/files/prometheus/ node_exporter-0.12.0.linux-amd64.tar.gz mysqld_exporter-0.8.1.linux-amd64.tar.gz start_node_exporter.sh start_mysqld_exporter.sh : node_exporter install file : mysqld_exporter install file : node_exporter start script nohup /opt/prometheus_exporters/node_exporter/node_exporter & nohup /opt/prometheus_exporters/mysqld_exporter/mysqld_exporter -config.my-cnf="/opt/prometheus_exporters/mysqld_exporter/.my.cnf" & Auto install & config exporters using Ansible : mysqld_exporter start script
  • 25. 25 ~/ansible/playbooks/files/prometheus/ .my.cnf [client] host= {{ansible_default_ipv4.address}} user=mon_user # db user for monitoring password=mon_user_passwd # db user password Auto install & config exporters using Ansible : mysqld_exporter config file mysql> GRANT REPLICATION CLIENT, PROCESS ON *.* TO ‘mon_user'@'127.0.0.1' identified by ‘mon_user_passwd'; mysql> GRANT SELECT ON performance_schema.* TO ‘mon_user'@'127.0.0.1'; You have to add db user for monitoring on db server
  • 26. 26 ~/ansible/playbooks/files/prometheus/ prometheus.yml.temp - job_name: linux_{{ansible_hostname}} target_groups: - targets: ['{{ansible_default_ipv4.address}}:9100'] labels: alias: {{ansible_hostname}} - job_name: mysql_{{ansible_hostname}} target_groups: - targets: ['{{ansible_default_ipv4.address}}:9104'] labels: alias: {{ansible_hostname}} Auto install & config exporters using Ansible : prometheus config information
  • 27. Install & config grafana on monitoring server 27 1. Install Grafana Download rpm file http://grafana.org/download/ #rpm –ivh grafana-3.1.1-1470047149.x86_64.rpm #/etc/init.d/grafana start 2. Grafana connect on web browser http://10.xxx.xxx.xxx:3000/
  • 28. 28 Make grafana dashboard CPU Usage Disk Bandwidth Disk space MySQL Active Threads Load Average MySQL QPS Network Traffic Memory
  • 29. Make grafana dashboard 29 1. Register Datasource
  • 30. Make grafana dashboard 30 2. Create new dashboard and templating
  • 31. 31 Make grafana dashboard 3. Create a templating
  • 32. 32 Make grafana dashboard 4. Add Graph-Load average(1)
  • 33. 33 Make grafana dashboard 4. Add Graph-Load average(2)
  • 34. 34 Make grafana dashboard 4. Add Graph-Load average(3)
  • 35. 35 Make grafana dashboard 4. Add Graph-Load average(4)
  • 36. 36 Make grafana dashboard 4. Add Graph-Load average(5)
  • 37. 37 Make grafana dashboard 4. Add Graph-Load average(6)
  • 38. 38 Make grafana dashboard 4. Add Graph-Load average(7)
  • 39. 39 Make grafana dashboard 5. Add Graph-CPU Usage 6. Add Graph-Disk Bandwidth
  • 40. 40 Make grafana dashboard 7. Add Graph-Disk space Query Detail ((node_filesystem_size{fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs",alias="$host"} - node_filesystem_avail{fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs",alias="$host"}) /node_filesystem_size{ fstype!~"rootfs|selinuxfs|autofs|rpc_pipefs|tmpfs",alias="$host"}) * 100
  • 41. 41 Make grafana dashboard 8. Add Graph-MySQL Active Threads 9. Add Graph-MySQL QPS
  • 42. 42 Make grafana dashboard 10. Add Graph-Network Traffic
  • 43. 43 Make grafana dashboard 11. Add Graph-Memory
  • 44. 44 Make grafana dashboard You can get more various kinds of dashboard. https://github.com/percona/grafana-dashboards