Switches to bytes

This commit is contained in:
Nemo 2018-06-06 15:29:56 +05:30
parent 7cf3e401cc
commit 60ffe296de
4 changed files with 31 additions and 23 deletions

View File

@ -3,13 +3,13 @@
Below are an example of the metrics as exposed by this exporter. Below are an example of the metrics as exposed by this exporter.
``` ```
# HELP act_fup_usage_gigabytes_total ACT current usage in GB # HELP act_fup_usage_bytes ACT current usage in bytes (precision GB)
# TYPE act_fup_usage_gigabytes_total gauge # TYPE act_fup_usage_bytes gauge
act_fup_usage_gigabytes_total 41.42 act_fup_usage_bytes 41.42
# HELP act_fup_max_gigabytes_total ACT FUP limit in GB # HELP act_fup_max_bytes ACT FUP limit in bytes (precision GB)
# TYPE act_fup_max_gigabytes_total gauge # TYPE act_fup_max_bytes gauge
act_fup_max_gigabytes_total 500 act_fup_max_bytes 500
``` ```
It also exposes some nodeJS metrics: It also exposes some nodeJS metrics:

View File

@ -2,7 +2,7 @@
Exposes your current ACT FUP usage as prometheus metrics. Scrapes the data from the ACT Portal website by using puppeteer. 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. - Only tested for ACT Bangalore connections.
## Metrics ## Metrics
@ -10,13 +10,13 @@ Exposes your current ACT FUP usage as prometheus metrics. Scrapes the data from
Sample: Sample:
``` ```
# HELP act_fup_usage_gigabytes_total ACT current usage in GB # HELP act_fup_usage_bytes ACT current usage in bytes (precision GB)
# TYPE act_fup_usage_gigabytes_total gauge # TYPE act_fup_usage_bytes gauge
act_fup_usage_gigabytes_total 41.42 act_fup_usage_bytes 41.42
# HELP act_fup_max_gigabytes_total ACT FUP limit in GB # HELP act_fup_max_bytes ACT FUP limit in bytes (precision GB)
# TYPE act_fup_max_gigabytes_total gauge # TYPE act_fup_max_bytes gauge
act_fup_max_gigabytes_total 500 act_fup_max_bytes 500
``` ```
# Using as a npm package # Using as a npm package
@ -30,10 +30,13 @@ console.log(m)
// Returns // Returns
// //
// { // {
// used: 2.34, // used: 102.92,
// total: 150, // 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 # Configuration

View File

@ -12,6 +12,8 @@ async function getUsage() {
let metrics = { let metrics = {
used: null, used: null,
total: null, total: null,
usedBytes: null,
totalBytes: null,
}; };
const page = await browser.newPage(); const page = await browser.newPage();
@ -26,6 +28,9 @@ async function getUsage() {
[metrics.used, metrics.total] = text [metrics.used, metrics.total] = text
.match(DATA_USAGE_REGEX) .match(DATA_USAGE_REGEX)
.map(x => parseFloat(x)); .map(x => parseFloat(x));
metrics.usedBytes = metrics.used * Math.pow(10, 6);
metrics.totalBytes = metrics.total * Math.pow(10, 6);
} catch (e) { } catch (e) {
console.log("Couldn't scrape ACT page, faced an error"); console.log("Couldn't scrape ACT page, faced an error");
console.log(e); console.log(e);

View File

@ -6,13 +6,13 @@ const metrics = require('./index');
pClient.collectDefaultMetrics({ timeout: 60000 }); pClient.collectDefaultMetrics({ timeout: 60000 });
let usedGauge = new pClient.Gauge({ let usedGauge = new pClient.Gauge({
name: 'act_fup_usage_gigabytes_total', name: 'act_fup_usage_bytes',
help: 'ACT current usage in GB', help: 'ACT current usage in bytes (precision GB)',
}); });
let totalGauge = new pClient.Gauge({ let totalGauge = new pClient.Gauge({
name: 'act_fup_max_gigabytes_total', name: 'act_fup_max_bytes',
help: 'ACT FUP limit in GB', help: 'ACT FUP limit in bytes (precision GB)',
}); });
const requestHandler = async (req, res) => { const requestHandler = async (req, res) => {
@ -23,8 +23,8 @@ const requestHandler = async (req, res) => {
let m = await metrics.getUsage(); let m = await metrics.getUsage();
// TODO: Switch to the correct err, res pattern with promise // TODO: Switch to the correct err, res pattern with promise
if (m !== null) { if (m !== null) {
usedGauge.set(m.used); usedGauge.set(m.usedBytes);
totalGauge.set(m.total); totalGauge.set(m.totalBytes);
res.setHeader('Content-Type', pClient.register.contentType); res.setHeader('Content-Type', pClient.register.contentType);
res.end(pClient.register.metrics()); res.end(pClient.register.metrics());
@ -37,7 +37,7 @@ const requestHandler = async (req, res) => {
default: default:
res.writeHead(302, { res.writeHead(302, {
Location: Location:
'https://git.captnemo.in/nemo/prometheus-node-exporter', 'https://git.captnemo.in/nemo/prometheus-act-exporter',
}); });
res.end(); res.end();
break; break;