使用InfluxDB,Grafana和Telegraf监控Docker环境

dockerhc 2019-09-08

使用InfluxDB,Grafana和Telegraf监控Docker环境

安装Grafana

  • 创建持久存储卷,确保在销毁并重新创建grafana docker以进行升级时,将保留应用的配置
# 挂在本地目录
mkdir /data/grafana-storage 
docker run -d --name=grafana -p 3000:3000 --name=grafana -v /data/grafana-storage:/var/lib/grafana grafana/grafana
  • 安装插件
# 根据需要自行安装
# grafana-cli plugins ls | grep -v Restart | grep -v installed | awk '{print $1}' (查看配置好已安装的插件,全新安装的grafana需要安装)           
alexanderzobnin-zabbix-app
grafana-clock-panel
grafana-kubernetes-app
grafana-piechart-panel
grafana-simple-json-datasource
grafana-worldmap-panel
michaeldmoore-annunciator-panel
  • 登录访问grafana
http://hostip:3000/login
# 默认:admin:admin

安装influxdb

mkdir /data/influxdb
docker run -d --name=influxdb -p 8083:8083 -p 8086:8086 -v /data/influxdb/influxdb.conf:/etc/influxdb/influxdb.conf:ro -v /data/influxdb:/var/lib/influxdb influxdb -config /etc/influxdb/influxdb.conf
  • 创建influxdb用户和数据库
# docker exec -it 7a717ccf97e1 /bin/bash
root@7a717ccf97e1:/# influx
Connected to http://localhost:8086 version 1.7.7
InfluxDB shell version: 1.7.7
> create user "telegraf" with password 'password'
> show users;
user     admin
----     -----
telegraf false
> create database telegraf
> show databases;
name: databases
name
----
_internal
telegraf
> exit

安装telegraf

mkdir /data/telegraf
docker run --rm telegraf telegraf config > /data/telegraf/telegraf.conf
docker run -d --name telegraf -v /data/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro telegraf -config /etc/telegraf/telegraf.conf
  • 配置telegraf.conf
# 参照更改
[[outputs.influxdb]]
  urls = ["http://hostip:8086"]

  database = "telegraf"

  retention_policy = ""

  write_consistency = "any"

  timeout = "5s"

  username = "telegraf"
  password = "password"
  • telegrafa连接influxdb成功显示如下
2019-08-30T00:25:48Z I! Starting Telegraf 1.11.5
2019-08-30T00:25:48Z I! Loaded inputs: mem processes swap system cpu disk diskio kernel
2019-08-30T00:25:48Z I! Loaded aggregators: 
2019-08-30T00:25:48Z I! Loaded processors: 
2019-08-30T00:25:48Z I! Loaded outputs: influxdb
2019-08-30T00:25:48Z I! Tags enabled: host=f0aa64ca61d8
2019-08-30T00:25:48Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"f0aa64ca61d8", Flush Interval:10s

grafana配置influxdb datasource

相关推荐