在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):EnricSala/influxdb-matlab开源软件地址(OpenSource Url):https://github.com/EnricSala/influxdb-matlab开源编程语言(OpenSource Language):MATLAB 99.9%开源软件介绍(OpenSource Introduction):InfluxDB MATLABThis is a MATLAB client library for interacting with InfluxDB. The library has been tested with Earlier versions of InfluxDB or MATLAB may also work but have not been tested. InstallationClone or download the repository and add the % Add the library to the path
addpath('path/to/influxdb-client'); UsageCreate 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 dataUse the % 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 dataThe 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 Other commandsUse % 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. ContributingFeedback or contributions are welcome! Please create an issue to discuss it first :) License
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论