InfluxDB和Grafana

时序数据库InfluxDB使用简单说明和Grafana可视化套件

开发环境:Windows10 教育版 1903

image.png

InfluxDB

InfluxDB版本:1.7.7

安装方法:解压运行即可

influx
influxd

修改配置文件influxdb.conf,打开用户验证,部分配置文件如下

[http]
  # Determines whether HTTP endpoint is enabled.
  enabled = true

  # Determines whether the Flux query endpoint is enabled.
  # flux-enabled = false

  # Determines whether the Flux query logging is enabled.
  # flux-log-enabled = false

  # The bind address used by the HTTP service.
  bind-address = ":8086"

  # Determines whether user authentication is enabled over HTTP/HTTPS.
  auth-enabled = true

  # The default realm sent back when issuing a basic auth challenge.
  # realm = "InfluxDB"

  # Determines whether HTTP request logging is enabled.
  log-enabled = true

  # Determines whether the HTTP write request logs should be suppressed when the log is enabled.
  # suppress-write-log = false

  # When HTTP request logging is enabled, this option specifies the path where
  # log entries should be written. If unspecified, the default is to write to stderr, which
  # intermingles HTTP logs with internal InfluxDB logging.
  #
  # If influxd is unable to access the specified path, it will log an error and fall back to writing
  # the request log to stderr.
  # access-log-path = ""

  # Filters which requests should be logged. Each filter is of the pattern NNN, NNX, or NXX where N is
  # a number and X is a wildcard for any number. To filter all 5xx responses, use the string 5xx.
  # If multiple filters are used, then only one has to match. The default is to have no filters which
  # will cause every request to be printed.
  # access-log-status-filters = []

  # Determines whether detailed write logging is enabled.
  write-tracing = false

  # Determines whether the pprof endpoint is enabled.  This endpoint is used for
  # troubleshooting and monitoring.
  pprof-enabled = false

  # Enables a pprof endpoint that binds to localhost:6060 immediately on startup.
  # This is only needed to debug startup issues.
  # debug-pprof-enabled = false

  # Determines whether HTTPS is enabled.
  https-enabled = false

  # The SSL certificate to use when HTTPS is enabled.
  # https-certificate = "/etc/ssl/influxdb.pem"

  # Use a separate private key location.
  # https-private-key = ""

  # The JWT auth shared secret to validate requests using JSON web tokens.
  # shared-secret = ""

  # The default chunk size for result sets that should be chunked.
  # max-row-limit = 0

  # The maximum number of HTTP connections that may be open at once.  New connections that
  # would exceed this limit are dropped.  Setting this value to 0 disables the limit.
  # max-connection-limit = 0

  # Enable http service over unix domain socket
  # unix-socket-enabled = false

  # The path of the unix domain socket.
  # bind-socket = "/var/run/influxdb.sock"

  # The maximum size of a client request body, in bytes. Setting this value to 0 disables the limit.
  # max-body-size = 25000000

  # The maximum number of writes processed concurrently.
  # Setting this to 0 disables the limit.
  # max-concurrent-write-limit = 0

  # The maximum number of writes queued for processing.
  # Setting this to 0 disables the limit.
  # max-enqueued-write-limit = 0

  # The maximum duration for a write to wait in the queue to be processed.
  # Setting this to 0 or setting max-concurrent-write-limit to 0 disables the limit.
  # enqueued-write-timeout = 0

http标签下的 auth-enabled 选项值改为 true

InfluxDB从1.2之后没有集成web客户端,所以可以使用其他工具进行访问,或者直接CMD

部分操作

  • 展现所有用户
show users
  • 创建用户
create user ccwith password 'cc'
  • 赋权

    GRANT ALL PRIVILEGES TO cc
    
  • 修改用户(密码)

    SET PASSWORD FOR cc= ‘cc‘
    
  • 删除用户

    DROP USER cc
    
  • 撤消权限

    REVOKE ALL  ON  mydb   FROM admin
    
  • 查看权限

    SHOW GRANTS FOR admin
    
  • 删除表

    drop measurement disk_free
    
  • 删除数据库

    drop database testdb
    
  • 数据插入

    insert disk_free,hostname=server01 value=442221834240   1435362189575692182
    #1435362189575692182就是一个时间戳
    
  • 显示Tag的Key

    show tag keys
    
  • 显示数据字段的Key

    show field keys
    

可能存在的问题

Java环境的集成

时间数据的精度问题

数据的删除问题

数据太多时候的写入超时问题

设计准测

  • 把你经常查询的字段作为tag

  • 如果你要对其使用GROUP BY(),也要放在tag

  • 如果你要对其使用InfluxQL函数,则将其放到field

  • 如果你需要存储的值不是字符串,则需要放到field中,因为tag value只能是字符串

  • 不要有太多的series

    tags包含高度可变的信息,如UUID,哈希值和随机字符串,这将导致数据库中的大量measurement,通俗地说是高series cardinality。series cardinality高是许多数据库高内存使用的主要原因。

参考资料

InfluxDB中文文档

饿了么 Influxdb 实践之路

InfluxDB使用教程:InfluxDB中数据结构概念

时序数据库 InfluxDB 2.0 alpha 发布:主推新的 Flux 查询语言,TICK 栈将成为整体


Grafana

Grafana版本:6.2.5

安装配置

安装方法:

  • 下载grafana-6.2.5.windows-amd64.msi安装文件

  • 执行默认安装

  • 新增custom.ini配置文件

    • 复制sample.ini

    • 修改增加port设置

      http_port=9000
      
  • 管理员方式启动grafana-server.exe

    注意此步如果安装位置在C盘,建议使用管理员方式进行启动。不然下一步登陆可能出现报错信息

  • 使用网页访问,修改密码

    • 访问地址:http://localhost:9000

      其中端口号由之前的配置文件进行设置

  • 配置InfluxDB

    • InfluxDB需要创建用户

    • 结果如下图所示

    image.png

参考资料

可视化工具Grafana:在windows上安装和运行

Using InfluxDB in Grafana,influxDB在grafana中使用

Grafana快速入门:InfluxDB数据源以及曲线图表仪表盘配置

你可能感兴趣的:(InfluxDB和Grafana)