Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ jobs:
- name: Run test with Influx 1.8
run: cd sitespeed.io && bin/sitespeed.js https://www.sitespeed.io -n 1 --influxdb.host 127.0.0.1 --xvfb --resultBaseUrl https://result.sitespeed.io --influxdb.annotationScreenshot=true --plugins.add ../../../lib/index.js
- name: Run test with Influx 2.6.1
run: cd sitespeed.io && bin/sitespeed.js https://www.sitespeed.io -n 1 --influxdb.host 127.0.0.1 --influxdb.port 8087 --influxdb.version 2 --influxdb.organisation sitespeed --influxdb.token sitespeed --xvfb --resultBaseUrl https://result.sitespeed.io --influxdb.annotationScreenshot=true --plugins.add ../../../lib/index.js
run: cd sitespeed.io && bin/sitespeed.js https://www.sitespeed.io -n 1 --influxdb.host 127.0.0.1 --influxdb.port 8087 --influxdb.version 2 --influxdb.organisation sitespeed --influxdb.token sitespeed --xvfb --resultBaseUrl https://result.sitespeed.io --influxdb.annotationScreenshot=true --influxdb.functions='min,max' --plugins.add ../../../lib/index.js
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Store data in InfluxDB from sitespeed.io. This plugin was included in sitespeed.io before sitespeed.io 37 was released. After that version you need to install it yourself.

## Install the plugin
If you use NodeJs the simplest way is to install the plugin globally: `npm install @sitespeed.io/plugin-influxdb -g`
If you use Node.js the simplest way is to install the plugin globally: `npm install @sitespeed.io/plugin-influxdb -g`


## Run the plugin
And then run sitespeed.io adding the pluging using the package name: `sitespeed.io --plugins.add @sitespeed.io/plugin-influxdb --influxdb.host YOUR_HOST https://www.sitespeed.io`
And then run sitespeed.io adding the plugin using the package name: `sitespeed.io --plugins.add @sitespeed.io/plugin-influxdb --influxdb.host YOUR_HOST https://www.sitespeed.io`

## CLI help
To see the command line options using help:
Expand Down
28 changes: 19 additions & 9 deletions lib/data-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ function getAdditionalTags(key, type) {
return tags;
}

function getFieldAndSeriesName(key) {
function getFieldAndSeriesName(key, options) {
const functions = [
'min',
'p10',
Expand All @@ -168,12 +168,20 @@ function getFieldAndSeriesName(key) {
'stddev',
'rsd'
];

const availableFunctions = options.influxdb.functions
? options.influxdb.functions.split(',')
: functions;

const keyArray = key.split('.');
const end = keyArray.pop();
if (functions.includes(end)) {
if (availableFunctions.includes(end)) {
return { field: end, seriesName: keyArray.pop() };
}
return { field: 'value', seriesName: end };
if (!availableFunctions.includes(end) && !functions.includes(end)) {
return { field: 'value', seriesName: end };
}
return {};
}
export class InfluxDBDataGenerator {
constructor(includeQueryParameters, options) {
Expand Down Expand Up @@ -237,7 +245,7 @@ export class InfluxDBDataGenerator {
}
return Object.entries(flattenMessageData(message)).reduce(
(entries, [key, value]) => {
const fieldAndSeriesName = getFieldAndSeriesName(key);
const fieldAndSeriesName = getFieldAndSeriesName(key, this.options);
let tags = getTagsFromMessage(
message,
this.includeQueryParams,
Expand All @@ -249,11 +257,13 @@ export class InfluxDBDataGenerator {
time: time.valueOf(),
[fieldAndSeriesName.field]: value
};
entries.push({
tags,
seriesName: fieldAndSeriesName.seriesName,
point
});
if (fieldAndSeriesName.seriesName !== undefined) {
entries.push({
tags,
seriesName: fieldAndSeriesName.seriesName,
point
});
}
return entries;
},
[]
Expand Down
Loading