• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

EnricSala/influxdb-matlab: MATLAB client for InfluxDB

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

EnricSala/influxdb-matlab

开源软件地址(OpenSource Url):

https://github.com/EnricSala/influxdb-matlab

开源编程语言(OpenSource Language):

MATLAB 99.9%

开源软件介绍(OpenSource Introduction):

InfluxDB MATLAB

This is a MATLAB client library for interacting with InfluxDB.

The library has been tested with InfluxDB 1.5 and MATLAB R2018a.

Earlier versions of InfluxDB or MATLAB may also work but have not been tested.

Installation

Clone or download the repository and add the influxdb-client directory to the path:

% Add the library to the path
addpath('path/to/influxdb-client');

Usage

Create an InfluxDB client instance and use it to interact with the server:

% Build an InfluxDB client
URL = 'http://localhost:8086';
USER = 'user';
PASS = 'password';
DATABASE = 'server_stats';
influxdb = InfluxDB(URL, USER, PASS, DATABASE);

% Check the status of the InfluxDB instance
[ok, ping] = influxdb.ping()

% Show the databases
dbs = influxdb.databases()

% Change the current database
influxdb.use('weather_stations');

If you plan on doing very large requests you may need to adjust the timeouts:

% Configure timeouts
influxdb.setReadTimeout(10);
influxdb.setWriteTimeout(10);

Writing data

Use the Series builder to prepare the data, then write it using the client:

% Create a series with a single sample
series1 = Series('weather') ...
    .tags('city', 'barcelona', 'country', 'catalonia') ...
    .fields('temperature', 24.3, 'humidity', 70.4) ...
    .time(datetime('today', 'TimeZone', 'local'));

% Create a series with many samples
series2 = Series('weather') ...
    .tags('city', 'copenhagen', 'country', 'denmark') ...
    .fields('temperature', [12.6; 11.8], 'humidity', [45.7; 46.3]) ...
    .time(datetime('now', 'TimeZone', 'local') - [0; 1] / 24);

% Create a series from an existing timetable
series3 = Series('weather') ...
    .tags('city', 'helsinki', 'country', 'finland') ...
    .import(my_timetable);

% Create an array of series
series_array = [series4, series5, etc];

% Save all the series in a batch
influxdb.writer() ...
    .append(series1, series2, series3) ...
    .append(series_array) ...
    .execute();

The parameters of a write request can optionally be customized as follows:

% Customize a write request
influxdb.writer() ...
    .database('another_database') ...
    .precision('ms') ...
    .retention('two_weeks') ...
    .consistency('quorum') ...
    .append(series, etc) ...
    .execute();

Querying data

The client supports reading data from InfluxDB using query strings:

% Manually written query
str = 'SELECT temperature FROM weather WHERE humidity > 60 LIMIT 100';
result = influxdb.runQuery(str);

Additionally, a query builder is provided to help generate them:

% Dynamically generated query
result = influxdb.query('weather') ...
    .fields('temperature', 'humidity') ...
    .tags('city', 'barcelona') ...
    .tagsLike('station', '^(foo|bar)[0-9]{3}') ...
    .before(datetime('today', 'TimeZone', 'local')) ...
    .after(datetime('2018-01-01', 'TimeZone', 'local')) ...
    .where('temperature > 20 AND humidity > 60') ...
    .execute();

% Another example with more options
result = influxdb.query('weather') ...
    .fields('mean(temperature)', 'sum(rain)') ...
    .groupByTags('country', 'city') ...
    .groupByTime('3h', 'linear') ...
    .limit(100) ...
    .execute();

The parameters of a query request can optionally be customized as follows:

% Customize a query request
result = influxdb.query('weather') ...
    .database('another_database') ...
    .epoch('m') ...
    .execute();

The result of a query is an object that provides additional functionalities:

% Check which series are present in a result
series_names = result.names()

% Get series with matching name
weather = result.series('weather')

% When grouping by tags, get series with matching tags
weather_bcn = result.series('weather', 'city', 'barcelona')
weather_cph = result.series('weather', 'city', 'copenhagen')

% Check which fields are present in a series
field_names = weather.fields()

% Plot a field
time = weather.time('Europe/Amsterdam');
temperature = weather.field('temperature');
plot(time, temperature);

% Convert a series to a table or timetable
mytable = weather.table();
mytable = weather.timetable('Europe/Paris');

Notice that the time() and timetable() methods take an optional timezone argument.

Other commands

Use runCommand(command, [database], [requiresPost]) for executing arbitrary commands:

% Show databases then create one
influxdb.runCommand('SHOW DATABASES')
influxdb.runCommand('CREATE DATABASE "example"', true)

% Show measurements and tag keys
influxdb.runCommand('SHOW MEASUREMENTS', 'example')
influxdb.runCommand('SHOW TAG KEYS', 'example')

% Create a retention policy that keeps data for one day
influxdb.runCommand('CREATE RETENTION POLICY "one_day" ON "example" DURATION 1d REPLICATION 1', true)

% Convert a command result to a table
result = influxdb.runCommand('SHOW RETENTION POLICIES', 'example')
policies = result.series().table()

See the InfluxDB documentation for more schema exploration and management commands.

Contributing

Feedback or contributions are welcome!

Please create an issue to discuss it first :)

License

MIT License

Copyright (c) 2018 Enric Sala

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap