1、安装influxdb数据库
docker run -d --name influxdb -p 8083:8083 -p 8086:8086 tutum/influxdb
两个端口都要映射出来,同时要开启防火墙端口
web http://192.168.199.151:8083/进入8083端口,创建数据库cadvisor
创建管理员admin密码123456的用户
好像最新的这个influxdb的docker数据库是放在容器里的/data里
docker run -d --name=cadvisor -p 8082:8080 -v /:/rootfs,ro -v /var/run:/var/run -v /sys:/sys,ro -v /var/lib/docker/:/var/lib/docker,ro google/cadvisor -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_host=influxdb:8086
上面这个应该有问题,应该host=influxdb:8086修改成下面的地址才对
docker run -d --name=cadvisor -p 8082:8080 -v /:/rootfs,ro -v /var/run:/var/run -v /sys:/sys,ro -v /var/lib/docker/:/var/lib/docker,ro --privileged=true google/cadvisor -storage_driver=influxdb -storage_driver_db=cadvisor -storage_driver_user=admin -storage_driver_password=123456 -storage_driver_host=192.168.199.151:8086 [root@localhost ~]# docker logs cadvisor W0730 02:50:08.190941 1 info.go:53] Couldn't collect info from any of the files in "/etc/machine-id,/var/lib/dbus/machine-id" W0730 02:50:08.208530 1 manager.go:349] Could not configure a source for OOM detection, disabling OOM events: open /dev/kmsg: no such file or directory
出现上面的错误了,但好像不影响相应的监控数据等功能
在influxdb 没有看到相关数据表,可以看到,要选择里面的cadvisor,但grafana却可以选择相应的数据同时显示出来
http://192.168.199.151:8082/docker/ 可以看容器的相关信息 ,但好像不能看到相关容器信息,只能看到主机相关信息
目前上面的这个办法有问题,暂时只能先放弃了
2、安装telegraf来进行监控
docker pull telegraf
再生成一个配置文件
docker run --rm telegraf telegraf config > telegraf.conf
需要对telegraf.conf进行相关监控配置
要监控docker 需要
[[inputs.docker]] endpoint = "unix:///var/run/docker.sock" container_names = [] container_name_include = [] container_name_exclude = [] timeout = "5s" perdevice = true total = false tag_env = ["JAVA_HOME", "HEAP_SIZE"] docker_label_include = [] docker_label_exclude = [] 上面的input要注释掉 要监控mysql要 # # Read metrics from one or many mysql servers [[inputs.mysql]] # ## specify servers via a url matching: # ## [username[:password]@][protocol[(address)]]/[?tls=[true|false|skip-verify|custom]] # ## see https://github.com/go-sql-driver/mysql#dsn-data-source-name # ## e.g. # ## servers = ["user:passwd@tcp(127.0.0.1:3306)/?tls=false"] # ## servers = ["user@tcp(127.0.0.1:3306)/?tls=false"] # # # ## If no servers are specified, then localhost is used as the host. servers = ["tcp(192.168.199.151:3306)/"] # # ## Selects the metric output format. # ## # ## This option exists to maintain backwards compatibility, if you have # ## existing metrics do not set or change this value until you are ready to # ## migrate to the new format. # ## # ## If you do not have existing metrics from this plugin set to the latest # ## version. # ## # ## Telegraf >=1.6: metric_version = 2 # ## metric_version = 2 # # ## the limits for metrics form perf_events_statements perf_events_statements_digest_text_limit = 120 perf_events_statements_limit = 250 perf_events_statements_time_limit = 86400 # # # ## if the list is empty, then metrics are gathered from all databasee tables table_schema_databases = [] # # # ## gather metrics from INFORMATION_SCHEMA.TABLES for databases provided above list gather_table_schema = false # # # ## gather thread state counts from INFORMATION_SCHEMA.PROCESSLIST gather_process_list = true # # # ## gather user statistics from INFORMATION_SCHEMA.USER_STATISTICS gather_user_statistics = true # # # ## gather auto_increment columns and max values from information schema gather_info_schema_auto_inc = true # # # ## gather metrics from INFORMATION_SCHEMA.INNODB_METRICS gather_innodb_metrics = true # # # ## gather metrics from SHOW SLAVE STATUS command output gather_slave_status = true # # # ## gather metrics from SHOW BINARY LOGS command output gather_binary_logs = false # # # ## gather metrics from PERFORMANCE_SCHEMA.TABLE_IO_WAITS_SUMMARY_BY_TABLE gather_table_io_waits = false # # # ## gather metrics from PERFORMANCE_SCHEMA.TABLE_LOCK_WAITS gather_table_lock_waits = false # # # ## gather metrics from PERFORMANCE_SCHEMA.TABLE_IO_WAITS_SUMMARY_BY_INDEX_USAGE gather_index_io_waits = false # # # ## gather metrics from PERFORMANCE_SCHEMA.EVENT_WAITS gather_event_waits = false # # # ## gather metrics from PERFORMANCE_SCHEMA.FILE_SUMMARY_BY_EVENT_NAME gather_file_events_stats = false # # # ## gather metrics from PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_SUMMARY_BY_DIGEST gather_perf_events_statements = false # # # ## Some queries we may want to run less often (such as SHOW GLOBAL VARIABLES) interval_slow = "30m" # # ## Optional TLS Config (will be used if tls=custom parameter specified in server uri) # # tls_ca = "/etc/telegraf/ca.pem" # # tls_cert = "/etc/telegraf/cert.pem" # # tls_key = "/etc/telegraf/key.pem" # ## Use TLS but skip chain & host verification # # insecure_skip_verify = false
要监控redis
# # Read metrics from one or many redis servers [[inputs.redis]] # ## specify servers via a url matching: # ## [protocol://][:password]@address[:port] # ## e.g. # ## tcp://localhost:6379 # ## tcp://:password@192.168.99.100 # ## unix:///var/run/redis.sock # ## # ## If no servers are specified, then localhost is used as the host. # ## If no port is specified, 6379 is used servers = ["tcp://192.168.199.151:6379"] # # ## specify server password password = "masterredis"
监控influxdb
# # Read InfluxDB-formatted JSON metrics from one or more HTTP endpoints [[inputs.influxdb]] # ## Works with InfluxDB debug endpoints out of the box, # ## but other services can use this format too. # ## See the influxdb plugin's README for more details. # # ## Multiple URLs from which to read InfluxDB-formatted JSON # ## Default is "http://localhost:8086/debug/vars". urls = [ "http://192.168.199.151:8086/debug/vars" ] # # ## Optional TLS Config # # tls_ca = "/etc/telegraf/ca.pem" # # tls_cert = "/etc/telegraf/cert.pem" # # tls_key = "/etc/telegraf/key.pem" # ## Use TLS but skip chain & host verification # # insecure_skip_verify = false # # ## http request & header timeout timeout = "5s"
对于输出到influxdb需要配置
[[outputs.influxdb]] urls = ["http://192.168.199.151:8086"] database = "telegraf" username = "admin" password = "123456" docker run -d --name=telegraf -v /root/telegraf/telegraf.conf:/etc/telegraf/telegraf.conf -v /var/run:/var/run telegraf
查询telegraf数据库的表"docker_container_cpu
SELECT * FROM "telegraf".."docker_container_cpu" LIMIT 100 docker run -d --name grafana -p 3000:3000 grafana/grafana
登录grafana后admin密码修改成XXXXXX
通过docker exec -it grafana bash进入grafana
安装饼图插件
grafana-cli plugins install grafana-piechart-panel
安装好后重新docker restart grafana
firewall-cmd --add-port=3000/tcp --permanent firewall-cmd --add-port=8082/tcp --permanent firewall-cmd --add-port=8083/tcp --permanent firewall-cmd --add-port=8086/tcp --permanent firewall-cmd --reload
3、效果图