Constructor
new Writer(client, queue) → {Writer}
- Source:
- Since:
- 2.2.0
Get the influxdb writer
Example
const Influx = require('influxdb-nodejs');
const client = new Influx('http://127.0.0.1:8086/mydb');
const writer = client.writer('http');
Parameters:
Name | Type | Description |
---|---|---|
client |
Influx | The influx instance |
queue |
function | The queue function |
Returns:
- Type
- Writer
Methods
field(key, value) → {Writer}
- Source:
- Since:
- 2.2.0
Set the field for the write point
Example
client.write('http')
.tag('method', 'GET')
.tag({
spdy: 'fast',
type: '2',
})
.field('size', 10 * 1024)
.field({
use: 300,
code: 200,
})
.then(() => console.info('write point success'))
.catch(err => console.error(`write point fail, ${err.message}`));
Parameters:
Name | Type | Description |
---|---|---|
key |
String | Object | The field's key |
value |
Any | The field's value |
Returns:
- Type
- Writer
queue() → {Writer}
- Source:
- Since:
- 2.2.0
Add the writer to the queue
Example
client.write('http')
.tag('method', 'GET')
.tag({
spdy: 'fast',
type: '2',
})
.field('size', 10 * 1024)
.field({
use: 300,
code: 200,
})
.queue();
Returns:
- Type
- Writer
set(key, value) → {Writer}
- Source:
- Since:
- 2.7.7
Set the internal value
Example
client.write('http')
.tag('method', 'GET')
.tag({
spdy: 'fast',
type: '2',
})
.set({
RP: 'test',
})
.field('size', 10 * 1024)
.field({
use: 300,
code: 200,
})
.then(() => console.info('write point success'))
.catch(err => console.error(`write point fail, ${err.message}`));
Parameters:
Name | Type | Description |
---|---|---|
key |
String | Object | the key |
value |
Any | the value |
Returns:
- Type
- Writer
tag(key, value) → {Writer}
- Source:
- Since:
- 2.2.0
Set the tag for the write point
Example
client.write('http')
.tag('method', 'GET')
.tag({
spdy: 'fast',
type: '2',
})
.field('size', 10 * 1024)
.field({
use: 300,
code: 200,
})
.then(() => console.info('write point success'))
.catch(err => console.error(`write point fail, ${err.message}`));
Parameters:
Name | Type | Description |
---|---|---|
key |
String | Object | The tag's key |
value |
Any | The tag's value |
Returns:
- Type
- Writer
then(resolve, reject) → {Promise}
- Source:
- Since:
- 2.2.0
Get the writer promise
Parameters:
Name | Type | Description |
---|---|---|
resolve |
function | resolve function |
reject |
function | reject function |
Returns:
- Type
- Promise
time(timestamp) → {String}
- Source:
- Since:
- 2.2.0
Set the timestamp for the write point
Example
client.write('http')
.tag('method', 'GET')
.tag({
spdy: 'fast',
type: '2',
})
.field('size', 10 * 1024)
.field({
use: 300,
code: 200,
})
.time(Date.now(), 'ms')
.then(() => console.info('write point success'))
.catch(err => console.error(`write point fail, ${err.message}`));
Parameters:
Name | Type | Description |
---|---|---|
timestamp |
String | The timestamp |
Returns:
precision - The precision for the timestamp
- Type
- String
toJSON() → {Object}
- Source:
- Since:
- 2.2.0
Get the point data {measurement: String, tags: Object, fields: Object, time: String }]
Example
const writer = client.write('http')
.tag('method', 'GET')
.tag({
spdy: 'fast',
type: '2',
})
.field('size', 10 * 1024)
.field({
use: 300,
code: 200,
});
console.info(writer.toJSON());
// => { measurement: 'http',
// tags: { method: 'GET', spdy: 'fast', type: '2' },
// fields: { size: 10240, use: 300, code: 200 },
// time: 0 }
Returns:
- Type
- Object