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',
      }
    },

請輸入圖片描述

相關文章
相關標籤/搜索