一、prometheus配置
1.prometheus安装
1.1官网下载安装包:https://prometheus.io/download/
1.2解压安装包:tar -zxvf prometheus-2.6.1.linux-amd64.tar.gz
1.3快速启动:进入解压目录并启动:./prometheus 默认使用解压目录下的prometheus.yml配置文件】
2.优化prometheus启动、停止
2.1创建日志记录文件:touch /var/log/prometheus.log
2.2添加服务prometheus服务:
$ cd /usr/lib/systemd/system
$ vim prometheus.service
prometheus.service内容
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
#User=prometheus # 必须用该用户和相应的执行权限否则不能启动
#Group=prometheus
User=root
Group=root
Type=simple
ExecStart=/opt/prometheus/prometheus.sh # 启动脚本
[Install]
WantedBy=multi-user.target
2.3启动脚本:vim /opt/prometheus/prometheus.sh
#!/bin/bash
/root/prometheus/prometheus-2.6.1.linux-amd64/prometheus --config.file=/root/prometheus/prometheus-2.6.1.linux-amd64/prometheus.yml &>> /var/log/prometheus.log
2.4启动、停止脚本:systemctl start prometheus.service / systemctl stop prometheus.service
2.5进入登录页面:ip:9090
二、安装grafana(centos)
1.1不同的操作系统具体参考官网:http://docs.grafana.org/
1.2(centos),配置文件为:/opt/grafana/grafana.ini
yum install https://dl.grafana.com/oss/release/grafana-5.4.2-1.x86_64.rpm
1.3启动:systemctl start grafana-server
1.4登录页面:ip:3000,账号密码默认:admin/admin
三、prometheus配置mysql
1.安装node_export、mysqld_export
#安装node_export
wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.14.0.linux-amd64.tar.gz -O node_exporter-0.14.0.linux-amd64.tar.gz
#安装mysqld_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.10.0/mysqld_exporter-0.10.0.linux-amd64.tar.gz -O mysqld_exporter-0.10.0.linux-amd64.tar.gz
#创建目录
mkdir /usr/local/services
mkdir /usr/local/services/prometheus_exporters
#解压node_export
tar zxf node_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local/services/prometheus_exporters --strip-components=1
#解压mysqld_exporter
tar zxf mysqld_exporter-0.10.0.linux-amd64.tar.gz -C /usr/local/services/prometheus_exporters --strip-components=1
1.2优化启动过程,类似prometheus
node_export进入解压目录直接启动: ./node_exporter
mysqld_export 进入解压目录直接启动:./mysqld_exporter -config.my-cnf=my.cnf
需要配置数据连接信息:需要注意权限问题
#解压文件夹目录创建文件
vim my.cnf
#内容,数据库账号密码
[client]
user=root
password=123456
port=3306
1.3启动node_export与mysqld_export
2.prometheus配置mysql
2.1修改prometheus.yml配置文件:
#修改
vim prometheus.yml
#添加:
- job_name: 'mysql'
static_configs:
- targets: ['192.168.1.158:9104']
labels:
instance: 192.168.1.158
- job_name: 'linux'
static_configs:
- targets: ['192.168.1.158:9100']
labels:
instance: db1
2.2重启服务,页面会看到
3.grafana配置
3.1Add prometheus datasource
2.添加mysql仪表盘:import 仪表盘
官网查询:Mysql overView https://grafana.com/dashboards?search=MySql%20Ov
选择datasource 为 Prometheus
四、增加canal监听
1.1修改prometheus配置文件
vim prometheus.yml
#增加内容
- job_name: 'canal'
static_configs:
- targets: ['localhost:11112']#canal服务ip
1.2grafana配置,增加canal仪表盘信息,如上,不过这次不是从官网下载,而是import外部文件
见下面:canal_instance.json
1.3重启服务可看到
canal_instance.json
{
"__inputs": [
{
"name": "DS_PROMETHEUS",
"label": "prometheus",
"description": "",
"type": "datasource",
"pluginId": "prometheus",
"pluginName": "Prometheus"
}
],
"__requires": [
{
"type": "grafana",
"id": "grafana",
"name": "Grafana",
"version": "5.2.2"
},
{
"type": "panel",
"id": "graph",
"name": "Graph",
"version": "5.0.0"
},
{
"type": "datasource",
"id": "prometheus",
"name": "Prometheus",
"version": "5.0.0"
}
],
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": "-- Grafana --",
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": null,
"iteration": 1536989235272,
"links": [],
"panels": [
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"id": 30,
"panels": [],
"title": "Instance status",
"type": "row"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "$datasource",
"description": "Canal instance 基本信息。",
"fill": 1,
"gridPos": {
"h": 5,
"w": 6,
"x": 0,
"y": 1
},
"id": 24,
"legend": {
"alignAsTable": true,
"avg": false,
"current": false,
"hideEmpty": false,
"hideZero": false,
"max": false,
"min": false,
"rightSide": true,
"show": true,
"sideWidth": 500,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"links": [],
"nullPointMode": "null",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"repeat": null,
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"targets": [
{
"expr": "canal_instance{destination=~\"$destination\"}",
"format": "time_series",
"instant": true,
"intervalFactor": 1,
"legendFormat": "Destination: {
{destination}}",
"refId": "A"
},
{
"expr": "canal_instance_parser_mode{destination=~\"$destination\"}",
"format": "time_series",
"instant": true,
"intervalFactor": 1,
"legendFormat": "Parallel parser: {
{parallel}}",
"refId": "B"
},
{
"expr": "canal_instance_store{destination=~\"$destination\"