zoukankan      html  css  js  c++  java
  • influxdb 端口、数据结构、写数据

    InfluxDB 是一个开源,分布式,时间序列,事件,可度量和无外部依赖的数据库。

    InfluxDB有三大特性:

    1. Time Series (时间序列):你可以使用与时间有关的相关函数(如最大,最小,求和等)
    2. Metrics(度量):你可以实时对大量数据进行计算
    3. Events(事件):它支持任意的事件数据

    端口暴露

    influxdb会监听4个端口:

    tcp        0      0 0.0.0.0:8099                0.0.0.0:*                   LISTEN      29458/influxdb
    tcp        0      0 0.0.0.0:8083                0.0.0.0:*                   LISTEN      29458/influxdb
    tcp        0      0 0.0.0.0:8086                0.0.0.0:*                   LISTEN      29458/influxdb
    tcp        0      0 0.0.0.0:8090                0.0.0.0:*                   LISTEN      29458/influxdb

    其中单机使用只需要用到两个,另外两个是分布式部署时采用的

    • 8083  WEB 管理界面
    • 8086 HTTP API 接口服务

    数据结构

    在 influxdb 中 database 、 series、point 分别类似于数据库系统中的 数据库、表、列的概念。

    所有的数据项在创建时都会自动增加两个字段:

    • time 数据创建的时间,时间戳类型
    • sequence_number 字段是 influxdb 数据库维护的,类似于mysql的 主键概念。

    比如我们用下面数据创建一个 Series

    image

    他就会产生下面数据格式的数据存储:

    image

    这里可以看到,系统自动增加了2个字段: time 和 sequence_number 。

    接口协议

    InfluxDB 支持两种api方式:

    • HTTP API ,已经提供
    • Protobuf API, 计划提供

    如何使用 http api 进行操作?

    比如对于foo_production这个数据库,插入一系列数据,可以发现POST 请求到 /db/foo_production/series?u=some_user&p=some_password, 数据放到body里。

    数据看起来是这样的:

    下面的"name": "events", 其中"events"就是一个series,类似关系型数据库的表table

    [
      {
        "name": "events",
        "columns": ["state", "email", "type"],
        "points": [
          ["ny", "paul@influxdb.org", "follow"],
          ["ny", "todd@influxdb.org", "open"]
        ]
      },
      {
        "name": "errors",
        "columns": ["class", "file", "user", "severity"],
        "points": [
          ["DivideByZero", "example.py", "someguy@influxdb.org", "fatal"]
        ]
      }
    ]
    

    格式是json,可以在一个POST请求发送多个 series, 每个 series 里的 points 可以是多个,但索引要和columns对应。

    上面的数据里没有包含time 列,InfluxDB会自己加上,不过也可以指定time,比如:

    [
      {
        "name": "response_times",
        "columns": ["time", "value"],
        "points": [
          [1382819388, 234.3],
          [1382819389, 120.1],
          [1382819380, 340.9]
        ]
      }
    ]
    

    time 在InfluxDB里是很重要的,毕竟InfluxDB是time series database
    在InfluxDB里还有个sequence_number字段是数据库维护的,类似于mysql的 主键概念

    当然 sequence_number 也是可以指定的,类似如下:

    [
      {
        "name": "log_lines",
        "columns": ["time", "sequence_number", "line"],
        "points": [
          [1400425947368, 1, "this line is first"],
          [1400425947368, 2, "and this is second"]
        ]
      }
    ]
    http://influxdb.com/docs/v0.8/api/reading_and_writing_data.html
     

    InfluxDB 增删更查都是用http api来完成,甚至支持使用正则表达式删除数据,还有计划任务。

    比如:

    发送POST请求到 /db/:name/scheduled_deletes, body如下,

    {
      "regex": "stats..*",
      "olderThan": "14d",
      "runAt": 3
    }
    

    这个查询会删除大于14天的数据,并且任何以stats开头的数据,并且每天3:00 AM运行。

    参考资料:

    InfluxDB 开源分布式时序、事件和指标数据库
    http://segmentfault.com/blog/lds/1190000000444617

    开源监控利器grafana
    http://www.cnblogs.com/txwsqk/p/3974915.html

  • 相关阅读:
    SQL创建的几种存储过程
    关于freemaker的一点使用技巧
    freemaker时间格式转换,精确到毫秒
    递归算法
    网易开发工程师编程题 比较重量 Java
    JavaScript tasks, microtasks, queues and schedules
    1000分以下局目标
    Lua简介
    浅谈Wireshark的基本操作
    adb操作
  • 原文地址:https://www.cnblogs.com/ghj1976/p/4095073.html
Copyright © 2011-2022 走看看