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 | * Path for Influx within the host, defaults to ''.
|
24 | * May be used if Influx is behind a reverse proxy or load balancer.
|
25 | */
|
26 | path?: string;
|
27 | /**
|
28 | * Protocol to connect over, defaults to 'http'.
|
29 | */
|
30 | protocol?: "http" | "https";
|
31 | /**
|
32 | * Optional request option overrides.
|
33 | */
|
34 | options?: RequestOptions;
|
35 | }
|
36 | export interface ISingleHostConfig extends IHostConfig {
|
37 | /**
|
38 | * Username for connecting to the database. Defaults to 'root'.
|
39 | */
|
40 | username?: string;
|
41 | /**
|
42 | * Password for connecting to the database. Defaults to 'root'.
|
43 | */
|
44 | password?: string;
|
45 | /**
|
46 | * Default database to write information to.
|
47 | */
|
48 | database?: string;
|
49 | /**
|
50 | * Settings for the connection pool.
|
51 | */
|
52 | pool?: IPoolOptions;
|
53 | /**
|
54 | * A list of schema for measurements in the database.
|
55 | */
|
56 | schema?: ISchemaOptions[];
|
57 | }
|
58 | export interface IClusterConfig {
|
59 | /**
|
60 | * Username for connecting to the database. Defaults to 'root'.
|
61 | */
|
62 | username?: string;
|
63 | /**
|
64 | * Password for connecting to the database. Defaults to 'root'.
|
65 | */
|
66 | password?: string;
|
67 | /**
|
68 | * Default database to write information to.
|
69 | */
|
70 | database?: string;
|
71 | /**
|
72 | * A list of cluster hosts to connect to.
|
73 | */
|
74 | hosts: IHostConfig[];
|
75 | /**
|
76 | * Settings for the connection pool.
|
77 | */
|
78 | pool?: IPoolOptions;
|
79 | /**
|
80 | * A list of schema for measurements in the database.
|
81 | */
|
82 | schema?: ISchemaOptions[];
|
83 | }
|
84 | export interface IPoint {
|
85 | /**
|
86 | * Measurement is the Influx measurement name.
|
87 | */
|
88 | measurement?: string;
|
89 | /**
|
90 | * Tags is the list of tag values to insert.
|
91 | */
|
92 | tags?: {
|
93 | [name: string]: string;
|
94 | };
|
95 | /**
|
96 | * Fields is the list of field values to insert.
|
97 | */
|
98 | fields?: {
|
99 | [name: string]: any;
|
100 | };
|
101 | /**
|
102 | * Timestamp tags this measurement with a date. This can be a Date object,
|
103 | * in which case we'll adjust it to the desired precision, or a numeric
|
104 | * string or number, in which case it gets passed directly to Influx.
|
105 | */
|
106 | timestamp?: Date | string | number;
|
107 | }
|
108 | export interface IParsedPoint extends IPoint {
|
109 | /**
|
110 | * Fields Pairs is the list of key/value pairs for each field on the point
|
111 | */
|
112 | fieldsPairs: Array<[string, string]>;
|
113 | /**
|
114 | * Tags Names is the list of tag names in the point
|
115 | */
|
116 | tagsNames: string[];
|
117 | /**
|
118 | * Casted Timestamp is the timestamp value after being casted to the
|
119 | * desired precision. Default 'n'
|
120 | */
|
121 | castedTimestamp?: string;
|
122 | }
|
123 | export interface IWriteOptions {
|
124 | /**
|
125 | * Precision at which the points are written, defaults to nanoseconds 'n'.
|
126 | */
|
127 | precision?: grammar.TimePrecision;
|
128 | /**
|
129 | * Retention policy to write the points under, defaults to the DEFAULT
|
130 | * database policy.
|
131 | */
|
132 | retentionPolicy?: string;
|
133 | /**
|
134 | * Database under which to write the points. This is required if a default
|
135 | * database is not provided in Influx.
|
136 | */
|
137 | database?: string;
|
138 | }
|
139 | export interface IQueryOptions {
|
140 | /**
|
141 | * Defines the precision at which to query points. When left blank, it will
|
142 | * query in nanosecond precision.
|
143 | */
|
144 | precision?: grammar.TimePrecision;
|
145 | /**
|
146 | * Retention policy to query from, defaults to the DEFAULT
|
147 | * database policy.
|
148 | */
|
149 | retentionPolicy?: string;
|
150 | /**
|
151 | * Database under which to query the points. This is required if a default
|
152 | * database is not provided in Influx.
|
153 | */
|
154 | database?: string;
|
155 | /**
|
156 | * Any placeholders used by the query. Using these is strongly recommended
|
157 | * to avoid injection attacks.
|
158 | */
|
159 | placeholders?: Record<string, string | number>;
|
160 | }
|
161 | export interface IParseOptions {
|
162 | /**
|
163 | * Precision at which the points are written, defaults to nanoseconds 'n'.
|
164 | */
|
165 | precision?: grammar.TimePrecision;
|
166 | /**
|
167 | * Database under which to write the points. This is required if a default
|
168 | * database is not provided in Influx.
|
169 | */
|
170 | database?: string;
|
171 | }
|
172 | /**
|
173 | * IRetentionOptions are passed into passed into the {@link
|
174 | * InfluxDB#createRetentionPolicy} and {@link InfluxDB#alterRetentionPolicy}.
|
175 | * See the [Downsampling and Retention page](https://docs.influxdata.com/
|
176 | * influxdb/v1.0/guides/downsampling_and_retention/) on the Influx docs for
|
177 | * more information.
|
178 | */
|
179 | export interface IRetentionOptions {
|
180 | database?: string;
|
181 | duration: string;
|
182 | replication: number;
|
183 | isDefault?: boolean;
|
184 | }
|
185 | /**
|
186 | * InfluxDB is the public interface to run queries against your database.
|
187 | * This is a 'driver-level' module, not a a full-fleged ORM or ODM; you run
|
188 | * queries directly by calling methods on this class.
|
189 | *
|
190 | * Please check out some of [the tutorials](https://node-influx.github.io/manual/tutorial.html)
|
191 | * if you want help getting started!
|
192 | *
|
193 | * @example
|
194 | * const Influx = require('influx');
|
195 | * const influx = new Influx.InfluxDB({
|
196 | * host: 'localhost',
|
197 | * database: 'express_response_db',
|
198 | * schema: [
|
199 | * {
|
200 | * measurement: 'response_times',
|
201 | * fields: {
|
202 | * path: Influx.FieldType.STRING,
|
203 | * duration: Influx.FieldType.INTEGER
|
204 | * },
|
205 | * tags: [
|
206 | * 'host'
|
207 | * ]
|
208 | * }
|
209 | * ]
|
210 | * })
|
211 | *
|
212 | * @example
|
213 | * // Connect over HTTPS
|
214 | * const Influx = require('influx');
|
215 | * const influx = new Influx.InfluxDB({
|
216 | * host: 'myinfluxdbhost',
|
217 | * port: 443,
|
218 | * protocol: 'https'
|
219 | * database: 'express_response_db',
|
220 | * schema: [
|
221 | * {
|
222 | * measurement: 'response_times',
|
223 | * fields: {
|
224 | * path: Influx.FieldType.STRING,
|
225 | * duration: Influx.FieldType.INTEGER
|
226 | * },
|
227 | * tags: [
|
228 | * 'host'
|
229 | * ]
|
230 | * }
|
231 | * ]
|
232 | * })
|
233 | *
|
234 | * influx.writePoints([
|
235 | * {
|
236 | * measurement: 'response_times',
|
237 | * tags: { host: os.hostname() },
|
238 | * fields: { duration, path: req.path },
|
239 | * }
|
240 | * ]).then(() => {
|
241 | * return influx.query(`
|
242 | * select * from response_times
|
243 | * where host = $<host>
|
244 | * order by time desc
|
245 | * limit 10
|
246 | * `, {
|
247 | * placeholders: {
|
248 | * host: os.hostname()
|
249 | * }
|
250 | * })
|
251 | * }).then(rows => {
|
252 | * rows.forEach(row => console.log(`A request to ${row.path} took ${row.duration}ms`))
|
253 | * })
|
254 | */
|
255 | export declare class InfluxDB {
|
256 | /**
|
257 | * Connect pool for making requests.
|
258 | * @private
|
259 | */
|
260 | private readonly _pool;
|
261 | /**
|
262 | * Config options for Influx.
|
263 | * @private
|
264 | */
|
265 | private readonly _options;
|
266 | /**
|
267 | * Map of Schema instances defining measurements in Influx.
|
268 | * @private
|
269 | */
|
270 | private _schema;
|
271 | constructor(options: ISingleHostConfig);
|
272 | /**
|
273 | * Connect to an InfluxDB cluster by specifying a
|
274 | * set of connection options.
|
275 | */
|
276 | constructor(options: IClusterConfig);
|
277 | /**
|
278 | * Connect to an InfluxDB instance using a configuration URL.
|
279 | * @example
|
280 | * new InfluxDB('http://user:password@host:8086/database')
|
281 | */
|
282 | constructor(url: string);
|
283 | /**
|
284 | * Connects to a local, default Influx instance.
|
285 | */
|
286 | constructor();
|
287 | /**
|
288 | * Adds specified schema for better fields coercing.
|
289 | *
|
290 | * @param {ISchemaOptions} schema
|
291 | * @memberof InfluxDB
|
292 | */
|
293 | addSchema(schema: ISchemaOptions): void;
|
294 | /**
|
295 | * Creates a new database with the provided name.
|
296 | * @param databaseName
|
297 | * @return
|
298 | * @example
|
299 | * influx.createDatabase('mydb')
|
300 | */
|
301 | createDatabase(databaseName: string): Promise<void>;
|
302 | /**
|
303 | * Deletes a database with the provided name.
|
304 | * @param databaseName
|
305 | * @return
|
306 | * @example
|
307 | * influx.dropDatabase('mydb')
|
308 | */
|
309 | dropDatabase(databaseName: string): Promise<void>;
|
310 | /**
|
311 | * Returns array of database names. Requires cluster admin privileges.
|
312 | * @returns a list of database names
|
313 | * @example
|
314 | * influx.getDatabaseNames().then(names =>
|
315 | * console.log('My database names are: ' + names.join(', ')));
|
316 | */
|
317 | getDatabaseNames(): Promise<string[]>;
|
318 | /**
|
319 | * Returns array of measurements.
|
320 | * @returns a list of measurement names
|
321 | * @param [database] the database the measurement lives in, optional
|
322 | * if a default database is provided.
|
323 | * @example
|
324 | * influx.getMeasurements().then(names =>
|
325 | * console.log('My measurement names are: ' + names.join(', ')));
|
326 | */
|
327 | getMeasurements(database?: string): Promise<string[]>;
|
328 | /**
|
329 | * Returns a list of all series within the target measurement, or from the
|
330 | * entire database if a measurement isn't provided.
|
331 | * @param [options]
|
332 | * @param [options.measurement] if provided, we'll only get series
|
333 | * from within that measurement.
|
334 | * @param [options.database] the database the series lives in,
|
335 | * optional if a default database is provided.
|
336 | * @returns a list of series names
|
337 | * @example
|
338 | * influx.getSeries().then(names => {
|
339 | * console.log('My series names in my_measurement are: ' + names.join(', '))
|
340 | * })
|
341 | *
|
342 | * influx.getSeries({
|
343 | * measurement: 'my_measurement',
|
344 | * database: 'my_db'
|
345 | * }).then(names => {
|
346 | * console.log('My series names in my_measurement are: ' + names.join(', '))
|
347 | * })
|
348 | */
|
349 | getSeries(options?: {
|
350 | measurement?: string;
|
351 | database?: string;
|
352 | }): Promise<string[]>;
|
353 | /**
|
354 | * Removes a measurement from the database.
|
355 | * @param measurement
|
356 | * @param [database] the database the measurement lives in, optional
|
357 | * if a default database is provided.
|
358 | * @return
|
359 | * @example
|
360 | * influx.dropMeasurement('my_measurement')
|
361 | */
|
362 | dropMeasurement(measurement: string, database?: string): Promise<void>;
|
363 | /**
|
364 | * Removes a one or more series from InfluxDB.
|
365 | *
|
366 | * @returns
|
367 | * @example
|
368 | * // The following pairs of queries are equivalent: you can chose either to
|
369 | * // use our builder or pass in string directly. The builder takes care
|
370 | * // of escaping and most syntax handling for you.
|
371 | *
|
372 | * influx.dropSeries({ where: e => e.tag('cpu').equals.value('cpu8') })
|
373 | * influx.dropSeries({ where: '"cpu" = \'cpu8\'' })
|
374 | * // DROP SERIES WHERE "cpu" = 'cpu8'
|
375 | *
|
376 | * influx.dropSeries({ measurement: m => m.name('cpu').policy('autogen') })
|
377 | * influx.dropSeries({ measurement: '"cpu"."autogen"' })
|
378 | * // DROP SERIES FROM "autogen"."cpu"
|
379 | *
|
380 | * influx.dropSeries({
|
381 | * measurement: m => m.name('cpu').policy('autogen'),
|
382 | * where: e => e.tag('cpu').equals.value('cpu8'),
|
383 | * database: 'my_db'
|
384 | * })
|
385 | * // DROP SERIES FROM "autogen"."cpu" WHERE "cpu" = 'cpu8'
|
386 | */
|
387 | dropSeries(options: b.measurement | b.where | {
|
388 | database: string;
|
389 | }): Promise<void>;
|
390 | /**
|
391 | * Returns a list of users on the Influx database.
|
392 | * @return
|
393 | * @example
|
394 | * influx.getUsers().then(users => {
|
395 | * users.forEach(user => {
|
396 | * if (user.admin) {
|
397 | * console.log(user.user, 'is an admin!')
|
398 | * } else {
|
399 | * console.log(user.user, 'is not an admin!')
|
400 | * }
|
401 | * })
|
402 | * })
|
403 | */
|
404 | getUsers(): Promise<IResults<{
|
405 | user: string;
|
406 | admin: boolean;
|
407 | }>>;
|
408 | /**
|
409 | * Creates a new InfluxDB user.
|
410 | * @param username
|
411 | * @param password
|
412 | * @param [admin=false] If true, the user will be given all
|
413 | * privileges on all databases.
|
414 | * @return
|
415 | * @example
|
416 | * influx.createUser('connor', 'pa55w0rd', true) // make 'connor' an admin
|
417 | *
|
418 | * // make non-admins:
|
419 | * influx.createUser('not_admin', 'pa55w0rd')
|
420 | */
|
421 | createUser(username: string, password: string, admin?: boolean): Promise<void>;
|
422 | /**
|
423 | * Sets a password for an Influx user.
|
424 | * @param username
|
425 | * @param password
|
426 | * @return
|
427 | * @example
|
428 | * influx.setPassword('connor', 'pa55w0rd')
|
429 | */
|
430 | setPassword(username: string, password: string): Promise<void>;
|
431 | /**
|
432 | * Grants a privilege to a specified user.
|
433 | * @param username
|
434 | * @param privilege Should be one of 'READ' or 'WRITE'
|
435 | * @param [database] If not provided, uses the default database.
|
436 | * @return
|
437 | * @example
|
438 | * influx.grantPrivilege('connor', 'READ', 'my_db') // grants read access on my_db to connor
|
439 | */
|
440 | grantPrivilege(username: string, privilege: "READ" | "WRITE", database?: string): Promise<void>;
|
441 | /**
|
442 | * Removes a privilege from a specified user.
|
443 | * @param username
|
444 | * @param privilege Should be one of 'READ' or 'WRITE'
|
445 | * @param [database] If not provided, uses the default database.
|
446 | * @return
|
447 | * @example
|
448 | * influx.revokePrivilege('connor', 'READ', 'my_db') // removes read access on my_db from connor
|
449 | */
|
450 | revokePrivilege(username: string, privilege: "READ" | "WRITE", database?: string): Promise<void>;
|
451 | /**
|
452 | * Grants admin privileges to a specified user.
|
453 | * @param username
|
454 | * @return
|
455 | * @example
|
456 | * influx.grantAdminPrivilege('connor')
|
457 | */
|
458 | grantAdminPrivilege(username: string): Promise<void>;
|
459 | /**
|
460 | * Removes a admin privilege from a specified user.
|
461 | * @param username
|
462 | * @return
|
463 | * @example
|
464 | * influx.revokeAdminPrivilege('connor')
|
465 | */
|
466 | revokeAdminPrivilege(username: string): Promise<void>;
|
467 | /**
|
468 | * Removes a user from the database.
|
469 | * @param username
|
470 | * @return
|
471 | * @example
|
472 | * influx.dropUser('connor')
|
473 | */
|
474 | dropUser(username: string): Promise<void>;
|
475 | /**
|
476 | * Creates a continuous query in a database
|
477 | * @param name The query name, for later reference
|
478 | * @param query The body of the query to run
|
479 | * @param [database] If not provided, uses the default database.
|
480 | * @param [resample] If provided, adds resample policy
|
481 | * @return
|
482 | * @example
|
483 | * influx.createContinuousQuery('downsample_cpu_1h', `
|
484 | * SELECT MEAN(cpu) INTO "7d"."perf"
|
485 | * FROM "1d"."perf" GROUP BY time(1m)
|
486 | * `, undefined, 'RESAMPLE FOR 7m')
|
487 | */
|
488 | createContinuousQuery(name: string, query: string, database?: string, resample?: string): Promise<void>;
|
489 | /**
|
490 | * Returns a list of continous queries in the database.
|
491 | * @param [database] If not provided, uses the default database.
|
492 | * @return
|
493 | * @example
|
494 | * influx.showContinousQueries()
|
495 | */
|
496 | showContinousQueries(database?: string): Promise<IResults<{
|
497 | name: string;
|
498 | query: string;
|
499 | }>>;
|
500 | /**
|
501 | * Creates a continuous query in a database
|
502 | * @param name The query name
|
503 | * @param [database] If not provided, uses the default database.
|
504 | * @return
|
505 | * @example
|
506 | * influx.dropContinuousQuery('downsample_cpu_1h')
|
507 | */
|
508 | dropContinuousQuery(name: string, database?: string): Promise<void>;
|
509 | /**
|
510 | * Creates a new retention policy on a database. You can read more about
|
511 | * [Downsampling and Retention](https://docs.influxdata.com/influxdb/v1.0/
|
512 | * guides/downsampling_and_retention/) on the InfluxDB website.
|
513 | *
|
514 | * @param name The retention policy name
|
515 | * @param options
|
516 | * @param [options.database] Database to create the policy on,
|
517 | * uses the default database if not provided.
|
518 | * @param options.duration How long data in the retention policy
|
519 | * should be stored for, should be in a format like `7d`. See details
|
520 | * [here](https://docs.influxdata.com/influxdb/v1.0/query_language/spec/#durations)
|
521 | * @param options.replication How many servers data in the series
|
522 | * should be replicated to.
|
523 | * @param [options.isDefault] Whether the retention policy should
|
524 | * be the default policy on the database.
|
525 | * @return
|
526 | * @example
|
527 | * influx.createRetentionPolicy('7d', {
|
528 | * duration: '7d',
|
529 | * replication: 1
|
530 | * })
|
531 | */
|
532 | createRetentionPolicy(name: string, options: IRetentionOptions): Promise<void>;
|
533 | /**
|
534 | * Alters an existing retention policy on a database.
|
535 | *
|
536 | * @param name The retention policy name
|
537 | * @param options
|
538 | * @param [options.database] Database to create the policy on,
|
539 | * uses the default database if not provided.
|
540 | * @param options.duration How long data in the retention policy
|
541 | * should be stored for, should be in a format like `7d`. See details
|
542 | * [here](https://docs.influxdata.com/influxdb/v1.0/query_language/spec/#durations)
|
543 | * @param options.replication How many servers data in the series
|
544 | * should be replicated to.
|
545 | * @param [options.default] Whether the retention policy should
|
546 | * be the default policy on the database.
|
547 | * @return
|
548 | * @example
|
549 | * influx.alterRetentionPolicy('7d', {
|
550 | * duration: '7d',
|
551 | * replication: 1,
|
552 | * default: true
|
553 | * })
|
554 | */
|
555 | alterRetentionPolicy(name: string, options: IRetentionOptions): Promise<void>;
|
556 | /**
|
557 | * Deletes a retention policy and associated data. Note that the data will
|
558 | * not be immediately destroyed, and will hang around until Influx's
|
559 | * bi-hourly cron.
|
560 | *
|
561 | * @param name The retention policy name
|
562 | * @param [database] Database name that the policy lives in,
|
563 | * uses the default database if not provided.
|
564 | * @return
|
565 | * @example
|
566 | * influx.dropRetentionPolicy('7d')
|
567 | */
|
568 | dropRetentionPolicy(name: string, database?: string): Promise<void>;
|
569 | /**
|
570 | * Shows retention policies on the database
|
571 | *
|
572 | * @param [database] The database to list policies on, uses the
|
573 | * default database if not provided.
|
574 | * @return
|
575 | * @example
|
576 | * influx.showRetentionPolicies().then(policies => {
|
577 | * expect(policies.slice()).to.deep.equal([
|
578 | * {
|
579 | * name: 'autogen',
|
580 | * duration: '0s',
|
581 | * shardGroupDuration: '168h0m0s',
|
582 | * replicaN: 1,
|
583 | * default: true,
|
584 | * },
|
585 | * {
|
586 | * name: '7d',
|
587 | * duration: '168h0m0s',
|
588 | * shardGroupDuration: '24h0m0s',
|
589 | * replicaN: 1,
|
590 | * default: false,
|
591 | * },
|
592 | * ])
|
593 | * })
|
594 | */
|
595 | showRetentionPolicies(database?: string): Promise<IResults<{
|
596 | default: boolean;
|
597 | duration: string;
|
598 | name: string;
|
599 | replicaN: number;
|
600 | shardGroupDuration: string;
|
601 | }>>;
|
602 | /**
|
603 | * Shows shards on the database
|
604 | *
|
605 | * @param [database] The database to list policies on, uses the
|
606 | * default database if not provided.
|
607 | * @return
|
608 | * @example
|
609 | * influx.showShards().then(shards => {
|
610 | * expect(shards.slice()).to.deep.equal([
|
611 | * {
|
612 | * id: 1
|
613 | * database: 'database',
|
614 | * retention_policy: 'autogen',
|
615 | * shard_group: 1,
|
616 | * start_time: '2019-05-06T00:00:00Z',
|
617 | * end_time: '2019-05-13T00:00:00Z',
|
618 | * expiry_time: '2019-05-13T00:00:00Z',
|
619 | * owners: null,
|
620 | * },
|
621 | * ])
|
622 | * })
|
623 | */
|
624 | showShards(database?: string): Promise<Array<{
|
625 | id: number;
|
626 | database: string;
|
627 | retention_policy: string;
|
628 | shard_group: number;
|
629 | start_time: string;
|
630 | end_time: string;
|
631 | expiry_time: string;
|
632 | owners: string;
|
633 | }>>;
|
634 | /**
|
635 | * Drops a shard with the provided number.
|
636 | * @param shard_id
|
637 | * @return
|
638 | * @example
|
639 | * influx.dropShard(3)
|
640 | */
|
641 | dropShard(shard_id: number): Promise<void>;
|
642 | /**
|
643 | * WritePoints sends a list of points together in a batch to InfluxDB. In
|
644 | * each point you must specify the measurement name to write into as well
|
645 | * as a list of tag and field values. Optionally, you can specify the
|
646 | * time to tag that point at, defaulting to the current time.
|
647 | *
|
648 | * If you defined a schema for the measurement in the options you passed
|
649 | * to `new Influx(options)`, we'll use that to make sure that types get
|
650 | * cast correctly and that there are no extraneous fields or columns.
|
651 | *
|
652 | * For best performance, it's recommended that you batch your data into
|
653 | * sets of a couple thousand records before writing it. In the future we'll
|
654 | * have some utilities within node-influx to make this easier.
|
655 | *
|
656 | * ---
|
657 | *
|
658 | * A note when using manually-specified times and precisions: by default
|
659 | * we write using the `ms` precision since that's what JavaScript gives us.
|
660 | * You can adjust this. However, there is some special behaviour if you
|
661 | * manually specify a timestamp in your points:
|
662 | * - if you specify the timestamp as a Date object, we'll convert it to
|
663 | * milliseconds and manipulate it as needed to get the right precision
|
664 | * - if provide a INanoDate as returned from {@link toNanoTime} or the
|
665 | * results from an Influx query, we'll be able to pull the precise
|
666 | * nanosecond timestamp and manipulate it to get the right precision
|
667 | * - if you provide a string or number as the timestamp, we'll pass it
|
668 | * straight into Influx.
|
669 | *
|
670 | * Please see the IPoint and IWriteOptions types for a
|
671 | * full list of possible options.
|
672 | *
|
673 | * @param points
|
674 | * @param [options]
|
675 | * @return
|
676 | * @example
|
677 | * // write a point into the default database with
|
678 | * // the default retention policy.
|
679 | * influx.writePoints([
|
680 | * {
|
681 | * measurement: 'perf',
|
682 | * tags: { host: 'box1.example.com' },
|
683 | * fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
684 | * }
|
685 | * ])
|
686 | *
|
687 | * // you can manually specify the database,
|
688 | * // retention policy, and time precision:
|
689 | * influx.writePoints([
|
690 | * {
|
691 | * measurement: 'perf',
|
692 | * tags: { host: 'box1.example.com' },
|
693 | * fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
694 | * timestamp: getLastRecordedTime(),
|
695 | * }
|
696 | * ], {
|
697 | * database: 'my_db',
|
698 | * retentionPolicy: '1d',
|
699 | * precision: 's'
|
700 | * })
|
701 | */
|
702 | writePoints(points: IPoint[], options?: IWriteOptions): Promise<void>;
|
703 | /**
|
704 | * ParsePoint will perform the coercions/schema checks and return the data
|
705 | * required for writing a point. This will throw an error if a schema check
|
706 | * or coercion fails. This can be useful for flagging or "throwing out" bad
|
707 | * points in a batch write to prevent the entire batch from getting aborted
|
708 | *
|
709 | * ---
|
710 | *
|
711 | * A note when using this function, {@link InfluxDB#writePoints} will still perform
|
712 | * the same checks, so any pre-processed data will be checked for validity twice which
|
713 | * has potential performance implications on large data sets
|
714 | *
|
715 | * @param point
|
716 | * @param [options]
|
717 | * @return
|
718 | * @example
|
719 | * // parse a point as if it is getting written to the default
|
720 | * // databse with the default time precision
|
721 | * influx.parsePoint({
|
722 | * measurement: 'perf',
|
723 | * tags: { host: 'box1.example.com' },
|
724 | * fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
725 | * })
|
726 | *
|
727 | * // you can manually specify the database and time precision
|
728 | * influx.parsePoint({
|
729 | * measurement: 'perf',
|
730 | * tags: { host: 'box1.example.com' },
|
731 | * fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
732 | * }, {
|
733 | * precision: 's',
|
734 | * database: 'my_db'
|
735 | * })
|
736 | *
|
737 | * // if an error occurs, you can catch the error with try...catch
|
738 | * try {
|
739 | * influx.parsePoint({
|
740 | * measurement: 'perf',
|
741 | * tags: { host: 'box1.example.com', myExtraneousTag: 'value' },
|
742 | * fields: { cpu: getCpuUsage(), mem: getMemUsage(), myExtraneousField: 'value' },
|
743 | * })
|
744 | * } catch(err) {
|
745 | * handleError(err);
|
746 | * }
|
747 | */
|
748 | parsePoint(point: IPoint, options?: IParseOptions): IParsedPoint;
|
749 | /**
|
750 | * WriteMeasurement functions similarly to {@link InfluxDB#writePoints}, but
|
751 | * it automatically fills in the `measurement` value for all points for you.
|
752 | *
|
753 | * @param measurement
|
754 | * @param points
|
755 | * @param [options]
|
756 | * @return
|
757 | * @example
|
758 | * influx.writeMeasurement('perf', [
|
759 | * {
|
760 | * tags: { host: 'box1.example.com' },
|
761 | * fields: { cpu: getCpuUsage(), mem: getMemUsage() },
|
762 | * }
|
763 | * ])
|
764 | */
|
765 | writeMeasurement(measurement: string, points: IPoint[], options?: IWriteOptions): Promise<void>;
|
766 | query<T>(query: string[], options?: IQueryOptions): Promise<Array<IResults<T>>>;
|
767 | query<T>(query: string, options?: IQueryOptions): Promise<IResults<T>>;
|
768 | /**
|
769 | * QueryRaw functions similarly to .query() but it does no fancy
|
770 | * transformations on the returned data; it calls `JSON.parse` and returns
|
771 | * those results verbatim.
|
772 | *
|
773 | * @param query
|
774 | * @param [options]
|
775 | * @return
|
776 | * @example
|
777 | * influx.queryRaw('select * from perf').then(rawData => {
|
778 | * console.log(rawData)
|
779 | * })
|
780 | */
|
781 | queryRaw(query: string | string[], options?: IQueryOptions): Promise<any>;
|
782 | /**
|
783 | * Pings all available hosts, collecting online status and version info.
|
784 | * @param timeout Given in milliseconds
|
785 | * @return
|
786 | * @example
|
787 | * influx.ping(5000).then(hosts => {
|
788 | * hosts.forEach(host => {
|
789 | * if (host.online) {
|
790 | * console.log(`${host.url.host} responded in ${host.rtt}ms running ${host.version})`)
|
791 | * } else {
|
792 | * console.log(`${host.url.host} is offline :(`)
|
793 | * }
|
794 | * })
|
795 | * })
|
796 | */
|
797 | ping(timeout: number): Promise<IPingStats[]>;
|
798 | /**
|
799 | * Returns the default database that queries operates on. It throws if called
|
800 | * when a default database isn't set.
|
801 | * @private
|
802 | */
|
803 | private _defaultDB;
|
804 | /**
|
805 | * Creates options to be passed into the pool to query databases.
|
806 | * @private
|
807 | */
|
808 | private _getQueryOpts;
|
809 | /**
|
810 | * Creates specified measurement schema
|
811 | *
|
812 | * @private
|
813 | * @param {ISchemaOptions} schema
|
814 | * @memberof InfluxDB
|
815 | */
|
816 | private _createSchema;
|
817 | }
|
818 |
|
\ | No newline at end of file |