Switches to bytes
This commit is contained in:
parent
7cf3e401cc
commit
60ffe296de
12
METRICS.md
12
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:
|
||||
|
|
23
README.md
23
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
|
||||
|
|
5
index.js
5
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);
|
||||
|
|
14
server.js
14
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;
|
||||
|
|
Loading…
Reference in New Issue