From 60ffe296de97e264780f38d1278f8ccbf68865a0 Mon Sep 17 00:00:00 2001 From: Nemo Date: Wed, 6 Jun 2018 15:29:56 +0530 Subject: [PATCH] Switches to bytes --- METRICS.md | 12 ++++++------ README.md | 23 +++++++++++++---------- index.js | 5 +++++ server.js | 14 +++++++------- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/METRICS.md b/METRICS.md index ee15c9b..c4a5d0b 100644 --- a/METRICS.md +++ b/METRICS.md @@ -3,13 +3,13 @@ Below are an example of the metrics as exposed by this exporter. ``` -# HELP act_fup_usage_gigabytes_total ACT current usage in GB -# TYPE act_fup_usage_gigabytes_total gauge -act_fup_usage_gigabytes_total 41.42 +# HELP act_fup_usage_bytes ACT current usage in bytes (precision GB) +# TYPE act_fup_usage_bytes gauge +act_fup_usage_bytes 41.42 -# HELP act_fup_max_gigabytes_total ACT FUP limit in GB -# TYPE act_fup_max_gigabytes_total gauge -act_fup_max_gigabytes_total 500 +# HELP act_fup_max_bytes ACT FUP limit in bytes (precision GB) +# TYPE act_fup_max_bytes gauge +act_fup_max_bytes 500 ``` It also exposes some nodeJS metrics: diff --git a/README.md b/README.md index bc31bd8..3d19f30 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Exposes your current ACT FUP usage as prometheus metrics. Scrapes the data from the ACT Portal website by using puppeteer. -- Does not support flexibytes yet. +- Does not support flexibytes yet (PRs welcome) - Only tested for ACT Bangalore connections. ## Metrics @@ -10,13 +10,13 @@ Exposes your current ACT FUP usage as prometheus metrics. Scrapes the data from Sample: ``` -# HELP act_fup_usage_gigabytes_total ACT current usage in GB -# TYPE act_fup_usage_gigabytes_total gauge -act_fup_usage_gigabytes_total 41.42 +# HELP act_fup_usage_bytes ACT current usage in bytes (precision GB) +# TYPE act_fup_usage_bytes gauge +act_fup_usage_bytes 41.42 -# HELP act_fup_max_gigabytes_total ACT FUP limit in GB -# TYPE act_fup_max_gigabytes_total gauge -act_fup_max_gigabytes_total 500 +# HELP act_fup_max_bytes ACT FUP limit in bytes (precision GB) +# TYPE act_fup_max_bytes gauge +act_fup_max_bytes 500 ``` # Using as a npm package @@ -30,10 +30,13 @@ console.log(m) // Returns // // { -// used: 2.34, -// total: 150, +// used: 102.92, +// total: 500, +// usedBytes: 102920000, +// totalBytes: 500000000 // } -// All values in GB +// used/total are in GB, other 2 are in bytes +// calculations made assuming ACT is using SI GB (exactly 1 billion bytes) ``` # Configuration diff --git a/index.js b/index.js index 640413e..791a749 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,8 @@ async function getUsage() { let metrics = { used: null, total: null, + usedBytes: null, + totalBytes: null, }; const page = await browser.newPage(); @@ -26,6 +28,9 @@ async function getUsage() { [metrics.used, metrics.total] = text .match(DATA_USAGE_REGEX) .map(x => parseFloat(x)); + + metrics.usedBytes = metrics.used * Math.pow(10, 6); + metrics.totalBytes = metrics.total * Math.pow(10, 6); } catch (e) { console.log("Couldn't scrape ACT page, faced an error"); console.log(e); diff --git a/server.js b/server.js index 52ba38f..29d755d 100644 --- a/server.js +++ b/server.js @@ -6,13 +6,13 @@ const metrics = require('./index'); pClient.collectDefaultMetrics({ timeout: 60000 }); let usedGauge = new pClient.Gauge({ - name: 'act_fup_usage_gigabytes_total', - help: 'ACT current usage in GB', + name: 'act_fup_usage_bytes', + help: 'ACT current usage in bytes (precision GB)', }); let totalGauge = new pClient.Gauge({ - name: 'act_fup_max_gigabytes_total', - help: 'ACT FUP limit in GB', + name: 'act_fup_max_bytes', + help: 'ACT FUP limit in bytes (precision GB)', }); const requestHandler = async (req, res) => { @@ -23,8 +23,8 @@ const requestHandler = async (req, res) => { let m = await metrics.getUsage(); // TODO: Switch to the correct err, res pattern with promise if (m !== null) { - usedGauge.set(m.used); - totalGauge.set(m.total); + usedGauge.set(m.usedBytes); + totalGauge.set(m.totalBytes); res.setHeader('Content-Type', pClient.register.contentType); res.end(pClient.register.metrics()); @@ -37,7 +37,7 @@ const requestHandler = async (req, res) => { default: res.writeHead(302, { Location: - 'https://git.captnemo.in/nemo/prometheus-node-exporter', + 'https://git.captnemo.in/nemo/prometheus-act-exporter', }); res.end(); break;