diff --git a/nzb2influx.js b/nzbget2influx.js similarity index 76% rename from nzb2influx.js rename to nzbget2influx.js index ec59467..f0522f8 100644 --- a/nzb2influx.js +++ b/nzbget2influx.js @@ -20,8 +20,12 @@ const nzbgetConfig = { password: process.env.NZBGET_PASSWORD || '' }; +function log(message) { + console.log(message); +} + function writeToInflux(seriesName, values, tags) { - var payload = { + let payload = { fields: values }; @@ -39,6 +43,8 @@ const ng = new nzbget({ }); function onGetNZBData(data) { + log(`${new Date()}: Parsing NZB Data`); + let nzbs = data.result; nzbs.forEach(function(nzb) { @@ -52,29 +58,34 @@ function onGetNZBData(data) { }; writeToInflux('nzb', value, tags).then(function() { - console.dir(`wrote ${nzb.NZBName} nzb data to influx: ${new Date()}`); + log(`wrote ${nzb.NZBName} nzb data to influx: ${new Date()}`); }); }); writeToInflux('nzbs', { count: nzbs.length }, null).then(function() { - console.dir(`wrote ${nzbs.length} nzbs data to influx: ${new Date()}`); + log(`wrote ${nzbs.length} nzb data to influx: ${new Date()}`); restart(); }); } -function restart(err) { - if (err) { - console.log(err); - } +function handleError(err) { + log(`${new Date()}: Error`); + log(err); +} +function restart() { // Every {checkInterval} seconds setTimeout(getAllTheMetrics, checkInterval); } function getAllTheMetrics() { - ng.listgroups().then(onGetNZBData).catch(restart); + ng.listgroups().then(onGetNZBData).catch(err => { + handleError(err); + restart(); + }); } +log(`${new Date()}: Initialize NZB2Influx`); getAllTheMetrics(); diff --git a/package.json b/package.json index 54dab5a..635d828 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "nzb2influx", - "version": "0.1.2", + "version": "0.1.3", "private": true, "scripts": { - "start": "node nzb2influx.js" + "start": "node nzbget2influx.js" }, - "devDependencies": { + "dependencies": { "influx": "~5.0", "node-nzbget": "0.0.4" }