0


Docker监控方案(TIG)的研究与实践之Influxdb

Docker监控方案(TIG)的研究与实践之Influxdb

目录


本文章向大家介绍Docker监控方案(TIG)的研究与实践之Influxdb,主要内容包括前言:、Influxdb研究与实践:、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

前言:

Influxdb也是有influxdata公司(www.influxdata.com )开发的用于数据存储的时间序列数据库.可用于数据的时间排列。在整个TIG(Telegraf+influxdb+grafana)方案中,influxdb可算作一个中间件,主要负责原始数据的存储,并按照时间序列进行索引构建以提供时间序列查询接口。在整个TIG方案中,应该先构建的就是Influxdb。

Influxdb研究与实践:

influxdb介绍:

使用TSM(Time Structured Merge)存储引擎,允许高摄取速度和数据压缩; 使用go编写,无需其他依赖; 简单,高性能写查询httpAPI接口; 支持其他数据获取协议的插件,比如graphite,collected,OpenTSDB; 使用relay构建高可用https://docs.influxdata.com/influxdb/v1.0/high_availability/relay/; 扩展的类sql语言,很容易查询汇总数据; tag的支持,可用让查询变的更加高效和快速; 保留策略有效地自动淘汰过期的数据; 持续所产生的自动计算的数据会使得频繁的查询更加高效; web管理页面的支持

下载安装:

github:GitHub - influxdata/influxdb: Scalable datastore for metrics, events, and real-time analytics 源码编译 官网下载: Centos系列:wgethttps://dl.influxdata.com/influxdb/releases/influxdb-1.0.0.x86_64.rpm && sudo yum localinstall influxdb-1.0.0.x86_64.rpm 源码包系列:wgethttps://dl.influxdata.com/influxdb/releases/influxdb-1.0.0_linux_amd64.tar.gz && tar xvfz influxdb-1.0.0_linux_amd64.tar.gz docker系列:docker pull influxdb 安装手册:https://docs.influxdata.com/influxdb/v0.9/introduction/installation/

配置:

  1. #cat /etc/influxdb/influxdb.conf
  2. reporting-disabled = false
  3. [registration]
  4. [meta]
  5. dir = "/var/lib/influxdb/meta"
  6. hostname = "10.0.0.2" #此hostname必须写本机,否则无法连接到数据操作的API
  7. bind-address = ":8088"
  8. retention-autocreate = true
  9. election-timeout = "1s"
  10. heartbeat-timeout = "1s"
  11. leader-lease-timeout = "500ms"
  12. commit-timeout = "50ms"
  13. cluster-tracing = false
  14. [data]
  15. dir = "/var/lib/influxdb/data"
  16. max-wal-size = 104857600 # Maximum size the WAL can reach before a flush. Defaults to 100MB.
  17. wal-flush-interval = "10m" # Maximum time data can sit in WAL before a flush.
  18. wal-partition-flush-delay = "2s" # The delay time between each WAL partition being flushed.
  19. wal-dir = "/var/lib/influxdb/wal"
  20. wal-logging-enabled = true
  21. [hinted-handoff]
  22. enabled = true
  23. dir = "/var/lib/influxdb/hh"
  24. max-size = 1073741824
  25. max-age = "168h"
  26. retry-rate-limit = 0
  27. retry-interval = "1s"
  28. retry-max-interval = "1m"
  29. purge-interval = "1h"
  30. [admin]
  31. enabled = true
  32. bind-address = ":8083"
  33. https-enabled = false
  34. https-certificate = "/etc/ssl/influxdb.pem"
  35. [http]
  36. enabled = true
  37. bind-address = ":8086"
  38. auth-enabled = false
  39. log-enabled = true
  40. write-tracing = false
  41. pprof-enabled = false
  42. https-enabled = false
  43. https-certificate = "/etc/ssl/influxdb.pem"
  44. [opentsdb]
  45. enabled = false
  46. [collectd]
  47. enabled = false
  1. 注意:

influxdb服务会启动三个端口:8086为服务的默认数据处理端口,主要用来influxdb数据库的相关操作,可提供相关的API;8083为管理员提供了一个可视化的web界面,用来为用户提供友好的可视化查询与数据管理;8088主要为了元数据的管理。需要注意的是,influxdb默认是需要influxdb用户启动,且数据存放在/var/lib/influxdb/下面,生产环境需要注意这个。

启动:

和telegraf启动方式一样,可以使用init.d或者systemd进行管理influxdb

  1. 注意,启动之后需要查看相关的端口是否正在监听,并检查日志确保服务正常启动

使用:

如果说使用telegraf最核心的部分在配置,那么influxdb最核心的就是SQL语言的使用了。influxdb默认支持三种操作方式: 登录influxdb的shell中操作:

  1. 创建数据库:
  2. create database mydb
  3. 创建用户:
  4. create user "bigdata" with password 'bigdata' with all privileges
  5. 查看数据库:
  6. show databases;
  7. 数据插入:
  8. insert bigdata,host=server001,regin=HC load=88
  9. 切换数据库:
  10. use mydb
  11. 查看数据库中有哪些measurement(类似数据库中的表):
  12. show measurements
  13. 查询:
  14. select * from cpu limit 2
  15. 查询一小时前开始到现在结束的:
  16. #select load from cpu where time > now() - 1h
  17. 查询从历史纪元开始到1000天之间:
  18. #select load from cpu where time < now() + 1000d
  19. 查找一个时间区间:
  20. #select load from cpu where time > '2016-08-18' and time < '2016-09-19'
  21. 查询一个小时间区间的数据,比如在September 18, 2016 21:24:00:后的6分钟:
  22. #select load from cpu where time > '2016-09-18T21:24:00Z' +6m
  23. 使用正则查询所有measurement的数据:
  24. #select * from /.*/ limit 1
  25. #select * from /^docker/ limit 3
  26. #select * from /.*mem.*/ limit 3
  27. 正则匹配加指定tag:(=~ !~)
  28. #select * from cpu where "host" !~ /.*HC.*/ limit 4
  29. #SELECT * FROM "h2o_feet" WHERE ("location" =~ /.*y.*/ OR "location" =~ /.*m.*/) AND "water_level" > 0 LIMIT 4
  30. 排序:group by的用法必须得是在复合函数中进行使用
  31. #select count(type) from events group by time(10s)
  32. #select count(type) from events group by time(10s),type
  33. 给查询字段做tag
  34. #select count(type) as number_of_types group by time(10m)
  35. #select count(type) from events group by time(1h) where time > now() - 3h
  36. 使用fill字段:
  37. #select count(type) from events group by time(1h) fill(0)/fill(-1)/fill(null) where time > now() - 3h
  38. 数据聚合:
  39. select count(type) from user_events merge admin_events group by time(10m)

使用API进行操作数据:

  1. 创建数据库:
  2. curl -G "http://localhost:8086/query" --data-urlencode "q=create database mydb"
  3. 插入数据:
  4. curl -XPOST 'http://localhost:8086/write?db=mydb' -d 'biaoge,name=xxbandy,xingqu=coding age=2'
  5. curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
  6. curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server02 value=0.67
  7. cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257
  8. cpu_load_short,direction=in,host=server01,region=us-west value=2.0 1422568543702900257'
  9. sql语句写入文件,并通过api插入:
  10. #cat sql.txt
  11. cpu_load_short,host=server02 value=0.67
  12. cpu_load_short,host=server02,region=us-west value=0.55 1422568543702900257
  13. cpu_load_short,direction=in,host=server01,region=us-west value=2.0 1422568543702900257
  14. #curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary @cpu_data.txt
  15. 查询数据:(--data-urlencode "epoch=s" 指定时间序列 "chunk_size=20000" 指定查询块大小)
  16. # curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=ydb" --data-urlencode "q=select * from biaoge where xingqu='coding'"
  17. 数据分析:
  18. #curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=mydb" --data-urlencode "q=select mean(load) from cpu"
  19. #curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=mydb" --data-urlencode "q=select load from cpu"
  20. 可以看到load的值分别是42 78 15.4;用mean(load)求出来的值为45,13
  21. curl -G http://localhost:8086/query?pretty=true --data-urlencode "db=ydb" --data-urlencode "q=select mean(load) from cpu where host='server01'"

使用influxdb提供的web界面进行操作:

这里只是简单的介绍了influxdb的使用,后期如果想在grafana中汇聚并完美地展示数据,可能需要熟悉influxdb的各种查询语法。(其实就是sql语句的一些使用技巧,聚合函数的使用,子查询等等)

标签: docker 容器 运维

本文转载自: https://blog.csdn.net/2301_78835635/article/details/133952337
版权归原作者 太极-彼岸 所有, 如有侵权,请联系我们删除。

“Docker监控方案(TIG)的研究与实践之Influxdb”的评论:

还没有评论