influx 5.0.6 → 5.0.7
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/lib/src/backoff/backoff.d.ts +15 -15
- package/lib/src/backoff/backoff.js +2 -2
- package/lib/src/backoff/exponential.d.ts +52 -52
- package/lib/src/backoff/exponential.js +40 -40
- package/lib/src/builder.d.ts +265 -265
- package/lib/src/builder.js +366 -366
- package/lib/src/doc.d.ts +315 -315
- package/lib/src/doc.js +340 -340
- package/lib/src/grammar/ds.d.ts +45 -45
- package/lib/src/grammar/ds.js +56 -56
- package/lib/src/grammar/escape.d.ts +25 -25
- package/lib/src/grammar/escape.js +108 -108
- package/lib/src/grammar/index.d.ts +3 -3
- package/lib/src/grammar/index.js +8 -8
- package/lib/src/grammar/times.d.ts +74 -74
- package/lib/src/grammar/times.js +325 -325
- package/lib/src/host.d.ts +26 -26
- package/lib/src/host.js +34 -34
- package/lib/src/index.d.ts +659 -659
- package/lib/src/index.js +870 -870
- package/lib/src/pool.d.ts +149 -149
- package/lib/src/pool.js +344 -344
- package/lib/src/results.d.ts +118 -118
- package/lib/src/results.js +146 -146
- package/lib/src/schema.d.ts +58 -58
- package/lib/src/schema.js +117 -117
- package/package.json +2 -2
package/lib/src/index.d.ts
CHANGED
|
@@ -1,659 +1,659 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { RequestOptions } from 'https';
|
|
3
|
-
import * as b from './builder';
|
|
4
|
-
import * as grammar from './grammar';
|
|
5
|
-
import { IPingStats, IPoolOptions } from './pool';
|
|
6
|
-
import { IResults } from './results';
|
|
7
|
-
import { ISchemaOptions } from './schema';
|
|
8
|
-
export * from './builder';
|
|
9
|
-
export { INanoDate, FieldType, Precision, Raw, TimePrecision, escape, toNanoDate } from './grammar';
|
|
10
|
-
export { ISchemaOptions } from './schema';
|
|
11
|
-
export { IPingStats, IPoolOptions } from './pool';
|
|
12
|
-
export { IResults, IResponse, ResultError } from './results';
|
|
13
|
-
export interface IHostConfig {
|
|
14
|
-
/**
|
|
15
|
-
* Influx host to connect to, defaults to 127.0.0.1.
|
|
16
|
-
*/
|
|
17
|
-
host: string;
|
|
18
|
-
/**
|
|
19
|
-
* Influx port to connect to, defaults to 8086.
|
|
20
|
-
*/
|
|
21
|
-
port?: number;
|
|
22
|
-
/**
|
|
23
|
-
* Protocol to connect over, defaults to 'http'.
|
|
24
|
-
*/
|
|
25
|
-
protocol?: 'http' | 'https';
|
|
26
|
-
/**
|
|
27
|
-
* Optional request option overrides.
|
|
28
|
-
*/
|
|
29
|
-
options?: RequestOptions;
|
|
30
|
-
}
|
|
31
|
-
export interface ISingleHostConfig extends IHostConfig {
|
|
32
|
-
/**
|
|
33
|
-
* Username for connecting to the database. Defaults to 'root'.
|
|
34
|
-
*/
|
|
35
|
-
username?: string;
|
|
36
|
-
/**
|
|
37
|
-
* Password for connecting to the database. Defaults to 'root'.
|
|
38
|
-
*/
|
|
39
|
-
password?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Default database to write information to.
|
|
42
|
-
*/
|
|
43
|
-
database?: string;
|
|
44
|
-
/**
|
|
45
|
-
* Settings for the connection pool.
|
|
46
|
-
*/
|
|
47
|
-
pool?: IPoolOptions;
|
|
48
|
-
/**
|
|
49
|
-
* A list of schema for measurements in the database.
|
|
50
|
-
*/
|
|
51
|
-
schema?: ISchemaOptions[];
|
|
52
|
-
}
|
|
53
|
-
export interface IClusterConfig {
|
|
54
|
-
/**
|
|
55
|
-
* Username for connecting to the database. Defaults to 'root'.
|
|
56
|
-
*/
|
|
57
|
-
username?: string;
|
|
58
|
-
/**
|
|
59
|
-
* Password for connecting to the database. Defaults to 'root'.
|
|
60
|
-
*/
|
|
61
|
-
password?: string;
|
|
62
|
-
/**
|
|
63
|
-
* Default database to write information to.
|
|
64
|
-
*/
|
|
65
|
-
database?: string;
|
|
66
|
-
/**
|
|
67
|
-
* A list of cluster hosts to connect to.
|
|
68
|
-
*/
|
|
69
|
-
hosts: IHostConfig[];
|
|
70
|
-
/**
|
|
71
|
-
* Settings for the connection pool.
|
|
72
|
-
*/
|
|
73
|
-
pool?: IPoolOptions;
|
|
74
|
-
/**
|
|
75
|
-
* A list of schema for measurements in the database.
|
|
76
|
-
*/
|
|
77
|
-
schema?: ISchemaOptions[];
|
|
78
|
-
}
|
|
79
|
-
export interface IPoint {
|
|
80
|
-
/**
|
|
81
|
-
* Measurement is the Influx measurement name.
|
|
82
|
-
*/
|
|
83
|
-
measurement?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Tags is the list of tag values to insert.
|
|
86
|
-
*/
|
|
87
|
-
tags?: {
|
|
88
|
-
[name: string]: string;
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Fields is the list of field values to insert.
|
|
92
|
-
*/
|
|
93
|
-
fields?: {
|
|
94
|
-
[name: string]: any;
|
|
95
|
-
};
|
|
96
|
-
/**
|
|
97
|
-
* Timestamp tags this measurement with a date. This can be a Date object,
|
|
98
|
-
* in which case we'll adjust it to the desired precision, or a numeric
|
|
99
|
-
* string or number, in which case it gets passed directly to Influx.
|
|
100
|
-
*/
|
|
101
|
-
timestamp?: Date | string | number;
|
|
102
|
-
}
|
|
103
|
-
export interface IWriteOptions {
|
|
104
|
-
/**
|
|
105
|
-
* Precision at which the points are written, defaults to nanoseconds 'n'.
|
|
106
|
-
*/
|
|
107
|
-
precision?: grammar.TimePrecision;
|
|
108
|
-
/**
|
|
109
|
-
* Retention policy to write the points under, defaults to the DEFAULT
|
|
110
|
-
* database policy.
|
|
111
|
-
*/
|
|
112
|
-
retentionPolicy?: string;
|
|
113
|
-
/**
|
|
114
|
-
* Database under which to write the points. This is required if a default
|
|
115
|
-
* database is not provided in Influx.
|
|
116
|
-
*/
|
|
117
|
-
database?: string;
|
|
118
|
-
}
|
|
119
|
-
export interface IQueryOptions {
|
|
120
|
-
/**
|
|
121
|
-
* Defines the precision at which to query points. When left blank, it will
|
|
122
|
-
* query in nanosecond precision.
|
|
123
|
-
*/
|
|
124
|
-
precision?: grammar.TimePrecision;
|
|
125
|
-
/**
|
|
126
|
-
* Retention policy to query from, defaults to the DEFAULT
|
|
127
|
-
* database policy.
|
|
128
|
-
*/
|
|
129
|
-
retentionPolicy?: string;
|
|
130
|
-
/**
|
|
131
|
-
* Database under which to query the points. This is required if a default
|
|
132
|
-
* database is not provided in Influx.
|
|
133
|
-
*/
|
|
134
|
-
database?: string;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* IRetentionOptions are passed into passed into the {@link
|
|
138
|
-
* InfluxDB#createRetentionPolicy} and {@link InfluxDB#alterRetentionPolicy}.
|
|
139
|
-
* See the [Downsampling and Retention page](https://docs.influxdata.com/
|
|
140
|
-
* influxdb/v1.0/guides/downsampling_and_retention/) on the Influx docs for
|
|
141
|
-
* more information.
|
|
142
|
-
*/
|
|
143
|
-
export interface IRetentionOptions {
|
|
144
|
-
database?: string;
|
|
145
|
-
duration: string;
|
|
146
|
-
replication: number;
|
|
147
|
-
isDefault?: boolean;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* InfluxDB is the public interface to run queries against the your database.
|
|
151
|
-
* This is a 'driver-level' module, not a a full-fleged ORM or ODM; you run
|
|
152
|
-
* queries directly by calling methods on this class.
|
|
153
|
-
*
|
|
154
|
-
* Please check out some of [the tutorials](https://node-influx.github.io/manual/tutorial.html)
|
|
155
|
-
* if you want help getting started!
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* const Influx = require('influx');
|
|
159
|
-
* const influx = new Influx.InfluxDB({
|
|
160
|
-
* host: 'localhost',
|
|
161
|
-
* database: 'express_response_db',
|
|
162
|
-
* schema: [
|
|
163
|
-
* {
|
|
164
|
-
* measurement: 'response_times',
|
|
165
|
-
* fields: {
|
|
166
|
-
* path: Influx.FieldType.STRING,
|
|
167
|
-
* duration: Influx.FieldType.INTEGER
|
|
168
|
-
* },
|
|
169
|
-
* tags: [
|
|
170
|
-
* 'host'
|
|
171
|
-
* ]
|
|
172
|
-
* }
|
|
173
|
-
* ]
|
|
174
|
-
* })
|
|
175
|
-
*
|
|
176
|
-
* influx.writePoints([
|
|
177
|
-
* {
|
|
178
|
-
* measurement: 'response_times',
|
|
179
|
-
* tags: { host: os.hostname() },
|
|
180
|
-
* fields: { duration, path: req.path },
|
|
181
|
-
* }
|
|
182
|
-
* ]).then(() => {
|
|
183
|
-
* return influx.query(`
|
|
184
|
-
* select * from response_times
|
|
185
|
-
* where host = ${Influx.escape.stringLit(os.hostname())}
|
|
186
|
-
* order by time desc
|
|
187
|
-
* limit 10
|
|
188
|
-
* `)
|
|
189
|
-
* }).then(rows => {
|
|
190
|
-
* rows.forEach(row => console.log(`A request to ${row.path} took ${row.duration}ms`))
|
|
191
|
-
* })
|
|
192
|
-
*/
|
|
193
|
-
export declare class InfluxDB {
|
|
194
|
-
/**
|
|
195
|
-
* Connect pool for making requests.
|
|
196
|
-
* @private
|
|
197
|
-
*/
|
|
198
|
-
private pool;
|
|
199
|
-
/**
|
|
200
|
-
* Config options for Influx.
|
|
201
|
-
* @private
|
|
202
|
-
*/
|
|
203
|
-
private options;
|
|
204
|
-
/**
|
|
205
|
-
* Map of Schema instances defining measurements in Influx.
|
|
206
|
-
* @private
|
|
207
|
-
*/
|
|
208
|
-
private schema;
|
|
209
|
-
constructor(options: ISingleHostConfig);
|
|
210
|
-
/**
|
|
211
|
-
* Connect to an InfluxDB cluster by specifying a
|
|
212
|
-
* set of connection options.
|
|
213
|
-
*/
|
|
214
|
-
constructor(options: IClusterConfig);
|
|
215
|
-
/**
|
|
216
|
-
* Connect to an InfluxDB instance using a configuration URL.
|
|
217
|
-
* @example
|
|
218
|
-
* new InfluxDB('http://user:password@host:8086/database')
|
|
219
|
-
*/
|
|
220
|
-
constructor(url: string);
|
|
221
|
-
/**
|
|
222
|
-
* Connects to a local, default Influx instance.
|
|
223
|
-
*/
|
|
224
|
-
constructor();
|
|
225
|
-
/**
|
|
226
|
-
* Creates a new database with the provided name.
|
|
227
|
-
* @param {string} databaseName
|
|
228
|
-
* @return {Promise.<void>}
|
|
229
|
-
* @example
|
|
230
|
-
* influx.createDatabase('mydb')
|
|
231
|
-
*/
|
|
232
|
-
createDatabase(databaseName: string): Promise<void>;
|
|
233
|
-
/**
|
|
234
|
-
* Deletes a database with the provided name.
|
|
235
|
-
* @param {string} databaseName
|
|
236
|
-
* @return {Promise.<void>}
|
|
237
|
-
* @example
|
|
238
|
-
* influx.createDatabase('mydb')
|
|
239
|
-
*/
|
|
240
|
-
dropDatabase(databaseName: string): Promise<void>;
|
|
241
|
-
/**
|
|
242
|
-
* Returns array of database names. Requires cluster admin privileges.
|
|
243
|
-
* @returns {Promise<String[]>} a list of database names
|
|
244
|
-
* @example
|
|
245
|
-
* influx.getMeasurements().then(names =>
|
|
246
|
-
* console.log('My database names are: ' + names.join(', ')));
|
|
247
|
-
*/
|
|
248
|
-
getDatabaseNames(): Promise<string[]>;
|
|
249
|
-
/**
|
|
250
|
-
* Returns array of measurements.
|
|
251
|
-
* @returns {Promise<String[]>} a list of measurement names
|
|
252
|
-
* @param {String} [database] the database the measurement lives in, optional
|
|
253
|
-
* if a default database is provided.
|
|
254
|
-
* @example
|
|
255
|
-
* influx.getMeasurements().then(names =>
|
|
256
|
-
* console.log('My measurement names are: ' + names.join(', ')));
|
|
257
|
-
*/
|
|
258
|
-
getMeasurements(database?: string): Promise<string[]>;
|
|
259
|
-
/**
|
|
260
|
-
* Returns a list of all series within the target measurement, or from the
|
|
261
|
-
* entire database if a measurement isn't provided.
|
|
262
|
-
* @param {Object} [options]
|
|
263
|
-
* @param {String} [options.measurement] if provided, we'll only get series
|
|
264
|
-
* from within that measurement.
|
|
265
|
-
* @param {String} [options.database] the database the series lives in,
|
|
266
|
-
* optional if a default database is provided.
|
|
267
|
-
* @returns {Promise<String[]>} a list of series names
|
|
268
|
-
* @example
|
|
269
|
-
* influx.getSeries().then(names => {
|
|
270
|
-
* console.log('My series names in my_measurement are: ' + names.join(', '))
|
|
271
|
-
* })
|
|
272
|
-
*
|
|
273
|
-
* influx.getSeries({
|
|
274
|
-
* measurement: 'my_measurement',
|
|
275
|
-
* database: 'my_db'
|
|
276
|
-
* }).then(names => {
|
|
277
|
-
* console.log('My series names in my_measurement are: ' + names.join(', '))
|
|
278
|
-
* })
|
|
279
|
-
*/
|
|
280
|
-
getSeries(options?: {
|
|
281
|
-
measurement?: string;
|
|
282
|
-
database?: string;
|
|
283
|
-
}): Promise<string[]>;
|
|
284
|
-
/**
|
|
285
|
-
* Removes a measurement from the database.
|
|
286
|
-
* @param {String} measurement
|
|
287
|
-
* @param {String} [database] the database the measurement lives in, optional
|
|
288
|
-
* if a default database is provided.
|
|
289
|
-
* @return {Promise.<void>}
|
|
290
|
-
* @example
|
|
291
|
-
* influx.dropMeasurement('my_measurement')
|
|
292
|
-
*/
|
|
293
|
-
dropMeasurement(measurement: string, database?: string): Promise<void>;
|
|
294
|
-
/**
|
|
295
|
-
* Removes a one or more series from InfluxDB.
|
|
296
|
-
*
|
|
297
|
-
* @returns {Promise<void>}
|
|
298
|
-
* @example
|
|
299
|
-
* // The following pairs of queries are equivalent: you can chose either to
|
|
300
|
-
* // use our builder or pass in string directly. The builder takes care
|
|
301
|
-
* // of escaping and most syntax handling for you.
|
|
302
|
-
*
|
|
303
|
-
* influx.dropSeries({ where: e => e.tag('cpu').equals.value('cpu8') })
|
|
304
|
-
* influx.dropSeries({ where: '"cpu" = \'cpu8\'' })
|
|
305
|
-
* // DROP SERIES WHERE "cpu" = 'cpu8'
|
|
306
|
-
*
|
|
307
|
-
* influx.dropSeries({ measurement: m => m.name('cpu').policy('autogen') })
|
|
308
|
-
* influx.dropSeries({ measurement: '"cpu"."autogen"' })
|
|
309
|
-
* // DROP SERIES FROM "autogen"."cpu"
|
|
310
|
-
*
|
|
311
|
-
* influx.dropSeries({
|
|
312
|
-
* measurement: m => m.name('cpu').policy('autogen'),
|
|
313
|
-
* where: e => e.tag('cpu').equals.value('cpu8'),
|
|
314
|
-
* database: 'my_db'
|
|
315
|
-
* })
|
|
316
|
-
* // DROP SERIES FROM "autogen"."cpu" WHERE "cpu" = 'cpu8'
|
|
317
|
-
*/
|
|
318
|
-
dropSeries(options: b.measurement | b.where | {
|
|
319
|
-
database: string;
|
|
320
|
-
}): Promise<void>;
|
|
321
|
-
/**
|
|
322
|
-
* Returns a list of users on the Influx database.
|
|
323
|
-
* @return {Promise<Array<{ user: String, admin: Boolean }>>}
|
|
324
|
-
* @example
|
|
325
|
-
* influx.getUsers().then(users => {
|
|
326
|
-
* users.forEach(user => {
|
|
327
|
-
* if (user.admin) {
|
|
328
|
-
* console.log(user.user, 'is an admin!')
|
|
329
|
-
* } else {
|
|
330
|
-
* console.log(user.user, 'is not an admin!')
|
|
331
|
-
* }
|
|
332
|
-
* })
|
|
333
|
-
* })
|
|
334
|
-
*/
|
|
335
|
-
getUsers(): Promise<{
|
|
336
|
-
user: string;
|
|
337
|
-
admin: boolean;
|
|
338
|
-
}[]>;
|
|
339
|
-
/**
|
|
340
|
-
* Creates a new InfluxDB user.
|
|
341
|
-
* @param {String} username
|
|
342
|
-
* @param {String} password
|
|
343
|
-
* @param {Boolean} [admin=false] If true, the user will be given all
|
|
344
|
-
* privileges on all databases.
|
|
345
|
-
* @return {Promise<void>}
|
|
346
|
-
* @example
|
|
347
|
-
* influx.createUser('connor', 'pa55w0rd', true) // make 'connor' an admin
|
|
348
|
-
*
|
|
349
|
-
* // make non-admins:
|
|
350
|
-
* influx.createUser('not_admin', 'pa55w0rd')
|
|
351
|
-
*/
|
|
352
|
-
createUser(username: string, password: string, admin?: boolean): Promise<void>;
|
|
353
|
-
/**
|
|
354
|
-
* Sets a password for an Influx user.
|
|
355
|
-
* @param {String} username
|
|
356
|
-
* @param {String} password
|
|
357
|
-
* @return {Promise<void>}
|
|
358
|
-
* @example
|
|
359
|
-
* influx.setPassword('connor', 'pa55w0rd')
|
|
360
|
-
*/
|
|
361
|
-
setPassword(username: string, password: string): Promise<void>;
|
|
362
|
-
/**
|
|
363
|
-
* Grants a privilege to a specified user.
|
|
364
|
-
* @param {String} username
|
|
365
|
-
* @param {String} privilege Should be one of 'READ' or 'WRITE'
|
|
366
|
-
* @param {String} [database] If not provided, uses the default database.
|
|
367
|
-
* @return {Promise<void>}
|
|
368
|
-
* @example
|
|
369
|
-
* influx.grantPrivilege('connor', 'READ', 'my_db') // grants read access on my_db to connor
|
|
370
|
-
*/
|
|
371
|
-
grantPrivilege(username: string, privilege: 'READ' | 'WRITE', database?: string): Promise<void>;
|
|
372
|
-
/**
|
|
373
|
-
* Removes a privilege from a specified user.
|
|
374
|
-
* @param {String} username
|
|
375
|
-
* @param {String} privilege Should be one of 'READ' or 'WRITE'
|
|
376
|
-
* @param {String} [database] If not provided, uses the default database.
|
|
377
|
-
* @return {Promise<void>}
|
|
378
|
-
* @example
|
|
379
|
-
* influx.revokePrivilege('connor', 'READ', 'my_db') // removes read access on my_db from connor
|
|
380
|
-
*/
|
|
381
|
-
revokePrivilege(username: string, privilege: 'READ' | 'WRITE', database?: string): Promise<void>;
|
|
382
|
-
/**
|
|
383
|
-
* Grants admin privileges to a specified user.
|
|
384
|
-
* @param {String} username
|
|
385
|
-
* @return {Promise<void>}
|
|
386
|
-
* @example
|
|
387
|
-
* influx.grantAdminPrivilege('connor')
|
|
388
|
-
*/
|
|
389
|
-
grantAdminPrivilege(username: string): Promise<void>;
|
|
390
|
-
/**
|
|
391
|
-
* Removes a admin privilege from a specified user.
|
|
392
|
-
* @param {String} username
|
|
393
|
-
* @return {Promise<void>}
|
|
394
|
-
* @example
|
|
395
|
-
* influx.revokeAdminPrivilege('connor')
|
|
396
|
-
*/
|
|
397
|
-
revokeAdminPrivilege(username: string): Promise<void>;
|
|
398
|
-
/**
|
|
399
|
-
* Removes a user from the database.
|
|
400
|
-
* @param {String} username
|
|
401
|
-
* @return {Promise<void>}
|
|
402
|
-
* @example
|
|
403
|
-
* influx.dropUser('connor')
|
|
404
|
-
*/
|
|
405
|
-
dropUser(username: string): Promise<void>;
|
|
406
|
-
/**
|
|
407
|
-
* Creates a continuous query in a database
|
|
408
|
-
* @param {String} name The query name, for later reference
|
|
409
|
-
* @param {String} query The body of the query to run
|
|
410
|
-
* @param {String} [database] If not provided, uses the default database.
|
|
411
|
-
* @return {Promise<void>}
|
|
412
|
-
* @example
|
|
413
|
-
* influx.createContinuousQuery('downsample_cpu_1h', `
|
|
414
|
-
* SELECT MEAN(cpu) INTO "7d"."perf"
|
|
415
|
-
* FROM "1d"."perf" GROUP BY time(1m)
|
|
416
|
-
* `)
|
|
417
|
-
*/
|
|
418
|
-
createContinuousQuery(name: string, query: string, database?: string): Promise<void>;
|
|
419
|
-
/**
|
|
420
|
-
* Returns a list of continous queries in the database.
|
|
421
|
-
* @param {String} [database] If not provided, uses the default database.
|
|
422
|
-
* @return {Promise<void>}
|
|
423
|
-
* @example
|
|
424
|
-
* influx.showContinousQueries()
|
|
425
|
-
*/
|
|
426
|
-
showContinousQueries(database?: string): Promise<IResults<{
|
|
427
|
-
name: string;
|
|
428
|
-
query: string;
|
|
429
|
-
}>>;
|
|
430
|
-
/**
|
|
431
|
-
* Creates a continuous query in a database
|
|
432
|
-
* @param {String} name The query name
|
|
433
|
-
* @param {String} [database] If not provided, uses the default database.
|
|
434
|
-
* @return {Promise<void>}
|
|
435
|
-
* @example
|
|
436
|
-
* influx.dropContinuousQuery('downsample_cpu_1h')
|
|
437
|
-
*/
|
|
438
|
-
dropContinuousQuery(name: string, database?: string): Promise<void>;
|
|
439
|
-
/**
|
|
440
|
-
* Creates a new retention policy on a database. You can read more about
|
|
441
|
-
* [Downsampling and Retention](https://docs.influxdata.com/influxdb/v1.0/
|
|
442
|
-
* guides/downsampling_and_retention/) on the InfluxDB website.
|
|
443
|
-
*
|
|
444
|
-
* @param {String} name The retention policy name
|
|
445
|
-
* @param {Object} options
|
|
446
|
-
* @param {String} [options.database] Database to create the policy on,
|
|
447
|
-
* uses the default database if not provided.
|
|
448
|
-
* @param {String} options.duration How long data in the retention policy
|
|
449
|
-
* should be stored for, should be in a format like `7d`. See details
|
|
450
|
-
* [here](https://docs.influxdata.com/influxdb/v1.0/query_language/spec/#durations)
|
|
451
|
-
* @param {Number} options.replication How many servers data in the series
|
|
452
|
-
* should be replicated to.
|
|
453
|
-
* @param {Boolean} [options.isDefault] Whether the retention policy should
|
|
454
|
-
* be the default policy on the database.
|
|
455
|
-
* @return {Promise<void>}
|
|
456
|
-
* @example
|
|
457
|
-
* influx.createRetentionPolicy('7d', {
|
|
458
|
-
* duration: '7d',
|
|
459
|
-
* replication: 1
|
|
460
|
-
* })
|
|
461
|
-
*/
|
|
462
|
-
createRetentionPolicy(name: string, options: IRetentionOptions): Promise<void>;
|
|
463
|
-
/**
|
|
464
|
-
* Alters an existing retention policy on a database.
|
|
465
|
-
*
|
|
466
|
-
* @param {String} name The retention policy name
|
|
467
|
-
* @param {Object} options
|
|
468
|
-
* @param {String} [options.database] Database to create the policy on,
|
|
469
|
-
* uses the default database if not provided.
|
|
470
|
-
* @param {String} options.duration How long data in the retention policy
|
|
471
|
-
* should be stored for, should be in a format like `7d`. See details
|
|
472
|
-
* [here](https://docs.influxdata.com/influxdb/v1.0/query_language/spec/#durations)
|
|
473
|
-
* @param {Number} options.replication How many servers data in the series
|
|
474
|
-
* should be replicated to.
|
|
475
|
-
* @param {Boolean} [options.default] Whether the retention policy should
|
|
476
|
-
* be the default policy on the database.
|
|
477
|
-
* @return {Promise<void>}
|
|
478
|
-
* @example
|
|
479
|
-
* influx.alterRetentionPolicy('7d', {
|
|
480
|
-
* duration: '7d',
|
|
481
|
-
* replication: 1,
|
|
482
|
-
* default: true
|
|
483
|
-
* })
|
|
484
|
-
*/
|
|
485
|
-
alterRetentionPolicy(name: string, options: IRetentionOptions): Promise<void>;
|
|
486
|
-
/**
|
|
487
|
-
* Deletes a retention policy and associated data. Note that the data will
|
|
488
|
-
* not be immediately destroyed, and will hang around until Influx's
|
|
489
|
-
* bi-hourly cron.
|
|
490
|
-
*
|
|
491
|
-
* @param {String} name The retention policy name
|
|
492
|
-
* @param {String} [database] Database name that the policy lives in,
|
|
493
|
-
* uses the default database if not provided.
|
|
494
|
-
* @return {Promise<void>}
|
|
495
|
-
* @example
|
|
496
|
-
* influx.dropRetentionPolicy('7d')
|
|
497
|
-
*/
|
|
498
|
-
dropRetentionPolicy(name: string, database?: string): Promise<void>;
|
|
499
|
-
/**
|
|
500
|
-
* Shows retention policies on the database
|
|
501
|
-
*
|
|
502
|
-
* @param {String} [database] The database to list policies on, uses the
|
|
503
|
-
* default database if not provided.
|
|
504
|
-
* @return {Promise<Array<{
|
|
505
|
-
* name: String,
|
|
506
|
-
* duration: String,
|
|
507
|
-
* shardGroupDuration: String,
|
|
508
|
-
* replicaN: Number,
|
|
509
|
-
* default: Boolean
|
|
510
|
-
* }>>}
|
|
511
|
-
* @example
|
|
512
|
-
* influx.showRetentionPolicies().then(policies => {
|
|
513
|
-
* expect(policies.slice()).to.deep.equal([
|
|
514
|
-
* {
|
|
515
|
-
* name: 'autogen',
|
|
516
|
-
* duration: '0s',
|
|
517
|
-
* shardGroupDuration: '168h0m0s',
|
|
518
|
-
* replicaN: 1,
|
|
519
|
-
* default: true,
|
|
520
|
-
* },
|
|
521
|
-
* {
|
|
522
|
-
* name: '7d',
|
|
523
|
-
* duration: '168h0m0s',
|
|
524
|
-
* shardGroupDuration: '24h0m0s',
|
|
525
|
-
* replicaN: 1,
|
|
526
|
-
* default: false,
|
|
527
|
-
* },
|
|
528
|
-
* ])
|
|
529
|
-
* })
|
|
530
|
-
*/
|
|
531
|
-
showRetentionPolicies(database?: string): Promise<{
|
|
532
|
-
default: boolean;
|
|
533
|
-
duration: string;
|
|
534
|
-
name: string;
|
|
535
|
-
replicaN: number;
|
|
536
|
-
shardGroupDuration: string;
|
|
537
|
-
}[]>;
|
|
538
|
-
/**
|
|
539
|
-
* writePoints sends a list of points together in a batch to InfluxDB. In
|
|
540
|
-
* each point you must specify the measurement name to write into as well
|
|
541
|
-
* as a list of tag and field values. Optionally, you can specify the
|
|
542
|
-
* time to tag that point at, defaulting to the current time.
|
|
543
|
-
*
|
|
544
|
-
* If you defined a schema for the measurement in the options you passed
|
|
545
|
-
* to `new Influx(options)`, we'll use that to make sure that types get
|
|
546
|
-
* cast correctly and that there are no extraneous fields or columns.
|
|
547
|
-
*
|
|
548
|
-
* For best performance, it's recommended that you batch your data into
|
|
549
|
-
* sets of a couple thousand records before writing it. In the future we'll
|
|
550
|
-
* have some utilities within node-influx to make this easier.
|
|
551
|
-
*
|
|
552
|
-
* ---
|
|
553
|
-
*
|
|
554
|
-
* A note when using manually-specified times and precisions: by default
|
|
555
|
-
* we write using the `ms` precision since that's what JavaScript gives us.
|
|
556
|
-
* You can adjust this. However, there is some special behaviour if you
|
|
557
|
-
* manually specify a timestamp in your points:
|
|
558
|
-
* - if you specify the timestamp as a Date object, we'll convert it to
|
|
559
|
-
* milliseconds and manipulate it as needed to get the right precision
|
|
560
|
-
* - if provide a INanoDate as returned from {@link toNanoTime} or the
|
|
561
|
-
* results from an Influx query, we'll be able to pull the precise
|
|
562
|
-
* nanosecond timestamp and manipulate it to get the right precision
|
|
563
|
-
* - if you provide a string or number as the timestamp, we'll pass it
|
|
564
|
-
* straight into Influx.
|
|
565
|
-
*
|
|
566
|
-
* Please see the IPoint and IWriteOptions types for a
|
|
567
|
-
* full list of possible options.
|
|
568
|
-
*
|
|
569
|
-
* @param {IPoint[]} points
|
|
570
|
-
* @param {IWriteOptions} [options]
|
|
571
|
-
* @return {Promise<void>}
|
|
572
|
-
* @example
|
|
573
|
-
* // write a point into the default database with
|
|
574
|
-
* // the default retention policy.
|
|
575
|
-
* influx.writePoints([
|
|
576
|
-
* {
|
|
577
|
-
* measurement: 'perf',
|
|
578
|
-
* tags: { host: 'box1.example.com' },
|
|
579
|
-
* fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
|
580
|
-
* }
|
|
581
|
-
* ])
|
|
582
|
-
*
|
|
583
|
-
* // you can manually specify the database,
|
|
584
|
-
* // retention policy, and time precision:
|
|
585
|
-
* influx.writePoints([
|
|
586
|
-
* {
|
|
587
|
-
* measurement: 'perf',
|
|
588
|
-
* tags: { host: 'box1.example.com' },
|
|
589
|
-
* fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
|
590
|
-
* timestamp: getLastRecordedTime(),
|
|
591
|
-
* }
|
|
592
|
-
* ], {
|
|
593
|
-
* database: 'my_db',
|
|
594
|
-
* retentionPolicy: '1d',
|
|
595
|
-
* precision: 's'
|
|
596
|
-
* })
|
|
597
|
-
*/
|
|
598
|
-
writePoints(points: IPoint[], options?: IWriteOptions): Promise<void>;
|
|
599
|
-
/**
|
|
600
|
-
* writeMeasurement functions similarly to {@link InfluxDB#writePoints}, but
|
|
601
|
-
* it automatically fills in the `measurement` value for all points for you.
|
|
602
|
-
*
|
|
603
|
-
* @param {String} measurement
|
|
604
|
-
* @param {IPoint[]} points
|
|
605
|
-
* @param {IWriteOptions} [options]
|
|
606
|
-
* @return {Promise<void>}
|
|
607
|
-
* @example
|
|
608
|
-
* influx.writeMeasurement('perf', [
|
|
609
|
-
* {
|
|
610
|
-
* tags: { host: 'box1.example.com' },
|
|
611
|
-
* fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
|
612
|
-
* }
|
|
613
|
-
* ])
|
|
614
|
-
*/
|
|
615
|
-
writeMeasurement(measurement: string, points: IPoint[], options?: IWriteOptions): Promise<void>;
|
|
616
|
-
query<T>(query: string[], options?: IQueryOptions): Promise<IResults<T>[]>;
|
|
617
|
-
query<T>(query: string, options?: IQueryOptions): Promise<IResults<T>>;
|
|
618
|
-
/**
|
|
619
|
-
* queryRaw functions similarly to .query() but it does no fancy
|
|
620
|
-
* transformations on the returned data; it calls `JSON.parse` and returns
|
|
621
|
-
* those results verbatim.
|
|
622
|
-
*
|
|
623
|
-
* @param {String|String[]} query
|
|
624
|
-
* @param {IQueryOptions} [options]
|
|
625
|
-
* @return {Promise<*>}
|
|
626
|
-
* @example
|
|
627
|
-
* influx.queryRaw('select * from perf').then(rawData => {
|
|
628
|
-
* console.log(rawData)
|
|
629
|
-
* })
|
|
630
|
-
*/
|
|
631
|
-
queryRaw<T>(query: string | string[], options?: IQueryOptions): Promise<any>;
|
|
632
|
-
/**
|
|
633
|
-
* Pings all available hosts, collecting online status and version info.
|
|
634
|
-
* @param {Number} timeout Given in milliseconds
|
|
635
|
-
* @return {Promise<IPingStats[]>}
|
|
636
|
-
* @example
|
|
637
|
-
* influx.ping(5000).then(hosts => {
|
|
638
|
-
* hosts.forEach(host => {
|
|
639
|
-
* if (host.online) {
|
|
640
|
-
* console.log(`${host.url.host} responded in ${host.rtt}ms running ${host.version})`)
|
|
641
|
-
* } else {
|
|
642
|
-
* console.log(`${host.url.host} is offline :(`)
|
|
643
|
-
* }
|
|
644
|
-
* })
|
|
645
|
-
* })
|
|
646
|
-
*/
|
|
647
|
-
ping(timeout: number): Promise<IPingStats[]>;
|
|
648
|
-
/**
|
|
649
|
-
* Returns the default database that queries operates on. It throws if called
|
|
650
|
-
* when a default database isn't set.
|
|
651
|
-
* @private
|
|
652
|
-
*/
|
|
653
|
-
private defaultDB();
|
|
654
|
-
/**
|
|
655
|
-
* Creates options to be passed into the pool to query databases.
|
|
656
|
-
* @private
|
|
657
|
-
*/
|
|
658
|
-
private getQueryOpts(params, method?);
|
|
659
|
-
}
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { RequestOptions } from 'https';
|
|
3
|
+
import * as b from './builder';
|
|
4
|
+
import * as grammar from './grammar';
|
|
5
|
+
import { IPingStats, IPoolOptions } from './pool';
|
|
6
|
+
import { IResults } from './results';
|
|
7
|
+
import { ISchemaOptions } from './schema';
|
|
8
|
+
export * from './builder';
|
|
9
|
+
export { INanoDate, FieldType, Precision, Raw, TimePrecision, escape, toNanoDate } from './grammar';
|
|
10
|
+
export { ISchemaOptions } from './schema';
|
|
11
|
+
export { IPingStats, IPoolOptions } from './pool';
|
|
12
|
+
export { IResults, IResponse, ResultError } from './results';
|
|
13
|
+
export interface IHostConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Influx host to connect to, defaults to 127.0.0.1.
|
|
16
|
+
*/
|
|
17
|
+
host: string;
|
|
18
|
+
/**
|
|
19
|
+
* Influx port to connect to, defaults to 8086.
|
|
20
|
+
*/
|
|
21
|
+
port?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Protocol to connect over, defaults to 'http'.
|
|
24
|
+
*/
|
|
25
|
+
protocol?: 'http' | 'https';
|
|
26
|
+
/**
|
|
27
|
+
* Optional request option overrides.
|
|
28
|
+
*/
|
|
29
|
+
options?: RequestOptions;
|
|
30
|
+
}
|
|
31
|
+
export interface ISingleHostConfig extends IHostConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Username for connecting to the database. Defaults to 'root'.
|
|
34
|
+
*/
|
|
35
|
+
username?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Password for connecting to the database. Defaults to 'root'.
|
|
38
|
+
*/
|
|
39
|
+
password?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Default database to write information to.
|
|
42
|
+
*/
|
|
43
|
+
database?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Settings for the connection pool.
|
|
46
|
+
*/
|
|
47
|
+
pool?: IPoolOptions;
|
|
48
|
+
/**
|
|
49
|
+
* A list of schema for measurements in the database.
|
|
50
|
+
*/
|
|
51
|
+
schema?: ISchemaOptions[];
|
|
52
|
+
}
|
|
53
|
+
export interface IClusterConfig {
|
|
54
|
+
/**
|
|
55
|
+
* Username for connecting to the database. Defaults to 'root'.
|
|
56
|
+
*/
|
|
57
|
+
username?: string;
|
|
58
|
+
/**
|
|
59
|
+
* Password for connecting to the database. Defaults to 'root'.
|
|
60
|
+
*/
|
|
61
|
+
password?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Default database to write information to.
|
|
64
|
+
*/
|
|
65
|
+
database?: string;
|
|
66
|
+
/**
|
|
67
|
+
* A list of cluster hosts to connect to.
|
|
68
|
+
*/
|
|
69
|
+
hosts: IHostConfig[];
|
|
70
|
+
/**
|
|
71
|
+
* Settings for the connection pool.
|
|
72
|
+
*/
|
|
73
|
+
pool?: IPoolOptions;
|
|
74
|
+
/**
|
|
75
|
+
* A list of schema for measurements in the database.
|
|
76
|
+
*/
|
|
77
|
+
schema?: ISchemaOptions[];
|
|
78
|
+
}
|
|
79
|
+
export interface IPoint {
|
|
80
|
+
/**
|
|
81
|
+
* Measurement is the Influx measurement name.
|
|
82
|
+
*/
|
|
83
|
+
measurement?: string;
|
|
84
|
+
/**
|
|
85
|
+
* Tags is the list of tag values to insert.
|
|
86
|
+
*/
|
|
87
|
+
tags?: {
|
|
88
|
+
[name: string]: string;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Fields is the list of field values to insert.
|
|
92
|
+
*/
|
|
93
|
+
fields?: {
|
|
94
|
+
[name: string]: any;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Timestamp tags this measurement with a date. This can be a Date object,
|
|
98
|
+
* in which case we'll adjust it to the desired precision, or a numeric
|
|
99
|
+
* string or number, in which case it gets passed directly to Influx.
|
|
100
|
+
*/
|
|
101
|
+
timestamp?: Date | string | number;
|
|
102
|
+
}
|
|
103
|
+
export interface IWriteOptions {
|
|
104
|
+
/**
|
|
105
|
+
* Precision at which the points are written, defaults to nanoseconds 'n'.
|
|
106
|
+
*/
|
|
107
|
+
precision?: grammar.TimePrecision;
|
|
108
|
+
/**
|
|
109
|
+
* Retention policy to write the points under, defaults to the DEFAULT
|
|
110
|
+
* database policy.
|
|
111
|
+
*/
|
|
112
|
+
retentionPolicy?: string;
|
|
113
|
+
/**
|
|
114
|
+
* Database under which to write the points. This is required if a default
|
|
115
|
+
* database is not provided in Influx.
|
|
116
|
+
*/
|
|
117
|
+
database?: string;
|
|
118
|
+
}
|
|
119
|
+
export interface IQueryOptions {
|
|
120
|
+
/**
|
|
121
|
+
* Defines the precision at which to query points. When left blank, it will
|
|
122
|
+
* query in nanosecond precision.
|
|
123
|
+
*/
|
|
124
|
+
precision?: grammar.TimePrecision;
|
|
125
|
+
/**
|
|
126
|
+
* Retention policy to query from, defaults to the DEFAULT
|
|
127
|
+
* database policy.
|
|
128
|
+
*/
|
|
129
|
+
retentionPolicy?: string;
|
|
130
|
+
/**
|
|
131
|
+
* Database under which to query the points. This is required if a default
|
|
132
|
+
* database is not provided in Influx.
|
|
133
|
+
*/
|
|
134
|
+
database?: string;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* IRetentionOptions are passed into passed into the {@link
|
|
138
|
+
* InfluxDB#createRetentionPolicy} and {@link InfluxDB#alterRetentionPolicy}.
|
|
139
|
+
* See the [Downsampling and Retention page](https://docs.influxdata.com/
|
|
140
|
+
* influxdb/v1.0/guides/downsampling_and_retention/) on the Influx docs for
|
|
141
|
+
* more information.
|
|
142
|
+
*/
|
|
143
|
+
export interface IRetentionOptions {
|
|
144
|
+
database?: string;
|
|
145
|
+
duration: string;
|
|
146
|
+
replication: number;
|
|
147
|
+
isDefault?: boolean;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* InfluxDB is the public interface to run queries against the your database.
|
|
151
|
+
* This is a 'driver-level' module, not a a full-fleged ORM or ODM; you run
|
|
152
|
+
* queries directly by calling methods on this class.
|
|
153
|
+
*
|
|
154
|
+
* Please check out some of [the tutorials](https://node-influx.github.io/manual/tutorial.html)
|
|
155
|
+
* if you want help getting started!
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* const Influx = require('influx');
|
|
159
|
+
* const influx = new Influx.InfluxDB({
|
|
160
|
+
* host: 'localhost',
|
|
161
|
+
* database: 'express_response_db',
|
|
162
|
+
* schema: [
|
|
163
|
+
* {
|
|
164
|
+
* measurement: 'response_times',
|
|
165
|
+
* fields: {
|
|
166
|
+
* path: Influx.FieldType.STRING,
|
|
167
|
+
* duration: Influx.FieldType.INTEGER
|
|
168
|
+
* },
|
|
169
|
+
* tags: [
|
|
170
|
+
* 'host'
|
|
171
|
+
* ]
|
|
172
|
+
* }
|
|
173
|
+
* ]
|
|
174
|
+
* })
|
|
175
|
+
*
|
|
176
|
+
* influx.writePoints([
|
|
177
|
+
* {
|
|
178
|
+
* measurement: 'response_times',
|
|
179
|
+
* tags: { host: os.hostname() },
|
|
180
|
+
* fields: { duration, path: req.path },
|
|
181
|
+
* }
|
|
182
|
+
* ]).then(() => {
|
|
183
|
+
* return influx.query(`
|
|
184
|
+
* select * from response_times
|
|
185
|
+
* where host = ${Influx.escape.stringLit(os.hostname())}
|
|
186
|
+
* order by time desc
|
|
187
|
+
* limit 10
|
|
188
|
+
* `)
|
|
189
|
+
* }).then(rows => {
|
|
190
|
+
* rows.forEach(row => console.log(`A request to ${row.path} took ${row.duration}ms`))
|
|
191
|
+
* })
|
|
192
|
+
*/
|
|
193
|
+
export declare class InfluxDB {
|
|
194
|
+
/**
|
|
195
|
+
* Connect pool for making requests.
|
|
196
|
+
* @private
|
|
197
|
+
*/
|
|
198
|
+
private pool;
|
|
199
|
+
/**
|
|
200
|
+
* Config options for Influx.
|
|
201
|
+
* @private
|
|
202
|
+
*/
|
|
203
|
+
private options;
|
|
204
|
+
/**
|
|
205
|
+
* Map of Schema instances defining measurements in Influx.
|
|
206
|
+
* @private
|
|
207
|
+
*/
|
|
208
|
+
private schema;
|
|
209
|
+
constructor(options: ISingleHostConfig);
|
|
210
|
+
/**
|
|
211
|
+
* Connect to an InfluxDB cluster by specifying a
|
|
212
|
+
* set of connection options.
|
|
213
|
+
*/
|
|
214
|
+
constructor(options: IClusterConfig);
|
|
215
|
+
/**
|
|
216
|
+
* Connect to an InfluxDB instance using a configuration URL.
|
|
217
|
+
* @example
|
|
218
|
+
* new InfluxDB('http://user:password@host:8086/database')
|
|
219
|
+
*/
|
|
220
|
+
constructor(url: string);
|
|
221
|
+
/**
|
|
222
|
+
* Connects to a local, default Influx instance.
|
|
223
|
+
*/
|
|
224
|
+
constructor();
|
|
225
|
+
/**
|
|
226
|
+
* Creates a new database with the provided name.
|
|
227
|
+
* @param {string} databaseName
|
|
228
|
+
* @return {Promise.<void>}
|
|
229
|
+
* @example
|
|
230
|
+
* influx.createDatabase('mydb')
|
|
231
|
+
*/
|
|
232
|
+
createDatabase(databaseName: string): Promise<void>;
|
|
233
|
+
/**
|
|
234
|
+
* Deletes a database with the provided name.
|
|
235
|
+
* @param {string} databaseName
|
|
236
|
+
* @return {Promise.<void>}
|
|
237
|
+
* @example
|
|
238
|
+
* influx.createDatabase('mydb')
|
|
239
|
+
*/
|
|
240
|
+
dropDatabase(databaseName: string): Promise<void>;
|
|
241
|
+
/**
|
|
242
|
+
* Returns array of database names. Requires cluster admin privileges.
|
|
243
|
+
* @returns {Promise<String[]>} a list of database names
|
|
244
|
+
* @example
|
|
245
|
+
* influx.getMeasurements().then(names =>
|
|
246
|
+
* console.log('My database names are: ' + names.join(', ')));
|
|
247
|
+
*/
|
|
248
|
+
getDatabaseNames(): Promise<string[]>;
|
|
249
|
+
/**
|
|
250
|
+
* Returns array of measurements.
|
|
251
|
+
* @returns {Promise<String[]>} a list of measurement names
|
|
252
|
+
* @param {String} [database] the database the measurement lives in, optional
|
|
253
|
+
* if a default database is provided.
|
|
254
|
+
* @example
|
|
255
|
+
* influx.getMeasurements().then(names =>
|
|
256
|
+
* console.log('My measurement names are: ' + names.join(', ')));
|
|
257
|
+
*/
|
|
258
|
+
getMeasurements(database?: string): Promise<string[]>;
|
|
259
|
+
/**
|
|
260
|
+
* Returns a list of all series within the target measurement, or from the
|
|
261
|
+
* entire database if a measurement isn't provided.
|
|
262
|
+
* @param {Object} [options]
|
|
263
|
+
* @param {String} [options.measurement] if provided, we'll only get series
|
|
264
|
+
* from within that measurement.
|
|
265
|
+
* @param {String} [options.database] the database the series lives in,
|
|
266
|
+
* optional if a default database is provided.
|
|
267
|
+
* @returns {Promise<String[]>} a list of series names
|
|
268
|
+
* @example
|
|
269
|
+
* influx.getSeries().then(names => {
|
|
270
|
+
* console.log('My series names in my_measurement are: ' + names.join(', '))
|
|
271
|
+
* })
|
|
272
|
+
*
|
|
273
|
+
* influx.getSeries({
|
|
274
|
+
* measurement: 'my_measurement',
|
|
275
|
+
* database: 'my_db'
|
|
276
|
+
* }).then(names => {
|
|
277
|
+
* console.log('My series names in my_measurement are: ' + names.join(', '))
|
|
278
|
+
* })
|
|
279
|
+
*/
|
|
280
|
+
getSeries(options?: {
|
|
281
|
+
measurement?: string;
|
|
282
|
+
database?: string;
|
|
283
|
+
}): Promise<string[]>;
|
|
284
|
+
/**
|
|
285
|
+
* Removes a measurement from the database.
|
|
286
|
+
* @param {String} measurement
|
|
287
|
+
* @param {String} [database] the database the measurement lives in, optional
|
|
288
|
+
* if a default database is provided.
|
|
289
|
+
* @return {Promise.<void>}
|
|
290
|
+
* @example
|
|
291
|
+
* influx.dropMeasurement('my_measurement')
|
|
292
|
+
*/
|
|
293
|
+
dropMeasurement(measurement: string, database?: string): Promise<void>;
|
|
294
|
+
/**
|
|
295
|
+
* Removes a one or more series from InfluxDB.
|
|
296
|
+
*
|
|
297
|
+
* @returns {Promise<void>}
|
|
298
|
+
* @example
|
|
299
|
+
* // The following pairs of queries are equivalent: you can chose either to
|
|
300
|
+
* // use our builder or pass in string directly. The builder takes care
|
|
301
|
+
* // of escaping and most syntax handling for you.
|
|
302
|
+
*
|
|
303
|
+
* influx.dropSeries({ where: e => e.tag('cpu').equals.value('cpu8') })
|
|
304
|
+
* influx.dropSeries({ where: '"cpu" = \'cpu8\'' })
|
|
305
|
+
* // DROP SERIES WHERE "cpu" = 'cpu8'
|
|
306
|
+
*
|
|
307
|
+
* influx.dropSeries({ measurement: m => m.name('cpu').policy('autogen') })
|
|
308
|
+
* influx.dropSeries({ measurement: '"cpu"."autogen"' })
|
|
309
|
+
* // DROP SERIES FROM "autogen"."cpu"
|
|
310
|
+
*
|
|
311
|
+
* influx.dropSeries({
|
|
312
|
+
* measurement: m => m.name('cpu').policy('autogen'),
|
|
313
|
+
* where: e => e.tag('cpu').equals.value('cpu8'),
|
|
314
|
+
* database: 'my_db'
|
|
315
|
+
* })
|
|
316
|
+
* // DROP SERIES FROM "autogen"."cpu" WHERE "cpu" = 'cpu8'
|
|
317
|
+
*/
|
|
318
|
+
dropSeries(options: b.measurement | b.where | {
|
|
319
|
+
database: string;
|
|
320
|
+
}): Promise<void>;
|
|
321
|
+
/**
|
|
322
|
+
* Returns a list of users on the Influx database.
|
|
323
|
+
* @return {Promise<Array<{ user: String, admin: Boolean }>>}
|
|
324
|
+
* @example
|
|
325
|
+
* influx.getUsers().then(users => {
|
|
326
|
+
* users.forEach(user => {
|
|
327
|
+
* if (user.admin) {
|
|
328
|
+
* console.log(user.user, 'is an admin!')
|
|
329
|
+
* } else {
|
|
330
|
+
* console.log(user.user, 'is not an admin!')
|
|
331
|
+
* }
|
|
332
|
+
* })
|
|
333
|
+
* })
|
|
334
|
+
*/
|
|
335
|
+
getUsers(): Promise<{
|
|
336
|
+
user: string;
|
|
337
|
+
admin: boolean;
|
|
338
|
+
}[]>;
|
|
339
|
+
/**
|
|
340
|
+
* Creates a new InfluxDB user.
|
|
341
|
+
* @param {String} username
|
|
342
|
+
* @param {String} password
|
|
343
|
+
* @param {Boolean} [admin=false] If true, the user will be given all
|
|
344
|
+
* privileges on all databases.
|
|
345
|
+
* @return {Promise<void>}
|
|
346
|
+
* @example
|
|
347
|
+
* influx.createUser('connor', 'pa55w0rd', true) // make 'connor' an admin
|
|
348
|
+
*
|
|
349
|
+
* // make non-admins:
|
|
350
|
+
* influx.createUser('not_admin', 'pa55w0rd')
|
|
351
|
+
*/
|
|
352
|
+
createUser(username: string, password: string, admin?: boolean): Promise<void>;
|
|
353
|
+
/**
|
|
354
|
+
* Sets a password for an Influx user.
|
|
355
|
+
* @param {String} username
|
|
356
|
+
* @param {String} password
|
|
357
|
+
* @return {Promise<void>}
|
|
358
|
+
* @example
|
|
359
|
+
* influx.setPassword('connor', 'pa55w0rd')
|
|
360
|
+
*/
|
|
361
|
+
setPassword(username: string, password: string): Promise<void>;
|
|
362
|
+
/**
|
|
363
|
+
* Grants a privilege to a specified user.
|
|
364
|
+
* @param {String} username
|
|
365
|
+
* @param {String} privilege Should be one of 'READ' or 'WRITE'
|
|
366
|
+
* @param {String} [database] If not provided, uses the default database.
|
|
367
|
+
* @return {Promise<void>}
|
|
368
|
+
* @example
|
|
369
|
+
* influx.grantPrivilege('connor', 'READ', 'my_db') // grants read access on my_db to connor
|
|
370
|
+
*/
|
|
371
|
+
grantPrivilege(username: string, privilege: 'READ' | 'WRITE', database?: string): Promise<void>;
|
|
372
|
+
/**
|
|
373
|
+
* Removes a privilege from a specified user.
|
|
374
|
+
* @param {String} username
|
|
375
|
+
* @param {String} privilege Should be one of 'READ' or 'WRITE'
|
|
376
|
+
* @param {String} [database] If not provided, uses the default database.
|
|
377
|
+
* @return {Promise<void>}
|
|
378
|
+
* @example
|
|
379
|
+
* influx.revokePrivilege('connor', 'READ', 'my_db') // removes read access on my_db from connor
|
|
380
|
+
*/
|
|
381
|
+
revokePrivilege(username: string, privilege: 'READ' | 'WRITE', database?: string): Promise<void>;
|
|
382
|
+
/**
|
|
383
|
+
* Grants admin privileges to a specified user.
|
|
384
|
+
* @param {String} username
|
|
385
|
+
* @return {Promise<void>}
|
|
386
|
+
* @example
|
|
387
|
+
* influx.grantAdminPrivilege('connor')
|
|
388
|
+
*/
|
|
389
|
+
grantAdminPrivilege(username: string): Promise<void>;
|
|
390
|
+
/**
|
|
391
|
+
* Removes a admin privilege from a specified user.
|
|
392
|
+
* @param {String} username
|
|
393
|
+
* @return {Promise<void>}
|
|
394
|
+
* @example
|
|
395
|
+
* influx.revokeAdminPrivilege('connor')
|
|
396
|
+
*/
|
|
397
|
+
revokeAdminPrivilege(username: string): Promise<void>;
|
|
398
|
+
/**
|
|
399
|
+
* Removes a user from the database.
|
|
400
|
+
* @param {String} username
|
|
401
|
+
* @return {Promise<void>}
|
|
402
|
+
* @example
|
|
403
|
+
* influx.dropUser('connor')
|
|
404
|
+
*/
|
|
405
|
+
dropUser(username: string): Promise<void>;
|
|
406
|
+
/**
|
|
407
|
+
* Creates a continuous query in a database
|
|
408
|
+
* @param {String} name The query name, for later reference
|
|
409
|
+
* @param {String} query The body of the query to run
|
|
410
|
+
* @param {String} [database] If not provided, uses the default database.
|
|
411
|
+
* @return {Promise<void>}
|
|
412
|
+
* @example
|
|
413
|
+
* influx.createContinuousQuery('downsample_cpu_1h', `
|
|
414
|
+
* SELECT MEAN(cpu) INTO "7d"."perf"
|
|
415
|
+
* FROM "1d"."perf" GROUP BY time(1m)
|
|
416
|
+
* `)
|
|
417
|
+
*/
|
|
418
|
+
createContinuousQuery(name: string, query: string, database?: string): Promise<void>;
|
|
419
|
+
/**
|
|
420
|
+
* Returns a list of continous queries in the database.
|
|
421
|
+
* @param {String} [database] If not provided, uses the default database.
|
|
422
|
+
* @return {Promise<void>}
|
|
423
|
+
* @example
|
|
424
|
+
* influx.showContinousQueries()
|
|
425
|
+
*/
|
|
426
|
+
showContinousQueries(database?: string): Promise<IResults<{
|
|
427
|
+
name: string;
|
|
428
|
+
query: string;
|
|
429
|
+
}>>;
|
|
430
|
+
/**
|
|
431
|
+
* Creates a continuous query in a database
|
|
432
|
+
* @param {String} name The query name
|
|
433
|
+
* @param {String} [database] If not provided, uses the default database.
|
|
434
|
+
* @return {Promise<void>}
|
|
435
|
+
* @example
|
|
436
|
+
* influx.dropContinuousQuery('downsample_cpu_1h')
|
|
437
|
+
*/
|
|
438
|
+
dropContinuousQuery(name: string, database?: string): Promise<void>;
|
|
439
|
+
/**
|
|
440
|
+
* Creates a new retention policy on a database. You can read more about
|
|
441
|
+
* [Downsampling and Retention](https://docs.influxdata.com/influxdb/v1.0/
|
|
442
|
+
* guides/downsampling_and_retention/) on the InfluxDB website.
|
|
443
|
+
*
|
|
444
|
+
* @param {String} name The retention policy name
|
|
445
|
+
* @param {Object} options
|
|
446
|
+
* @param {String} [options.database] Database to create the policy on,
|
|
447
|
+
* uses the default database if not provided.
|
|
448
|
+
* @param {String} options.duration How long data in the retention policy
|
|
449
|
+
* should be stored for, should be in a format like `7d`. See details
|
|
450
|
+
* [here](https://docs.influxdata.com/influxdb/v1.0/query_language/spec/#durations)
|
|
451
|
+
* @param {Number} options.replication How many servers data in the series
|
|
452
|
+
* should be replicated to.
|
|
453
|
+
* @param {Boolean} [options.isDefault] Whether the retention policy should
|
|
454
|
+
* be the default policy on the database.
|
|
455
|
+
* @return {Promise<void>}
|
|
456
|
+
* @example
|
|
457
|
+
* influx.createRetentionPolicy('7d', {
|
|
458
|
+
* duration: '7d',
|
|
459
|
+
* replication: 1
|
|
460
|
+
* })
|
|
461
|
+
*/
|
|
462
|
+
createRetentionPolicy(name: string, options: IRetentionOptions): Promise<void>;
|
|
463
|
+
/**
|
|
464
|
+
* Alters an existing retention policy on a database.
|
|
465
|
+
*
|
|
466
|
+
* @param {String} name The retention policy name
|
|
467
|
+
* @param {Object} options
|
|
468
|
+
* @param {String} [options.database] Database to create the policy on,
|
|
469
|
+
* uses the default database if not provided.
|
|
470
|
+
* @param {String} options.duration How long data in the retention policy
|
|
471
|
+
* should be stored for, should be in a format like `7d`. See details
|
|
472
|
+
* [here](https://docs.influxdata.com/influxdb/v1.0/query_language/spec/#durations)
|
|
473
|
+
* @param {Number} options.replication How many servers data in the series
|
|
474
|
+
* should be replicated to.
|
|
475
|
+
* @param {Boolean} [options.default] Whether the retention policy should
|
|
476
|
+
* be the default policy on the database.
|
|
477
|
+
* @return {Promise<void>}
|
|
478
|
+
* @example
|
|
479
|
+
* influx.alterRetentionPolicy('7d', {
|
|
480
|
+
* duration: '7d',
|
|
481
|
+
* replication: 1,
|
|
482
|
+
* default: true
|
|
483
|
+
* })
|
|
484
|
+
*/
|
|
485
|
+
alterRetentionPolicy(name: string, options: IRetentionOptions): Promise<void>;
|
|
486
|
+
/**
|
|
487
|
+
* Deletes a retention policy and associated data. Note that the data will
|
|
488
|
+
* not be immediately destroyed, and will hang around until Influx's
|
|
489
|
+
* bi-hourly cron.
|
|
490
|
+
*
|
|
491
|
+
* @param {String} name The retention policy name
|
|
492
|
+
* @param {String} [database] Database name that the policy lives in,
|
|
493
|
+
* uses the default database if not provided.
|
|
494
|
+
* @return {Promise<void>}
|
|
495
|
+
* @example
|
|
496
|
+
* influx.dropRetentionPolicy('7d')
|
|
497
|
+
*/
|
|
498
|
+
dropRetentionPolicy(name: string, database?: string): Promise<void>;
|
|
499
|
+
/**
|
|
500
|
+
* Shows retention policies on the database
|
|
501
|
+
*
|
|
502
|
+
* @param {String} [database] The database to list policies on, uses the
|
|
503
|
+
* default database if not provided.
|
|
504
|
+
* @return {Promise<Array<{
|
|
505
|
+
* name: String,
|
|
506
|
+
* duration: String,
|
|
507
|
+
* shardGroupDuration: String,
|
|
508
|
+
* replicaN: Number,
|
|
509
|
+
* default: Boolean
|
|
510
|
+
* }>>}
|
|
511
|
+
* @example
|
|
512
|
+
* influx.showRetentionPolicies().then(policies => {
|
|
513
|
+
* expect(policies.slice()).to.deep.equal([
|
|
514
|
+
* {
|
|
515
|
+
* name: 'autogen',
|
|
516
|
+
* duration: '0s',
|
|
517
|
+
* shardGroupDuration: '168h0m0s',
|
|
518
|
+
* replicaN: 1,
|
|
519
|
+
* default: true,
|
|
520
|
+
* },
|
|
521
|
+
* {
|
|
522
|
+
* name: '7d',
|
|
523
|
+
* duration: '168h0m0s',
|
|
524
|
+
* shardGroupDuration: '24h0m0s',
|
|
525
|
+
* replicaN: 1,
|
|
526
|
+
* default: false,
|
|
527
|
+
* },
|
|
528
|
+
* ])
|
|
529
|
+
* })
|
|
530
|
+
*/
|
|
531
|
+
showRetentionPolicies(database?: string): Promise<{
|
|
532
|
+
default: boolean;
|
|
533
|
+
duration: string;
|
|
534
|
+
name: string;
|
|
535
|
+
replicaN: number;
|
|
536
|
+
shardGroupDuration: string;
|
|
537
|
+
}[]>;
|
|
538
|
+
/**
|
|
539
|
+
* writePoints sends a list of points together in a batch to InfluxDB. In
|
|
540
|
+
* each point you must specify the measurement name to write into as well
|
|
541
|
+
* as a list of tag and field values. Optionally, you can specify the
|
|
542
|
+
* time to tag that point at, defaulting to the current time.
|
|
543
|
+
*
|
|
544
|
+
* If you defined a schema for the measurement in the options you passed
|
|
545
|
+
* to `new Influx(options)`, we'll use that to make sure that types get
|
|
546
|
+
* cast correctly and that there are no extraneous fields or columns.
|
|
547
|
+
*
|
|
548
|
+
* For best performance, it's recommended that you batch your data into
|
|
549
|
+
* sets of a couple thousand records before writing it. In the future we'll
|
|
550
|
+
* have some utilities within node-influx to make this easier.
|
|
551
|
+
*
|
|
552
|
+
* ---
|
|
553
|
+
*
|
|
554
|
+
* A note when using manually-specified times and precisions: by default
|
|
555
|
+
* we write using the `ms` precision since that's what JavaScript gives us.
|
|
556
|
+
* You can adjust this. However, there is some special behaviour if you
|
|
557
|
+
* manually specify a timestamp in your points:
|
|
558
|
+
* - if you specify the timestamp as a Date object, we'll convert it to
|
|
559
|
+
* milliseconds and manipulate it as needed to get the right precision
|
|
560
|
+
* - if provide a INanoDate as returned from {@link toNanoTime} or the
|
|
561
|
+
* results from an Influx query, we'll be able to pull the precise
|
|
562
|
+
* nanosecond timestamp and manipulate it to get the right precision
|
|
563
|
+
* - if you provide a string or number as the timestamp, we'll pass it
|
|
564
|
+
* straight into Influx.
|
|
565
|
+
*
|
|
566
|
+
* Please see the IPoint and IWriteOptions types for a
|
|
567
|
+
* full list of possible options.
|
|
568
|
+
*
|
|
569
|
+
* @param {IPoint[]} points
|
|
570
|
+
* @param {IWriteOptions} [options]
|
|
571
|
+
* @return {Promise<void>}
|
|
572
|
+
* @example
|
|
573
|
+
* // write a point into the default database with
|
|
574
|
+
* // the default retention policy.
|
|
575
|
+
* influx.writePoints([
|
|
576
|
+
* {
|
|
577
|
+
* measurement: 'perf',
|
|
578
|
+
* tags: { host: 'box1.example.com' },
|
|
579
|
+
* fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
|
580
|
+
* }
|
|
581
|
+
* ])
|
|
582
|
+
*
|
|
583
|
+
* // you can manually specify the database,
|
|
584
|
+
* // retention policy, and time precision:
|
|
585
|
+
* influx.writePoints([
|
|
586
|
+
* {
|
|
587
|
+
* measurement: 'perf',
|
|
588
|
+
* tags: { host: 'box1.example.com' },
|
|
589
|
+
* fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
|
590
|
+
* timestamp: getLastRecordedTime(),
|
|
591
|
+
* }
|
|
592
|
+
* ], {
|
|
593
|
+
* database: 'my_db',
|
|
594
|
+
* retentionPolicy: '1d',
|
|
595
|
+
* precision: 's'
|
|
596
|
+
* })
|
|
597
|
+
*/
|
|
598
|
+
writePoints(points: IPoint[], options?: IWriteOptions): Promise<void>;
|
|
599
|
+
/**
|
|
600
|
+
* writeMeasurement functions similarly to {@link InfluxDB#writePoints}, but
|
|
601
|
+
* it automatically fills in the `measurement` value for all points for you.
|
|
602
|
+
*
|
|
603
|
+
* @param {String} measurement
|
|
604
|
+
* @param {IPoint[]} points
|
|
605
|
+
* @param {IWriteOptions} [options]
|
|
606
|
+
* @return {Promise<void>}
|
|
607
|
+
* @example
|
|
608
|
+
* influx.writeMeasurement('perf', [
|
|
609
|
+
* {
|
|
610
|
+
* tags: { host: 'box1.example.com' },
|
|
611
|
+
* fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
|
612
|
+
* }
|
|
613
|
+
* ])
|
|
614
|
+
*/
|
|
615
|
+
writeMeasurement(measurement: string, points: IPoint[], options?: IWriteOptions): Promise<void>;
|
|
616
|
+
query<T>(query: string[], options?: IQueryOptions): Promise<IResults<T>[]>;
|
|
617
|
+
query<T>(query: string, options?: IQueryOptions): Promise<IResults<T>>;
|
|
618
|
+
/**
|
|
619
|
+
* queryRaw functions similarly to .query() but it does no fancy
|
|
620
|
+
* transformations on the returned data; it calls `JSON.parse` and returns
|
|
621
|
+
* those results verbatim.
|
|
622
|
+
*
|
|
623
|
+
* @param {String|String[]} query
|
|
624
|
+
* @param {IQueryOptions} [options]
|
|
625
|
+
* @return {Promise<*>}
|
|
626
|
+
* @example
|
|
627
|
+
* influx.queryRaw('select * from perf').then(rawData => {
|
|
628
|
+
* console.log(rawData)
|
|
629
|
+
* })
|
|
630
|
+
*/
|
|
631
|
+
queryRaw<T>(query: string | string[], options?: IQueryOptions): Promise<any>;
|
|
632
|
+
/**
|
|
633
|
+
* Pings all available hosts, collecting online status and version info.
|
|
634
|
+
* @param {Number} timeout Given in milliseconds
|
|
635
|
+
* @return {Promise<IPingStats[]>}
|
|
636
|
+
* @example
|
|
637
|
+
* influx.ping(5000).then(hosts => {
|
|
638
|
+
* hosts.forEach(host => {
|
|
639
|
+
* if (host.online) {
|
|
640
|
+
* console.log(`${host.url.host} responded in ${host.rtt}ms running ${host.version})`)
|
|
641
|
+
* } else {
|
|
642
|
+
* console.log(`${host.url.host} is offline :(`)
|
|
643
|
+
* }
|
|
644
|
+
* })
|
|
645
|
+
* })
|
|
646
|
+
*/
|
|
647
|
+
ping(timeout: number): Promise<IPingStats[]>;
|
|
648
|
+
/**
|
|
649
|
+
* Returns the default database that queries operates on. It throws if called
|
|
650
|
+
* when a default database isn't set.
|
|
651
|
+
* @private
|
|
652
|
+
*/
|
|
653
|
+
private defaultDB();
|
|
654
|
+
/**
|
|
655
|
+
* Creates options to be passed into the pool to query databases.
|
|
656
|
+
* @private
|
|
657
|
+
*/
|
|
658
|
+
private getQueryOpts(params, method?);
|
|
659
|
+
}
|