Browse Source

Update dependencies and version bump

tests 2.0.3
Nemo 1 year ago
parent
commit
6c4741d846
4 changed files with 91 additions and 69 deletions
  1. +2
    -2
      Dockerfile
  2. +24
    -21
      index.js
  3. +57
    -42
      package-lock.json
  4. +8
    -4
      package.json

+ 2
- 2
Dockerfile View File

@ -1,4 +1,4 @@
FROM alekzonder/puppeteer:1
FROM schliflo/docker-puppeteer:1.15.0
LABEL maintainer "Nemo <docker@captnemo.in>"
@ -22,4 +22,4 @@ COPY index.js server.js prom.js *.md /app/
ENTRYPOINT ["/usr/local/bin/node", "server.js"]
EXPOSE 3000
EXPOSE 3000

+ 24
- 21
index.js View File

@ -1,27 +1,30 @@
const puppeteer = require('puppeteer-core');
const containerized = require('containerized');
const puppeteer = require("puppeteer-core");
const containerized = require("containerized");
const MY_PACKAGE_SELECTOR_ID =
'table[style="margin-top:-10px;"] tr:first-child+tr';
const DATA_SELECTOR = 'packagecol3';
const MY_ACCOUNT_URL = 'https://selfcare.actcorp.in/group/blr/myaccount';
const DATA_SELECTOR = "packagecol3";
const MY_ACCOUNT_URL = "https://selfcare.actcorp.in/group/blr/myaccount";
const DATA_USAGE_REGEX = /\d+\.\d{0,2}/g;
const KEYS = ['live', 'flexibytes'];
const KEYS = ["live", "flexibytes"];
var browser;
async function getUsage() {
if (!browser) {
throw new Error("Browser not launched yet");
}
const page = await browser.newPage();
let defaultMetric = {
usedBytes: null,
totalBytes: null,
totalBytes: null
};
let metrics = {
live: defaultMetric,
flexibytes: defaultMetric,
aggregate: defaultMetric,
aggregate: defaultMetric
};
try {
@ -36,14 +39,14 @@ async function getUsage() {
let elements = document.getElementsByClassName(sel);
if (!elements || elements.length < 4) {
return '0.00 0.00';
return "0.00 0.00";
}
let usage = {
live: elements[3].innerText,
aggregate: '0.00 GB (Quota 800.00 GB)',
aggregate: "0.00 GB (Quota 800.00 GB)"
};
if (elements.length >= 6) {
usage['flexibytes'] = elements[5].innerText;
usage["flexibytes"] = elements[5].innerText;
}
return usage;
}, DATA_SELECTOR);
@ -59,7 +62,7 @@ async function getUsage() {
KEYS.map(key => {
dataUsage[key] = {
usedBytes: dataUsage[key][0],
totalBytes: dataUsage[key][1],
totalBytes: dataUsage[key][1]
};
dataUsage.aggregate.usedBytes += dataUsage[key].usedBytes;
dataUsage.aggregate.totalBytes += dataUsage[key].totalBytes;
@ -79,27 +82,27 @@ async function getUsage() {
function chromeLaunchConfig() {
let defaultArgs = [];
if (containerized()) {
defaultArgs = ['--no-sandbox', '--disable-setuid-sandbox'];
defaultArgs = ["--no-sandbox", "--disable-setuid-sandbox"];
}
var options = {
// These are set for Docker usage
// https://github.com/alekzonder/docker-puppeteer#before-usage
args: defaultArgs.concat(
process.env.hasOwnProperty('PROXY_SERVER')
? [`--proxy-server=${process.env['PROXY_SERVER']}`]
process.env.hasOwnProperty("PROXY_SERVER")
? [`--proxy-server=${process.env["PROXY_SERVER"]}`]
: []
),
)
};
if (process.env.hasOwnProperty('DISABLE_HEADLESS')) {
if (process.env.hasOwnProperty("DISABLE_HEADLESS")) {
options.headless = false;
}
if (process.env.hasOwnProperty('CHROME_BIN')) {
options.executablePath = process.env['CHROME_BIN'];
if (process.env.hasOwnProperty("CHROME_BIN")) {
options.executablePath = process.env["CHROME_BIN"];
}
console.log('Launching Chrome with args:');
console.log("Launching Chrome with args:");
console.log(options);
return options;
@ -108,9 +111,9 @@ function chromeLaunchConfig() {
// Async IIFE FTW
(async () => {
browser = await puppeteer.launch(chromeLaunchConfig());
console.log('Browser Initialized');
console.log("Browser Initialized");
})();
module.exports = {
getUsage: getUsage,
getUsage: getUsage
};

+ 57
- 42
package-lock.json View File

@ -1,13 +1,13 @@
{
"name": "prometheus-act-exporter",
"version": "2.0.0",
"version": "2.0.3",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"agent-base": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.0.tgz",
"integrity": "sha512-c+R/U5X+2zz2+UCrCFv6odQzJdoqI+YecuhnAJLa1zYaMc13zPfwMwZrr91Pd1DYNo/yPRbiM4WVf9whgwFsIg==",
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/agent-base/-/agent-base-4.2.1.tgz",
"integrity": "sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==",
"requires": {
"es6-promisify": "^5.0.0"
}
@ -37,9 +37,9 @@
}
},
"buffer-from": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.0.tgz",
"integrity": "sha512-c5mRlguI/Pe2dSZmpER62rSCu0ryKmWddzRYsuXc50U2/g8jMOulc31VZMa4mYx31U5xsmSOpDCgH88Vl9cDGQ=="
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"concat-map": {
"version": "0.0.1",
@ -68,17 +68,17 @@
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
"requires": {
"ms": "2.0.0"
"ms": "^2.1.1"
}
},
"es6-promise": {
"version": "4.2.4",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.4.tgz",
"integrity": "sha512-/NdNZVJg+uZgtm9eS3O6lrOLYmQag2DjdEXuPaHlZ6RuVqgqaVZfgYCepEIKsLqwdQArOPtC3XzRLqGGfT8KQQ=="
"version": "4.2.6",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.6.tgz",
"integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q=="
},
"es6-promisify": {
"version": "5.0.0",
@ -106,6 +106,11 @@
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
}
}
},
@ -123,9 +128,9 @@
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
},
"glob": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz",
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
"version": "7.1.4",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.4.tgz",
"integrity": "sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==",
"requires": {
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
@ -142,6 +147,16 @@
"requires": {
"agent-base": "^4.1.0",
"debug": "^3.1.0"
},
"dependencies": {
"debug": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"requires": {
"ms": "^2.1.1"
}
}
}
},
"inflight": {
@ -164,9 +179,9 @@
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"mime": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.3.1.tgz",
"integrity": "sha512-OEUllcVoydBHGN1z84yfQDimn58pZNNNXgZlHXSboxMlFvgI6MXSWpWKpFRra7H1HxpVhHTkrghfRW49k6yjeg=="
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/mime/-/mime-2.4.2.tgz",
"integrity": "sha512-zJBfZDkwRu+j3Pdd2aHsR5GfH2jIWhmL1ZzBoc+X+3JEti2hbArWcyJ+1laC1D2/U/W1a/+Cegj0/OnEU2ybjg=="
},
"minimatch": {
"version": "3.0.4",
@ -190,9 +205,9 @@
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
},
"once": {
"version": "1.4.0",
@ -218,14 +233,14 @@
"integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw=="
},
"progress": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.0.tgz",
"integrity": "sha1-ihvjZr+Pwj2yvSPxDG/pILQ4nR8="
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA=="
},
"prom-client": {
"version": "11.1.1",
"resolved": "https://registry.npmjs.org/prom-client/-/prom-client-11.1.1.tgz",
"integrity": "sha512-itUicyrq3Rko56v3ovQAMYwxEouK7lIylp26bjnlt1b/3fzn783riZnZn432I4udYmPsRgNx1F/u9RFvLyH7zA==",
"version": "11.3.0",
"resolved": "https://registry.npmjs.org/prom-client/-/prom-client-11.3.0.tgz",
"integrity": "sha512-OqSf5WOvpGZXkfqPXUHNHpjrbEE/q8jxjktO0i7zg1cnULAtf0ET67/J5R4e4iA4MZx2260tzTzSFSWgMdTZmQ==",
"requires": {
"tdigest": "^0.1.1"
}
@ -236,18 +251,18 @@
"integrity": "sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4="
},
"puppeteer-core": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-1.7.0.tgz",
"integrity": "sha512-SpUOJL8gTPEuABGcZxKM3jg5s0rIwmRC6P9Jw/JTG3XFCVtUcYQru4Uwlz7jAXe6JEeeLOm6hApgGCmRyALiig==",
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-1.15.0.tgz",
"integrity": "sha512-AH82x8Tx0/JkubeF6U12y8SuVB5vFgsw8lt/Ox5MhXaAktREFiotCTq324U2nPtJUnh2A8yJciDnzAmhbHidqQ==",
"requires": {
"debug": "^3.1.0",
"debug": "^4.1.0",
"extract-zip": "^1.6.6",
"https-proxy-agent": "^2.2.1",
"mime": "^2.0.3",
"progress": "^2.0.0",
"progress": "^2.0.1",
"proxy-from-env": "^1.0.0",
"rimraf": "^2.6.1",
"ws": "^5.1.1"
"ws": "^6.1.0"
}
},
"readable-stream": {
@ -265,11 +280,11 @@
}
},
"rimraf": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz",
"integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==",
"version": "2.6.3",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz",
"integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==",
"requires": {
"glob": "^7.0.5"
"glob": "^7.1.3"
}
},
"safe-buffer": {
@ -309,9 +324,9 @@
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"ws": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-5.2.1.tgz",
"integrity": "sha512-2NkHdPKjDBj3CHdnAGNpmlliryKqF+n9MYXX7/wsVC4yqYocKreKNjydPDvT3wShAZnndlM0RytEfTALCDvz7A==",
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-6.2.1.tgz",
"integrity": "sha512-GIyAXC2cB7LjvpgMt9EKS2ldqr0MTrORaleiOno6TweZ6r3TKtoFQWay/2PceJ3RuBasOHzXNn5Lrw1X0bEjqA==",
"requires": {
"async-limiter": "~1.0.0"
}


+ 8
- 4
package.json View File

@ -1,12 +1,16 @@
{
"name": "prometheus-act-exporter",
"version": "2.0.2",
"version": "2.0.3",
"description": "Exports ACT Fibernet data usage as prometheus metrics",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": ["actcorp", "balance", "flexibyte"],
"keywords": [
"actcorp",
"balance",
"flexibyte"
],
"repository": {
"type": "git",
"url": "git+ssh://git@git.captnemo.in/nemo/prometheus-act-exporter.git"
@ -18,7 +22,7 @@
"license": "WTFPL",
"dependencies": {
"containerized": "^1.0.2",
"prom-client": "^11.1.0",
"puppeteer-core": "^1.8.0"
"prom-client": "^11.3.0",
"puppeteer-core": "^1.15.0"
}
}

Loading…
Cancel
Save