Connect to an InfluxDB cluster by specifying a set of connection options.
Connects to a local, default Influx instance.
Alters an existing retention policy on a database.
The retention policy name
IRetentionOptions are passed into passed into the InfluxDB#createRetentionPolicy and InfluxDB#alterRetentionPolicy. See the [Downsampling and Retention page](https://docs.influxdata.com/ influxdb/v1.0/guides/downsampling_and_retention/) on the Influx docs for more information.
Optionaldatabase?: stringOptionalisDefault?: booleanOptionalshardGroupDuration?: stringCreates a continuous query in a database
The query name, for later reference
The body of the query to run
Optionaldatabase: string = ...
If not provided, uses the default database.
Optionalresample: string = ""
If provided, adds resample policy
Creates a new retention policy on a database. You can read more about [Downsampling and Retention](https://docs.influxdata.com/influxdb/v1.0/ guides/downsampling_and_retention/) on the InfluxDB website.
The retention policy name
IRetentionOptions are passed into passed into the InfluxDB#createRetentionPolicy and InfluxDB#alterRetentionPolicy. See the [Downsampling and Retention page](https://docs.influxdata.com/ influxdb/v1.0/guides/downsampling_and_retention/) on the Influx docs for more information.
Optionaldatabase?: stringOptionalisDefault?: booleanOptionalshardGroupDuration?: stringCreates a new InfluxDB user.
Optionaladmin: boolean = false
If true, the user will be given all privileges on all databases.
Deletes a retention policy and associated data. Note that the data will not be immediately destroyed, and will hang around until Influx's bi-hourly cron.
The retention policy name
Optionaldatabase: string = ...
Database name that the policy lives in, uses the default database if not provided.
Removes a one or more series from InfluxDB.
// The following pairs of queries are equivalent: you can chose either to
// use our builder or pass in string directly. The builder takes care
// of escaping and most syntax handling for you.
influx.dropSeries({ where: e => e.tag('cpu').equals.value('cpu8') })
influx.dropSeries({ where: '"cpu" = \'cpu8\'' })
// DROP SERIES WHERE "cpu" = 'cpu8'
influx.dropSeries({ measurement: m => m.name('cpu').policy('autogen') })
influx.dropSeries({ measurement: '"cpu"."autogen"' })
// DROP SERIES FROM "autogen"."cpu"
influx.dropSeries({
measurement: m => m.name('cpu').policy('autogen'),
where: e => e.tag('cpu').equals.value('cpu8'),
database: 'my_db'
})
// DROP SERIES FROM "autogen"."cpu" WHERE "cpu" = 'cpu8'
Returns array of measurements.
Optionaldatabase: string = ...
the database the measurement lives in, optional if a default database is provided.
a list of measurement names
Returns a list of all series within the target measurement, or from the entire database if a measurement isn't provided.
Optionaloptions: { database?: string; measurement?: string } = {}
Optionaldatabase?: stringthe database the series lives in, optional if a default database is provided.
Optionalmeasurement?: stringif provided, we'll only get series from within that measurement.
a list of series names
Returns a list of users on the Influx database.
Grants a privilege to a specified user.
Should be one of 'READ' or 'WRITE'
Optionaldatabase: string = ...
If not provided, uses the default database.
ParsePoint will perform the coercions/schema checks and return the data required for writing a point. This will throw an error if a schema check or coercion fails. This can be useful for flagging or "throwing out" bad points in a batch write to prevent the entire batch from getting aborted
A note when using this function, InfluxDB#writePoints will still perform the same checks, so any pre-processed data will be checked for validity twice which has potential performance implications on large data sets
Optionaloptions: IParseOptions = {}// parse a point as if it is getting written to the default
// databse with the default time precision
influx.parsePoint({
measurement: 'perf',
tags: { host: 'box1.example.com' },
fields: { cpu: getCpuUsage(), mem: getMemUsage() },
})
// you can manually specify the database and time precision
influx.parsePoint({
measurement: 'perf',
tags: { host: 'box1.example.com' },
fields: { cpu: getCpuUsage(), mem: getMemUsage() },
}, {
precision: 's',
database: 'my_db'
})
// if an error occurs, you can catch the error with try...catch
try {
influx.parsePoint({
measurement: 'perf',
tags: { host: 'box1.example.com', myExtraneousTag: 'value' },
fields: { cpu: getCpuUsage(), mem: getMemUsage(), myExtraneousField: 'value' },
})
} catch(err) {
handleError(err);
}
Pings all available hosts, collecting online status and version info.
Given in milliseconds
Optionaloptions: IQueryOptionsOptionaloptions: IQueryOptionsQueryRaw functions similarly to .query() but it does no fancy
transformations on the returned data; it calls JSON.parse and returns
those results verbatim.
Optionaloptions: IQueryOptions = {}Removes a privilege from a specified user.
Should be one of 'READ' or 'WRITE'
Optionaldatabase: string = ...
If not provided, uses the default database.
Returns a list of continous queries in the database.
Optionaldatabase: string = ...
If not provided, uses the default database.
Shows retention policies on the database
Optionaldatabase: string = ...
The database to list policies on, uses the default database if not provided.
Shows shards on the database
Optionaldatabase: string = ...
The database to list policies on, uses the default database if not provided.
WriteMeasurement functions similarly to InfluxDB#writePoints, but
it automatically fills in the measurement value for all points for you.
Optionaloptions: IWriteOptions = {}WritePoints sends a list of points together in a batch to InfluxDB. In each point you must specify the measurement name to write into as well as a list of tag and field values. Optionally, you can specify the time to tag that point at, defaulting to the current time.
If you defined a schema for the measurement in the options you passed
to new Influx(options), we'll use that to make sure that types get
cast correctly and that there are no extraneous fields or columns.
For best performance, it's recommended that you batch your data into sets of a couple thousand records before writing it. In the future we'll have some utilities within node-influx to make this easier.
A note when using manually-specified times and precisions: by default
we write using the ms precision since that's what JavaScript gives us.
You can adjust this. However, there is some special behaviour if you
manually specify a timestamp in your points:
Please see the IPoint and IWriteOptions types for a full list of possible options.
Optionaloptions: IWriteOptions = {}// write a point into the default database with
// the default retention policy.
influx.writePoints([
{
measurement: 'perf',
tags: { host: 'box1.example.com' },
fields: { cpu: getCpuUsage(), mem: getMemUsage() },
}
])
// you can manually specify the database,
// retention policy, and time precision:
influx.writePoints([
{
measurement: 'perf',
tags: { host: 'box1.example.com' },
fields: { cpu: getCpuUsage(), mem: getMemUsage() },
timestamp: getLastRecordedTime(),
}
], {
database: 'my_db',
retentionPolicy: '1d',
precision: 's'
})
InfluxDB is the public interface to run queries against your database. This is a 'driver-level' module, not a a full-fleged ORM or ODM; you run queries directly by calling methods on this class.
Please check out some of the tutorials if you want help getting started!
Example
Example