iobroker.influxdb 5.3.1 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -300,13 +300,20 @@ SELECT mean("value") FROM "system.adapter.admin.0.memRss" WHERE $timeFilter GROU
300
300
 
301
301
  Most of these values can be pre-defined in the instance settings and are then pre-filled or used for the datapoint.
302
302
 
303
+ ## Messages for scripts and AI agents
304
+ `sendTo('influxdb.0', 'help', {})` answers `{help, commands}`: a description of all messages and of the measurement layout for AI agents (e.g. ioBroker.pi-agent) and script authors, and the list of all commands with `write: true` for the ones that change something.
305
+
306
+ `getHistory`, `aggregate` and `lastChange` are standard commands of the shared catalog of sendTo commands (family `history`, marked with `standard` in the answer of `help`), the same in history, sql, influxdb and recorder:
307
+ - `aggregate {id, start, end?, fn, value?}` answers one number for a period, `{value, ts?, unit?, count}`. `fn`: `min`, `max`, `avg`, `sum`, `count` (with `value`: how often the state became it), `delta` (how much a counter rose, resets included), `first`, `last`, `integral` (value × hours, W gives Wh), `duration` (with `value`: seconds the state had it).
308
+ - `lastChange {id, value?, before?}` answers when the state last changed (to `value`): `{ts, val}`.
309
+
303
310
  ## Access values from Javascript adapter
304
311
  The sorted values can be accessed from Javascript adapter.
305
312
 
306
- * Get 50 last stored events for all IDs
313
+ * Get the 50 last stored values of "system.adapter.admin.0.memRss" (InfluxDB keeps one measurement per state, so `id: '*'` for all IDs is not supported and answers an error)
307
314
  ```javascript
308
315
  sendTo('influxdb.0', 'getHistory', {
309
- id: '*',
316
+ id: 'system.adapter.admin.0.memRss',
310
317
  options: {
311
318
  end: Date.now(),
312
319
  count: 50,
@@ -495,7 +502,7 @@ Additionally, you can add attribute `rules: true` in a message to activate all r
495
502
  In case of errors, an array with all single error messages is returned and also a successCount to see how many entries were stored successfully.
496
503
 
497
504
  ## delete state
498
- If you want to delete entry from the Database, you can use the build in system function `delete`:
505
+ If you want to delete entry from the Database, you can use the build in system function `delete`. It deletes the values with exactly the given `ts`:
499
506
 
500
507
  ```javascript
501
508
  sendTo('influxdb.0', 'delete', [
@@ -504,6 +511,8 @@ sendTo('influxdb.0', 'delete', [
504
511
  ], result => console.log('deleted'));
505
512
  ```
506
513
 
514
+ A single entry can be sent without the list (`{id: 'mbus.0.counter.xxx', state: {ts: 1589458809352}}` or `{id: 'mbus.0.counter.xxx', ts: 1589458809352}`), several values of one data point as `{id: 'mbus.0.counter.xxx', ts: [1589458809352, 1589458809353]}`.
515
+
507
516
  To delete ALL history data for some data point execute:
508
517
 
509
518
  ```javascript
@@ -522,10 +531,16 @@ sendTo('influxdb.0', 'deleteRange', [
522
531
  ], result => console.log('deleted'));
523
532
  ```
524
533
 
525
- Time could be ms since epoch or ans string, that could be converted by javascript Date object.
534
+ A single range can be sent without the list: `{id: 'mbus.0.counter.xxx', start: 1589458809352, end: 1589458809353}`. `start` is required, `end` is optional and defaults to now.
535
+
536
+ Time could be ms since epoch or a string, that could be converted by javascript Date object. `0` is a valid time.
526
537
 
527
538
  Values will be deleted including defined limits. `ts >= start AND ts <= end`
528
539
 
540
+ Every entry needs a valid `ts` (one value) or a valid `start` (a range; `end` alone is not accepted). If one entry has neither, the adapter answers with `{success: false, error}` naming it and deletes nothing, not even the valid entries of the same message. To delete all values of a data point, use `deleteAll`.
541
+
542
+ InfluxDB 3 can only delete whole data points: there `delete` and `deleteRange` answer with an error, only `deleteAll` works.
543
+
529
544
  ## change state
530
545
  If you want to change entry's value, quality or acknowledge flag in the database, you can use the build in system function `update`:
531
546
 
@@ -721,6 +736,15 @@ sendTo('influxdb.0', 'cleanupOrphaned', {
721
736
  Placeholder for the next version (at the beginning of the line):
722
737
  ### **WORK IN PROGRESS**
723
738
  -->
739
+ ### 5.5.0 (2026-11-23)
740
+ * (GermanBluefox) Added the standard commands of the shared catalog: history.aggregate (one number for a period: min, max, avg, sum, count, delta, first, last, integral, duration) and history.lastChange; getHistory is marked as history.getHistory
741
+ * (GermanBluefox) Fixed: `getHistory` with `id: '*'` (or without ID) answers an error instead of an empty result. InfluxDB keeps one measurement per state and cannot read all states at once; the example in this README that used `'*'` reads one state now
742
+ * (GermanBluefox) Fixed: `getHistory` with an aggregate (e.g. average) and without `start` answers instead of failing with "Invalid time value" (the step was NaN). Like the sql and history adapters, it takes the newest `count` values and builds the intervals from them. An unparsable `start` or `end` is refused with "is not a valid date", a time stamp as text ("1700000000000") is accepted
743
+
744
+ ### 5.4.0 (2026-11-19)
745
+ * (GermanBluefox) Fixed: `delete` / `deleteRange` without a valid `ts` or range no longer deletes all values of the state. A single `{id, state: {start, end}}`, a state without `ts` or with `ts: 0` deleted everything (InfluxDB 1.x since 2000, 2.x since 1970, 3.x the whole table), an unparsable `start` everything up to `end`. Such a message is refused now with an error and nothing is deleted; `{id, state: {start, end}}` and `{id, start, end}` delete the range, `ts: 0` the value at 0
746
+ * (GermanBluefox) Added the message "help": a description of all messages for AI agents (e.g. pi-agent), and `common.supportedMessages.help`
747
+
724
748
  ### 5.3.1 (2026-11-17)
725
749
  * (GermanBluefox) Fixed: timed relog leaked timers and wrote the skipped value multiple times when a state was set twice in quick succession (#595)
726
750
  * (GermanBluefox) Data browser: the values of a datapoint can be exported as CSV (e.g. for Excel) or as JSON (the format of `storeState`) for the selected time range
@@ -735,12 +759,6 @@ sendTo('influxdb.0', 'cleanupOrphaned', {
735
759
  ### 5.2.2 (2026-10-27)
736
760
  * (GermanBluefox) The cleanup dialog of the statistics tab shows the oldest and the newest value of each datapoint and can preselect only datapoints whose last value is older than a given number of days, so measurements that scripts still write to stay untouched
737
761
 
738
- ### 5.2.0 (2026-10-24)
739
- * (GermanBluefox) The cleanup dialog of the statistics tab has checkboxes, so only the selected datapoints are deleted (#565)
740
-
741
- ### 5.1.8 (2026-10-23)
742
- * (@GermanBluefox) The timed relog (`changesRelogInterval`) starts right after the adapter start or a change of the datapoint settings, not only with the first update of the state
743
-
744
762
  [Older changelogs can be found there](CHANGELOG_OLD.md)
745
763
 
746
764
  ## License
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ /**
3
+ * Parsing and validation of the time stamps of `delete`, `deleteRange` and `update`.
4
+ *
5
+ * `ts`, `start` and `end` were taken as they came, and whatever was missing, 0 or not a date fell
6
+ * through to "delete every value of the datapoint": a single `{id, state: {start, end}}` or
7
+ * `{id, state: {}}` reached `_delete` as `{ts: undefined}`, an unparsable `start` became `NaN`. That
8
+ * deleted everything since 2000 on InfluxDB 1.x, everything since 1970 on 2.x and the whole table on
9
+ * 3.x. Every entry is checked here, and `_delete` refuses an invalid range itself as well.
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.toTimestamp = toTimestamp;
13
+ exports.deleteRangeProblem = deleteRangeProblem;
14
+ exports.parseDeleteRequests = parseDeleteRequests;
15
+ /** Largest distance from 1970 in ms a `Date` can hold */
16
+ const MAX_DATE_MS = 8.64e15;
17
+ function isTimestamp(value) {
18
+ return typeof value === 'number' && Number.isFinite(value) && Math.abs(value) <= MAX_DATE_MS;
19
+ }
20
+ /** A value for an error text: `NaN` and `undefined` are not readable as JSON */
21
+ function show(value) {
22
+ return typeof value === 'number' || value === undefined ? String(value) : JSON.stringify(value);
23
+ }
24
+ /**
25
+ * Time stamp in ms from a number, a numeric string, a date string or a `Date`.
26
+ *
27
+ * @param value the value of `ts`, `start` or `end` from the message
28
+ * @returns the time stamp, or `undefined` if the value is none. 0 is a valid time stamp.
29
+ */
30
+ function toTimestamp(value) {
31
+ let ts;
32
+ if (typeof value === 'number') {
33
+ ts = value;
34
+ }
35
+ else if (typeof value === 'string' && value.trim()) {
36
+ const text = value.trim();
37
+ // "1589458809352" is a number: `new Date()` would read it as a date and return NaN
38
+ ts = /^-?\d+(\.\d+)?$/.test(text) ? Number(text) : new Date(text).getTime();
39
+ }
40
+ else if (value instanceof Date) {
41
+ ts = value.getTime();
42
+ }
43
+ else {
44
+ return undefined;
45
+ }
46
+ return isTimestamp(ts) ? ts : undefined;
47
+ }
48
+ /**
49
+ * Why a range must not be deleted, or `null` if it is valid.
50
+ *
51
+ * The second line of defence in `_delete`: whatever a caller passes, a missing or invalid time stamp
52
+ * must never turn into deleting every value.
53
+ *
54
+ * @param range what the caller wants to delete
55
+ */
56
+ function deleteRangeProblem(range) {
57
+ if (!range || typeof range !== 'object') {
58
+ return 'neither "ts" nor a range given';
59
+ }
60
+ if (range.mode === 'one') {
61
+ return isTimestamp(range.ts) ? null : `invalid "ts" ${show(range.ts)}`;
62
+ }
63
+ if (range.mode === 'range') {
64
+ if (!isTimestamp(range.start)) {
65
+ return `invalid "start" ${show(range.start)}`;
66
+ }
67
+ return isTimestamp(range.end) ? null : `invalid "end" ${show(range.end)}`;
68
+ }
69
+ if (range.mode === 'all') {
70
+ return null;
71
+ }
72
+ return `unknown delete mode ${show(range.mode)}`;
73
+ }
74
+ /**
75
+ * Turn the message of `delete` or `deleteRange` into a list of requests.
76
+ *
77
+ * Both commands accept the same shapes: `{id, ts}`, `{id, start, end?}`, `{id, state: {ts}}`,
78
+ * `{id, state: {start, end?}}`, each also as a list, plus `{id, state: [...]}` and `{id, ts: [...]}`
79
+ * for several entries of one datapoint (a number in these lists is a `ts`). `ts` deletes the values
80
+ * with exactly this time stamp, `start` / `end` the values in `[start, end]`; `end` defaults to now,
81
+ * `end` without `start` is refused like in the history and sql adapters. Time stamps are ms or date
82
+ * strings, 0 is valid. An entry without ID, without `ts` or `start`, or with a value that is no time
83
+ * stamp is reported in `errors` and not returned in `requests`.
84
+ *
85
+ * @param message `msg.message` as delivered
86
+ * @param now the time stamp `end` defaults to
87
+ * @param resolveId maps an alias to the ID of the datapoint
88
+ */
89
+ function parseDeleteRequests(message, now, resolveId = id => id) {
90
+ const requests = [];
91
+ const errors = [];
92
+ const one = (id, entry) => {
93
+ if (typeof id !== 'string' || !id) {
94
+ errors.push(`No "id" given for ${show(entry)}`);
95
+ return;
96
+ }
97
+ // a plain value is a time stamp (`{id, ts: [1, 2]}`), an object carries ts or start/end
98
+ const spec = entry && typeof entry === 'object' ? entry : { ts: entry };
99
+ if (spec.ts !== undefined && spec.ts !== null) {
100
+ const ts = toTimestamp(spec.ts);
101
+ if (ts === undefined) {
102
+ errors.push(`Invalid "ts" ${show(spec.ts)} for ${id}`);
103
+ }
104
+ else {
105
+ requests.push({ id: resolveId(id), range: { mode: 'one', ts } });
106
+ }
107
+ return;
108
+ }
109
+ if (spec.start !== undefined && spec.start !== null) {
110
+ const start = toTimestamp(spec.start);
111
+ const end = spec.end === undefined || spec.end === null ? now : toTimestamp(spec.end);
112
+ if (start === undefined) {
113
+ errors.push(`Invalid "start" ${show(spec.start)} for ${id}`);
114
+ }
115
+ else if (end === undefined) {
116
+ errors.push(`Invalid "end" ${show(spec.end)} for ${id}`);
117
+ }
118
+ else {
119
+ requests.push({ id: resolveId(id), range: { mode: 'range', start, end } });
120
+ }
121
+ return;
122
+ }
123
+ if (spec.end !== undefined && spec.end !== null) {
124
+ errors.push(`"start" is missing for ${id}: a range needs "start", "end" is optional`);
125
+ return;
126
+ }
127
+ errors.push(`Neither "ts" nor "start" given for ${id}: ${show(entry)}`);
128
+ };
129
+ /** `{id, ts}` / `{id, start, end}` carry the time themselves, otherwise it is in `state` */
130
+ const timeOf = (item) => (item.ts === undefined || item.ts === null) &&
131
+ (item.start === undefined || item.start === null) &&
132
+ item.state &&
133
+ typeof item.state === 'object'
134
+ ? item.state
135
+ : item;
136
+ if (Array.isArray(message)) {
137
+ for (const item of message) {
138
+ if (!item || typeof item !== 'object') {
139
+ errors.push(`Invalid entry ${show(item)}`);
140
+ }
141
+ else {
142
+ one(item.id, timeOf(item));
143
+ }
144
+ }
145
+ }
146
+ else if (message && typeof message === 'object') {
147
+ const msg = message;
148
+ if (Array.isArray(msg.state)) {
149
+ msg.state.forEach(entry => one(msg.id, entry));
150
+ }
151
+ else if (Array.isArray(msg.ts)) {
152
+ msg.ts.forEach(ts => one(msg.id, ts));
153
+ }
154
+ else {
155
+ one(msg.id, timeOf(msg));
156
+ }
157
+ }
158
+ else {
159
+ errors.push(`Invalid call: ${show(message)}`);
160
+ }
161
+ return { requests, errors };
162
+ }
163
+ //# sourceMappingURL=deleteRequests.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteRequests.js","sourceRoot":"","sources":["../../src/lib/deleteRequests.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AA8BH,kCAcC;AAUD,gDAiBC;AAiBD,kDA2EC;AAvJD,yDAAyD;AACzD,MAAM,WAAW,GAAG,OAAO,CAAC;AAE5B,SAAS,WAAW,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC;AACjG,CAAC;AAED,gFAAgF;AAChF,SAAS,IAAI,CAAC,KAAc;IACxB,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACpG,CAAC;AAED;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,KAAc;IACtC,IAAI,EAAU,CAAC;IACf,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,EAAE,GAAG,KAAK,CAAC;IACf,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QACnD,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAC1B,mFAAmF;QACnF,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IAChF,CAAC;SAAM,IAAI,KAAK,YAAY,IAAI,EAAE,CA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AAC;AAChC,CAAC"}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ /**
3
+ * The answer of the message `help`: what the instance answers, written for an AI agent (e.g. ioBroker.pi-agent, or
4
+ * the MCP server with `send_to`) and for script authors. Keep it in sync with `processMessage` in main.ts.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.HELP = exports.COMMANDS = void 0;
8
+ /**
9
+ * Every command `processMessage` answers; `write` = it changes data, settings or the instance; `standard` = it follows
10
+ * the shared catalog of sendTo commands (HELP.md of ioBroker.assistant), the same in history, sql, influxdb and recorder
11
+ */
12
+ exports.COMMANDS = [
13
+ { command: 'help', write: false },
14
+ { command: 'getHistory', write: false, standard: 'history.getHistory' },
15
+ { command: 'aggregate', write: false, standard: 'history.aggregate' },
16
+ { command: 'lastChange', write: false, standard: 'history.lastChange' },
17
+ { command: 'getEnabledDPs', write: false },
18
+ { command: 'getDatapoints', write: false },
19
+ { command: 'getRawEntries', write: false },
20
+ { command: 'getDpStatistics', write: false },
21
+ { command: 'getRetention', write: false },
22
+ { command: 'getConflictingPoints', write: false },
23
+ { command: 'features', write: false },
24
+ { command: 'flushBuffer', write: false },
25
+ { command: 'test', write: false },
26
+ { command: 'query', write: true },
27
+ { command: 'enableHistory', write: true },
28
+ { command: 'disableHistory', write: true },
29
+ { command: 'storeState', write: true },
30
+ { command: 'update', write: true },
31
+ { command: 'delete', write: true },
32
+ { command: 'deleteRange', write: true },
33
+ { command: 'deleteAll', write: true },
34
+ { command: 'cleanupOrphaned', write: true },
35
+ { command: 'resetConflictingPoints', write: true },
36
+ { command: 'destroy', write: true },
37
+ { command: 'stopInstance', write: true },
38
+ ];
39
+ exports.HELP = `ioBroker.influxdb: stores the history of the states that are enabled for it (per state in the object settings)
40
+ in InfluxDB 1.x, 2.x or 3.x (native.dbversion of system.adapter.influxdb.0). An agent can read the course of a
41
+ state (the stored values or one value per interval), list the logged states and the stored data, run a reading
42
+ query and, only on the user's request, enable or disable the logging and store, change or delete values.
43
+
44
+ Times (start, end, ts): milliseconds since 1970 or a date text such as "2026-11-19T08:00" (local time of the host).
45
+ Times in the answers are milliseconds since 1970.
46
+
47
+ Layout (for a query):
48
+ - Database (1.x, 3.x) or bucket (2.x, organization native.organization): native.dbname, default "iobroker".
49
+ - One measurement per state, named after its ID (or its setting aliasId). Field "value": float, boolean or string
50
+ (objects as JSON); the first point fixes the type (setting storageType of the state). q, ack and from are
51
+ fields; on 2.x and 3.x with native.usetags they are tags (strings). The custom tags of a state are tags.
52
+ - InfluxQL (1.x and 3.x): SELECT value FROM "hm-rpc.0.ABC.1.TEMPERATURE" WHERE time > now() - 1h; the ID in
53
+ double quotes, times as now() - 1d or '2026-11-19T08:00:00Z'.
54
+ - Flux (2.x): from(bucket: "iobroker") |> range(start: -1h) |> filter(fn: (r) => r._measurement ==
55
+ "hm-rpc.0.ABC.1.TEMPERATURE" and r._field == "value"); the value is in _value.
56
+
57
+ Commands (sendTo influxdb.0): getHistory, aggregate and lastChange are standard commands of the shared catalog of
58
+ ioBroker (family history): the same names, parameters and answers in history, sql, influxdb and recorder.
59
+ - getHistory {id, options: {start?, end?, aggregate?, count?, step?, ...}}: the course of one state:
60
+ {result: [{ts, val, ack?, from?, q?, id?}], step, sessionId}, on an error {result: [], error}. options is
61
+ required (may be {}). id: one state; "*" (all states) is refused with an error.
62
+ aggregate: average (default), min, max, minmax (min and max of each interval), total, count, percentile
63
+ {percentile 0-100, default 50}, quantile {quantile 0-1, default 0.5}, integral {integralUnit in s, default 60,
64
+ 3600 gives Wh from W; integralInterpolation none (default) | linear}: one value per interval, mostly computed
65
+ by InfluxDB; none or onchange: the stored values (with their ack, q and from).
66
+ start: without it the newest count values; with an aggregate and without step, the adapter builds the
67
+ intervals from them (as sql and history do).
68
+ end: default now + 5000 s. count: the number of intervals (default 500); with none/onchange the number of
69
+ values (default limit on 1.x and 3.x, 500 on 2.x). step: the interval in ms instead of count.
70
+ intervalBorders: [ms, ...] ascending borders of the intervals (e.g. local days), replaces start, end and step.
71
+ limit: at most this many values or intervals (default count, else the setting limit, else 2000).
72
+ returnNewestEntries: true = the newest values instead of the oldest when count cuts. addId: true adds the id.
73
+ round: digits after the decimal point (default the setting of the instance). removeBorderValues: true drops
74
+ the values before start and after end that are added for charts. sessionId: returned as it is. ignoreNull,
75
+ ack, from and q are not read: a null is replaced by the value before.
76
+ - aggregate {id, start, end?, fn, value?}: one number for a period: {value, ts?, unit?, count}. fn: min, max (ts =
77
+ when), avg (the mean of the stored values), sum, count (with value: how often the state became it, e.g. true),
78
+ delta (how much a counter rose, resets included), first, last, integral (value × hours: W gives Wh), duration
79
+ (with value: how many seconds the state had it). end: default now. count: the stored values in the period, at
80
+ most 50000 (else reason TOO_MANY_VALUES). Errors: {error, reason} (reason BAD_REQUEST for a wrong parameter).
81
+ Computed from the values of getHistory (aggregate none).
82
+ - lastChange {id, value?, before?}: when the state last changed (to value): {ts, val}; before: only the values
83
+ before this time. A value logged again does not count as a change. Reason NOT_FOUND if it never had the value;
84
+ only the newest 10000 stored values are searched: limited true = it had it already then.
85
+ - getEnabledDPs {}: the states this instance logs: {[id]: their settings (enabled, changesOnly, debounceTime,
86
+ blockTime, changesMinDelta, changesRelogInterval, ignoreZero, ignoreBelowNumber, ignoreAboveNumber, round,
87
+ storageType, aliasId, customTags, ...)}.
88
+ - getDatapoints {}: every measurement of the database, also the ones no longer logged: {success, result: [{id,
89
+ type: Number | String | Boolean | null}]}.
90
+ - getRawEntries {id, start?, end?, limit? (1-5000, default 100), offset? (default 0), sort? desc (default) | asc,
91
+ noTotal?}: the points exactly as stored: {id, total, limit, offset, sort, result: [{ts, val, ack, q, from}]};
92
+ noTotal: true skips the counting (total is missing then).
93
+ - getDpStatistics {start?, end?}: per measurement the number of values (a full scan, slow on a big database):
94
+ {success, result: [{id, type, count, firstTs, lastTs, cardinality (series), status}], summary: {datapoints,
95
+ values, cardinality, byStatus}}. status: active, loggingDisabled (the state exists, not logged), objectMissing.
96
+ - getRetention {}: how long the database keeps values: {result: {name, time (s, 0 = forever)}} or {error}.
97
+ - getConflictingPoints {}: the states whose values InfluxDB refused for another type; they are written directly
98
+ since: {conflictingPoints: {[id]: 1}}.
99
+ - features {}: {supportedFeatures: [update, delete, deleteRange, deleteAll, storeState, getDatapoints,
100
+ getRawEntries, getDpStatistics, cleanupOrphaned]}; 3.x without delete and deleteRange (and update with usetags).
101
+ - flushBuffer {id?}: writes the buffered values of the state (of all without id) into the database now, as
102
+ getHistory does itself: {error: null} or {error}.
103
+ - query "statement" (the message is the string itself): runs it as it is, InfluxQL on 1.x and 3.x, Flux on 2.x;
104
+ several statements separated by ";": {result: [[rows of the 1st statement], ...], ts} or {result: [], error}.
105
+ time becomes ts (ms); InfluxQL rows keep the field as "value". It runs ANY statement (also DELETE, DROP or a
106
+ Flux to()); use it only for reading.
107
+ - enableHistory {id, options?}: logs the state from now on; options = its settings as in getEnabledDPs (the
108
+ defaults of the instance otherwise): {success} or {error}.
109
+ - disableHistory {id}: stops logging the state, the stored values stay: {success} or {error}.
110
+ - storeState {id, state: {ts, val, ack?, q?, from?} or a list of them, rules?} or [{id, state, rules?}]: writes
111
+ values (through the buffer), also of a state that is not logged; ts is required, null is refused, a number as
112
+ text becomes a number; rules: true applies the logging settings (only for a logged state): {success,
113
+ successCount} or {error, errors, successCount}.
114
+ - update {id, state: {ts, val?, ack?, q?, from?}} or [{id, state}] or {id, state: [...]}: changes the stored point
115
+ with exactly this ts (not on 3.x with usetags): {success} or {success: false, error}.
116
+ - delete {id, ts} or {id, ts: [ts, ...]} or [{id, ts}]: deletes the points with exactly these ts (not on 3.x):
117
+ {success} or {success: false, error}.
118
+ - deleteRange {id, start, end?} or [{id, start, end?}] or {id, state: [{start, end?}]}: deletes the points with
119
+ start <= ts <= end (end default now; not on 3.x): {success} or {success: false, error}.
120
+ ts, start and end: ms or a date string, 0 is valid. If one entry has no valid ts or start, nothing is deleted
121
+ and error says what is missing.
122
+ - deleteAll {id} or [{id}]: deletes every value of these states (3.x: drops the measurement): {success} or
123
+ {success: false, error}.
124
+ - cleanupOrphaned {scope?: {objectMissing? (default true), loggingDisabled? (default false), ids?}, confirm?}: the
125
+ measurements of states that are not logged any more. Without confirm: true only the preview {dryRun: true,
126
+ datapoints, values, items}; with confirm: true it drops them and adds {deleted, failed}.
127
+ - resetConflictingPoints {}: empties the list of getConflictingPoints: {reset: true, conflictingPoints}.
128
+ - destroy {noRestart?}: drops the whole database (bucket), then restarts the instance (noRestart: true creates it
129
+ empty again instead): {error: null} or {error}. Every stored value is lost.
130
+ - test {config}, stopInstance: for the settings and js-controller, not for agents.
131
+
132
+ How to talk to the user:
133
+ - Find the state first (search the objects); name states by their name, give times in local time and values
134
+ with their unit.
135
+ - A state has a history only if it is or was logged (getEnabledDPs, getDatapoints). For a longer period request
136
+ one value per interval (e.g. aggregate average with start and count 24 to 200) instead of every stored value.
137
+ For one number of a period (the highest value, how often, how long, how much) use the command aggregate, for
138
+ "when was it last ..." lastChange. Prefer these and getHistory; write a query only for what they cannot answer,
139
+ and read dbversion and dbname first.
140
+ - Send only reading statements with query (InfluxQL SELECT or SHOW, Flux without to() or another output). Any
141
+ other statement only on the user's explicit request.
142
+ - query (other than reading), delete, deleteRange, deleteAll, update, storeState, cleanupOrphaned, destroy,
143
+ resetConflictingPoints, enableHistory, disableHistory and stopInstance change the database, the settings or
144
+ the instance: never without the user's explicit request. Deleted values cannot be restored: name the state
145
+ and the range and ask for confirmation first; show the preview of cleanupOrphaned (without confirm) before
146
+ deleting; for destroy say that the whole history is lost.`;
147
+ //# sourceMappingURL=help.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/lib/help.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;GAGG;AACU,QAAA,QAAQ,GAA6D;IAC9E,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE;IACjC,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,Q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