@creditkarma/good-influx v6.0.0
good-influx
InfluxDB broadcasting for Good process monitor, based on good-http. It can write to HTTP or UDP Telegraf endpoints.
Good Influx will format your Good data according to the InfluxDB Line Protocol.
Usage
good-influx is a write stream used to send events to InfluxDB endpoints in batches. If your endpoint is http:// or https://, it makes a "POST" request with a plain-text payload to the supplied endpoint. It will make a final "POST" request to the endpoint to flush the rest of the data on "finish".
If the supplied endpoint is a udp:// endpoint then good-influx will send the stats via UDP. This may improve application performance since UDP does not wait for a response. Though it does fail silently, so you run the risk that your stats are failing to record and you don't know about it.
Example
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection();
const options = {
ops: {
interval: 1000
},
reporters: {
// Send only 'ops' events to InfluxDB
influx: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ ops: '*' }]
}, {
module: 'good-influx',
args: ['http://localhost:8086/write?db=good', {
threshold: 10,
defaultTags: {
serviceName: 'SuperAwesomeService',
dataCenter: 'Banff'
},
prefix: ['my', 'awesome', 'service']
}]
}]
}
};
server.register({
register: require('good'),
options: options
}, (err) => {
if (err) {
console.error(err);
} else {
server.start(() => {
console.info('Server started at ' + server.info.uri);
});
}
});Good Influx
GoodInflux (endpoint, config)
Creates a new GoodInflux object where:
endpoint- full path to remote server's InfluxDB HTTP API end point to transmit InfluxDB statistics (e.g.http://localhost:8086/write?db=good)config- configuration object (Optional)[threshold]- number of events to hold before transmission. Defaults to5. Set to0to have every event start transmission instantly.- Note that for UDP, threshold above
5will be set to5. Why? Because if UDP packets get too big they fail to transmit.
- Note that for UDP, threshold above
[errorThreshold]- number of erroring message sends to tolerate before the plugin fails. Default is 0.[wreck]- configuration object to pass intowreck. Defaults to{ timeout: 60000, headers: {} }.content-typeis always "text/plain".[udpType]- UDP type; defaults toudp4. Probably not necessary to change, but more documentation is available on the NodeJS Dgram Documentation[prefix]- applied to each measurement name. Useful if you want to limit the scope of your measurements to a specific service. You can specify a string, or an array of strings (recommended). Arrays will be joined by prefixDelimiter below. For example, usingprefix: ['my', 'awesome', 'service']theopsmeasurement will be renamed tomy/awesome/service/ops[prefixDelimiter]- Used to delimit measurement prefix arrays defined in prefix above. Defaults to/.[defaultTags]- An object which contains default influxdb tags to add to every event.- Example:
defaultTags: { version: '1.0.0' }[defaultFields]- An object which contains default influxdb fields to add to every event.- Example:
defaultFields: { serviceName: 'my-service' }[eventName]- Either a string or a function.- If it is a string, all events, regardless of what they are actually logged as, will be processed as an event of that name.
- Example:
eventName: 'test'will process all events with the schemas defined fortest.
- Example:
- If it is a function, that function is called with the
eventobject and then the event will be processed as if it was whatever event name is returned (or the original name ifundefinedis returned).- Example:
eventName: (event) => { return event.isMetric ? 'metric' : 'log' }will process all events with a truthy value ofisMetricunder themetricschema, and all other events under thelogschema.
- Example:
- If it is a string, all events, regardless of what they are actually logged as, will be processed as an event of that name.
[schemas]- An object where the keys are the event names to handle and the values are either a schema or array of schemas. When defining schemas here, they are merged with the default schemas such that if you provide one that exists in the default (such asops), it will overwrite all of those default schemas. See Schemas- Example:
schemas: { metrics: myMetricsSchema ops: [myOps1Schema, myOps2Schema] }
Schemas
Good-Influx uses a schema system to determine how to format an event. Each event can have multiple schemas attached to it. While giving you all the fields and some basic examples of how to use them with schemas is helpful, I also strongly suggest looking at the default ones defined in the schemas folder to see how they are built and how each type is used.
NOTE However you define your schemas, all line items will additionally have host and pid attached to them.
Schema Definition
[metric]- The metric to use for this schema. This applies beforeprefixis applied such that if yourprefixis 'test',prefixDelimiteris '/' and yourmetricis 'log', you would have a final metric name oftest/log.[splitLines]- This allows you to generate multiple line items from one event and one schema which are similar, but key off an objects keys.[splitOn]- This is the base field to split on. This value is retrieved with_.get, so you can use dot and array syntax to reach nested fields.[splitKey]- This creates a reusable name which can reference the keys you are splitting on.- Example Given:
I can define:event = { my: { fieldA: { data: 'testA' }, fieldB: { data: 'testB' } } }
This means that for all the tags and fields, I can specify keys like:splitLines: { splitOn: 'my', splitKey: 'field' }${field}Dataand values likemy.${field}.data. The end result of this definition will be two different line items.[tags]- An array of SchemaItems which will be processed into tags for the line item(s). Thetypefield of the SchemaItem is ignored for tags as all tags are processed as a special type of string.[fields]- An array of SchemaItems which will be processed into fields for the line item(s).
Schema Item
There are a couple of different items you can define and they behave a little differently.
Basic Items
[key]- What name to give this item in the resultant line item. You can use template syntax (${var}) to reference any keys fromsplitKeyorarrayKeywhich are available.[type]- How to format the value. Available types are:[value]- Where the value to format lives on the event object. This can also look up keys fromsplitKeyandarrayKeywhich are available. You can also use template syntax (${var}) to replace values in the path and dot or array syntax to find nested data.- Example: If
valueismy.${field}.datafrom the above example, it would finetestAin the first line pass andtestBin the second.
- Example: If
[default]- If the value does not resolve to anything, an optional default value can be defined. Note: This value should not be pre-formatted to the type and still must be valid for the type defined.[transform]- A function which can be specified to transform the value after it is retrieved but before it is formatted.
Iterator Items
Iterator items allow you to process a set of similarly structured data from the event. This is very similar to the concept behind splitLines above, but it does not create a new line item for each iteration.
[type]- In this case, you must set type toiterator.[iteratorBase]- The path to the base object you will be iterating over[itemKey]- This creates a reusable name which can be used in templating for the resultant fields and their keys.[tags]- A set of Schema Item tags to generate which have access to theitemKeyfor templating theirkeyandvalue.[fields]- A set of Schema Item fields to generate which have access to theitemKeyfor templating theirkeyandvalue.
Object Items
Object items allow you to take things with unknown or arbitrary data and flatten them into your response. This will support any level of nesting and will reduce it to dot notation. As part of the flattening, the data will be formatted to the most appropriate matching type between string, float, and int.
NOTE: You should still make an attempt to know what your data looks like before using this formatter. Influx only allows one type per field, and once it is set, and lines which attempt to place a different type in that field will just not be logged at all.
NOTE: Objects with circular references are automatically truncated
[type]- In this case, you must set type toobject.[value]- The base path to the object you want to flatten.[keyPrefix]- Allows you to set a prefix for all values that are flattened.- Example: If your value resolves to
{ a: 'test' }and yourkeyPrefixis "data", the resultant field will bedata.a="test".
- Example: If your value resolves to
Built-in Schemas
Please look at the actual schema definitions in the schemas folder to see what is captured for each event.
- error
- ops
- ops
- ops_requests (multiple lines split on
load.requests) - ops_concurrents (multiple lines split on
load.concurrents) - ops_responseTiems (multiple lines split on
load.responseTimes) - ops_sockets
- log
- request
- response