InfluxDB 开源分布式时序、事件和指标数据库

InfluxDB 是一个开源分布式时序、事件和指标数据库。使用 Go 语言编写,无需外部依赖。其设计目标是实现分布式和水平伸缩扩展。html

特色

  • schemaless(无结构),能够是任意数量的列
  • Scalable
  • min, max, sum, count, mean, median 一系列函数,方便统计
  • Native HTTP API, 内置http支持,使用http读写
  • Powerful Query Language 相似sql
  • Built-in Explorer 自带管理工具

管理界面:mysql

请输入图片描述

API

InfluxDB 支持两种api方式ios

  • HTTP API
  • Protobuf API

Protobuf 还未开发完成, 官网文档都没有git

如何使用 http api 进行操做?github

好比对于foo_production这个数据库,插入一系列数据,能够发现POST 请求到 /db/foo_production/series?u=some_user&p=some_password, 数据放到body里。正则表达式

数据看起来是这样的:sql

下面的"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对应。json

上面的数据里没有包含time 列,InfluxDB会本身加上,不过也能够指定time,好比:segmentfault

[
  {
    "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的 主键概念

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

好比:

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

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

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

更加详细查看官方文档: http://influxdb.org/docs/api/http.html

查询语言

InfluxDB 提供了相似sql的查询语言

看起来是这样的:

select * from events where state == 'NY';

select * from log_lines where line =~ /error/i;

select * from events where customer_id == 23 and type == 'click';

select * from response_times where value > 500;

select * from events where email !~ /.*gmail.*/;

select * from nagios_checks where status != 0;

select * from events 
where (email =~ /.*gmail.* or email =~ /.*yahoo.*/) and state == 'ny';

delete from response_times where time > now() - 1h

很是容易上手, 还支持Group By, Merging Series, Joining Series, 并内置经常使用统计函数,好比max, min, mean 等

文档: http://influxdb.org/docs/query_language/

经常使用语言的库都有,由于api简单,也很容易本身封装。

InfluxdDB做为不少监控软件的后端,这样监控数据就能够直接存储在InfluxDB
StatsD, CollectD, FluentD

还有其它的可视化工具支持InfluxDB, 这样就能够基于InfluxDB很方便的搭建监控平台

InfluxDB 数据可视化工具

InfluxDB 用于存储基于时间的数据,好比监控数据,由于InfluxDB自己提供了Http API,因此可使用InfluxDB很方便的搭建了个监控数据存储中心。

对于InfluxDB中的数据展现,官方admin有很是简单的图表, 看起来是这样的

请输入图片描述

除了本身写程序展现数据还能够选择:

tasseo

tasseo,为Graphite写的Live dashboard,如今也支持InfluxDB,tasseo 比较简单, 能够配置的选项不多。

请输入图片描述

Grafana

Grafana是一个纯粹的html/js应用,访问InfluxDB时不会有跨域访问的限制。只要配置好数据源为InfluxDB以后就能够,剩下的工做就是配置图表。Grafana 功能很是强大。使用ElasticsSearch保存DashBoard的定义文件,也能够Export出JSON文件(Save ->Advanced->Export Schema),而后上传回它的/app/dashboards目录。

配置数据源:

datasources: {      
      influx: {
        default: true,
        type: 'influxdb',
        url: 'http://<your_influx_db_server>:8086/db/<db_name>',
        username: 'test',
        password: 'test',
      }
    },

请输入图片描述

相关文章
相关标签/搜索