ref:
安装 grafana
docker run -d --name=grafana \
-v grafana-storage:/var/lib/grafana \
-p 3000:3000 \
--restart=unless-stopped \
grafana/grafana
现在打开 http://dockerip:3000 默认账户密码 admin admin
安装 promethues
先创建配置文件
mkdir /path/to/config-folder
cd /path/to/config-folder
vi prometheus.yml
# my global config
global:
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 configuration
alerting:
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=<job_name>` 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: 'mikrotik-exporter'
static_configs:
- targets:
- dockerip地址:9436
labels:
instance: 'RB4011'
env: 'Prodction'
安装
docker run -d --name=prometheus \
-p 9090:9090 \
-v /path/to/config-folder:/etc/prometheus \
--restart=unless-stopped \
prom/prometheus
现在打开 http://dockerip:9090 测试
安装mikrotik exporter
获取mikrotik ros 信息
进入winbox 或者ssh操作
创建用户组并赋予只读权限
/user group add name=prometheus policy=api,read,winbox
给用户设置密码
/user add name=prometheus group=prometheus password=密码
创建配置文件
mkdir /path/to/config-folder
cd /path/to/config-folder
vi config.yml
内容
devices:
- name: 路由器起个名
address: 路由器ip
user: prometheus
password: api用户的密码
features:
dhcp: true
dhcpl: true
capsman: true
health: true
routes: true
pool: true
wlan-interfaces: true
wlan-stations: true
monitor: true
安装 mikrotik-exporter
docker run -d --name mikrotik-exporter \
-e CONFIG_FILE=/config/config.yml \
-p 9436:9436 \
--restart=unless-stopped \
-v /path/to/config-folder:/config \
nshttpd/mikrotik-exporter
现在打开 http://dockerip:9436/metrics 检查有没有获取到信息
如果一切正常
现在只要在grafana操作
进入后台
找到齿轮标志 data source - Add data source
搜索 prometheus url处添加 http://dockerip:9090
再找到
https://grafana.com/grafana/dashboards/12055
grafana后台 点击 + 号, import 输入12055
即可自动下载面板配置了
grafana很强大
可根据 http://dockerip:9436/mertics 内容自行添加 优化改善得出自己想要的监控结果
还可以设置telegram 钉钉 邮箱等提醒