1、下载安装包
mysqld_exporter-0.12.1.linux-amd64.tar.gz
[mysql_exporter工具包][https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz]
node_exporter-1.0.0-rc.0.linux-amd64.tar.gz
[监控机器的工具包][https://github.com/prometheus/node_exporter/releases/download/v1.0.0-rc.0/node_exporter-1.0.0-rc.0.linux-amd64.tar.gz]
2、解压缩文件
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/
tar -zxvf node_exporter-1.0.0-rc.0.linux-amd64.tar.gz -C /usr/local/
3、导入mysql的一些配置
export DATA_SOURCE_NAME="username:password@(host:port)/"
echo "export DATA_SOURCE_NAME='username:password@(host:port)/'" >>/etc/profile
4、启动mysqld_exporter
cd /usr/local/mysqld_exporter-0.12.1.linux-amd64/
#启动
nohup ./mysqld_exporter --collect.info_schema.innodb_tablespaces --collect.info_schema.innodb_metrics --collect.info_schema.innodb_cmp --collect.info_schema.innodb_cmpmem --collect.perf_schema.tableiowaits --collect.perf_schema.indexiowaits --collect.perf_schema.tablelocks --collect.engine_innodb_status --collect.perf_schema.file_events --collect.info_schema.processlist --collect.binlog_size --collect.info_schema.clientstats --collect.perf_schema.eventswaits &
通过netstat -tnlp | grep "9104"
可以查看到本地已经在监听9104端口了。
6、启动node exporter
#cd
cd node_exporter-1.0.0-rc.0.linux-amd64/
#启动
nohup ./node_exporter &
通过netstat -tnlp | grep "9100"
可以查看到本地已经在监听9100端口了。
7、配置Prometheus
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'mysql'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
metrics_path: 'metrics'
static_configs:
- targets: ['host:9104']
- job_name: 'node'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
metrics_path: 'metrics'
static_configs:
- targets: ['host:9100']
启动Prometheus
/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml &
进入到Prometheus的管理页面查看目标是否已经接通并且可以抓取。选择Status
->Target
菜单,就可以看到配置的俩个exporter源都已经是UP
状态了。
Prometheus也提供了一个简单的查询页面,可以按照查询条件去展示值或者图形。
8、高大上的Grafana
和Prometheus最搭的还是Grafana,Grafana是一款强大的展示监控信息的web图形展示工具。对于各种指标都能以合适的图形展示出来。
这里我们选取的是俩款Grafana模板来展示上文搭建的监控指标。
1、[MYSQL Overview][https://grafana.com/grafana/dashboards/7362]
效果如下:
2,[机器指标监控][https://grafana.com/grafana/dashboards/8919]
效果如下: