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