|
1 | 1 | classdef InfluxDB < handle
|
2 | 2 |
|
3 | 3 | properties(Access = private)
|
4 |
| - Host = '' |
| 4 | + Url = '' |
5 | 5 | User = ''
|
6 | 6 | Password = ''
|
7 | 7 | Database = ''
|
|
11 | 11 |
|
12 | 12 | methods
|
13 | 13 | % Constructor
|
14 |
| - function obj = InfluxDB(host, user, password, database) |
15 |
| - obj.Host = host; |
| 14 | + function obj = InfluxDB(url, user, password, database) |
| 15 | + obj.Url = url; |
16 | 16 | obj.User = user;
|
17 | 17 | obj.Password = password;
|
18 | 18 | obj.Database = database;
|
|
32 | 32 | function [ok, millis] = ping(obj)
|
33 | 33 | try
|
34 | 34 | timer = tic;
|
35 |
| - webread([obj.Host '/ping']); |
| 35 | + webread([obj.Url '/ping']); |
36 | 36 | millis = toc(timer) * 1000;
|
37 | 37 | ok = true;
|
38 | 38 | catch
|
|
43 | 43 |
|
44 | 44 | % Show databases
|
45 | 45 | function databases = databases(obj)
|
46 |
| - url = [obj.Host '/query']; |
| 46 | + url = [obj.Url '/query']; |
47 | 47 | opts = weboptions('Timeout', obj.ReadTimeout, ...
|
48 | 48 | 'Username', obj.User, 'Password', obj.Password);
|
49 | 49 | response = webread(url, 'q', 'SHOW DATABASES', opts);
|
|
57 | 57 |
|
58 | 58 | % Execute a query string
|
59 | 59 | function result = runQuery(obj, query)
|
60 |
| - url = [obj.Host '/query']; |
| 60 | + url = [obj.Url '/query']; |
61 | 61 | opts = weboptions('Timeout', obj.ReadTimeout, ...
|
62 | 62 | 'Username', obj.User, 'Password', obj.Password);
|
63 | 63 | response = webread(url, 'db', obj.Database, 'epoch', 'ms', 'q', query, opts);
|
|
96 | 96 | 'consistency:unknown', '"%s" is not a valid consistency', consistency);
|
97 | 97 | params{end + 1} = ['consistency=' consistency];
|
98 | 98 | end
|
99 |
| - url = [obj.Host '/write?' strjoin(params, '&')]; |
| 99 | + url = [obj.Url '/write?' strjoin(params, '&')]; |
100 | 100 | weboptions('Timeout', obj.WriteTimeout, ...
|
101 | 101 | 'Username', obj.User, 'Password', obj.Password);
|
102 | 102 | webwrite(url, lines, opts);
|
|
0 commit comments