Compare commits
29 Commits
Author | SHA1 | Date | |
---|---|---|---|
057a0a329e | |||
e53bebf7a1 | |||
c4f5e9338a | |||
dad2bc26fc | |||
29609eb5ba | |||
0292d9bc13 | |||
69af53a30a | |||
121bfdad43 | |||
f96ed80be0 | |||
ce74c3da40 | |||
c108c00963 | |||
25de5d5874 | |||
9822d470e3 | |||
a425ed64c3 | |||
2eb4bc5697 | |||
dd46f0d90b | |||
0972f1c64d | |||
22b181a7a0 | |||
e43b89f51d | |||
3185c7dab1 | |||
ef6d625ac9 | |||
f5e8af9a06 | |||
cd2cc0685e | |||
1b8f4f2219 | |||
533639b66d | |||
8f0ebccb58 | |||
e98b1779e1 | |||
df5197fc8e | |||
0e3fadca36 |
152
package-lock.json
generated
152
package-lock.json
generated
@ -1,24 +1,27 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartmetrics",
|
"name": "@pushrocks/smartmetrics",
|
||||||
"version": "1.0.2",
|
"version": "1.0.17",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartmetrics",
|
"name": "@pushrocks/smartmetrics",
|
||||||
"version": "1.0.2",
|
"version": "1.0.17",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartlog": "^2.0.44",
|
"@pushrocks/smartlog": "^2.0.44",
|
||||||
|
"@types/pidusage": "^2.0.1",
|
||||||
|
"pidtree": "^0.5.0",
|
||||||
|
"pidusage": "^2.0.21",
|
||||||
"prom-client": "^13.2.0"
|
"prom-client": "^13.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.26",
|
||||||
"@gitzone/tsbundle": "^1.0.78",
|
"@gitzone/tsbundle": "^1.0.78",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.44",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^16.6.0",
|
"@types/node": "^16.6.1",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
}
|
}
|
||||||
@ -1819,38 +1822,24 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@gitzone/tsbuild": {
|
"node_modules/@gitzone/tsbuild": {
|
||||||
"version": "2.1.25",
|
"version": "2.1.26",
|
||||||
"resolved": "https://verdaccio.lossless.one/@gitzone%2ftsbuild/-/tsbuild-2.1.25.tgz",
|
"resolved": "https://verdaccio.lossless.one/@gitzone%2ftsbuild/-/tsbuild-2.1.26.tgz",
|
||||||
"integrity": "sha512-KtesoQEm96x0/x1800R3pcj06RcYTdqwBhG9oje+jQW4qZs/bnUirWZXkRMSLAK92cVm899KzZtYkq/fKga2+A==",
|
"integrity": "sha512-FE0cjdAyzTR+Rr7pHULTF5rHiCW+FFnEHuV4kP7pdrHzl5oFZTUQ3uqEFEgmsrV6a0gzNwKgr/MfnVO/3sUrdw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/early": "^3.0.6",
|
"@pushrocks/early": "^3.0.6",
|
||||||
"@pushrocks/smartcli": "^3.0.12",
|
"@pushrocks/smartcli": "^3.0.14",
|
||||||
"@pushrocks/smartfile": "^8.0.0",
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
"@pushrocks/smartlog": "^2.0.36",
|
"@pushrocks/smartlog": "^2.0.44",
|
||||||
"@pushrocks/smartpath": "^4.0.3",
|
"@pushrocks/smartpath": "^4.0.3",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"typescript": "^3.9.7"
|
"typescript": "^4.3.5"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"tsbuild": "cli.js"
|
"tsbuild": "cli.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@gitzone/tsbuild/node_modules/typescript": {
|
|
||||||
"version": "3.9.10",
|
|
||||||
"resolved": "https://verdaccio.lossless.one/typescript/-/typescript-3.9.10.tgz",
|
|
||||||
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "Apache-2.0",
|
|
||||||
"bin": {
|
|
||||||
"tsc": "bin/tsc",
|
|
||||||
"tsserver": "bin/tsserver"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">=4.2.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@gitzone/tsbundle": {
|
"node_modules/@gitzone/tsbundle": {
|
||||||
"version": "1.0.84",
|
"version": "1.0.84",
|
||||||
"resolved": "https://verdaccio.lossless.one/@gitzone%2ftsbundle/-/tsbundle-1.0.84.tgz",
|
"resolved": "https://verdaccio.lossless.one/@gitzone%2ftsbundle/-/tsbundle-1.0.84.tgz",
|
||||||
@ -3038,9 +3027,9 @@
|
|||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "16.6.0",
|
"version": "16.6.1",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-16.6.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-16.6.1.tgz",
|
||||||
"integrity": "sha512-OyiZPohMMjZEYqcVo/UJ04GyAxXOJEZO/FpzyXxcH4r/ArrVoXHf4MbUrkLp0Tz7/p1mMKpo5zJ6ZHl8XBNthQ==",
|
"integrity": "sha512-Sr7BhXEAer9xyGuCN3Ek9eg9xPviCF2gfu9kTfuU2HkTVAMYSDeX40fvpmo72n5nansg3nsBjuQBrsS28r+NUw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
@ -3054,6 +3043,12 @@
|
|||||||
"@types/express-serve-static-core": "*"
|
"@types/express-serve-static-core": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/pidusage": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@types%2fpidusage/-/pidusage-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-tYYcz/+5v/EGYT83C0pIXrJGOiVBLksQvxgJboG4nGqx/gZTvq0Ro4SkAjECqMk7L4Ww58VWB4j48qeYh4/YJg==",
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/puppeteer": {
|
"node_modules/@types/puppeteer": {
|
||||||
"version": "5.4.4",
|
"version": "5.4.4",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fpuppeteer/-/puppeteer-5.4.4.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fpuppeteer/-/puppeteer-5.4.4.tgz",
|
||||||
@ -10453,6 +10448,50 @@
|
|||||||
"url": "https://github.com/sponsors/jonschlinkert"
|
"url": "https://github.com/sponsors/jonschlinkert"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/pidtree": {
|
||||||
|
"version": "0.5.0",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/pidtree/-/pidtree-0.5.0.tgz",
|
||||||
|
"integrity": "sha512-9nxspIM7OpZuhBxPg73Zvyq7j1QMPMPsGKTqRc2XOaFQauDvoNz9fM1Wdkjmeo7l9GXOZiRs97sPkuayl39wjA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"bin": {
|
||||||
|
"pidtree": "bin/pidtree.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/pidusage": {
|
||||||
|
"version": "2.0.21",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/pidusage/-/pidusage-2.0.21.tgz",
|
||||||
|
"integrity": "sha512-cv3xAQos+pugVX+BfXpHsbyz/dLzX+lr44zNMsYiGxUw+kV5sgQCIcLd1z+0vq+KyC7dJ+/ts2PsfgWfSC3WXA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"safe-buffer": "^5.2.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/pidusage/node_modules/safe-buffer": {
|
||||||
|
"version": "5.2.1",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||||
|
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "patreon",
|
||||||
|
"url": "https://www.patreon.com/feross"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "consulting",
|
||||||
|
"url": "https://feross.org/support"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/pkg-dir": {
|
"node_modules/pkg-dir": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/pkg-dir/-/pkg-dir-4.2.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/pkg-dir/-/pkg-dir-4.2.0.tgz",
|
||||||
@ -15979,26 +16018,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@gitzone/tsbuild": {
|
"@gitzone/tsbuild": {
|
||||||
"version": "2.1.25",
|
"version": "2.1.26",
|
||||||
"resolved": "https://verdaccio.lossless.one/@gitzone%2ftsbuild/-/tsbuild-2.1.25.tgz",
|
"resolved": "https://verdaccio.lossless.one/@gitzone%2ftsbuild/-/tsbuild-2.1.26.tgz",
|
||||||
"integrity": "sha512-KtesoQEm96x0/x1800R3pcj06RcYTdqwBhG9oje+jQW4qZs/bnUirWZXkRMSLAK92cVm899KzZtYkq/fKga2+A==",
|
"integrity": "sha512-FE0cjdAyzTR+Rr7pHULTF5rHiCW+FFnEHuV4kP7pdrHzl5oFZTUQ3uqEFEgmsrV6a0gzNwKgr/MfnVO/3sUrdw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/early": "^3.0.6",
|
"@pushrocks/early": "^3.0.6",
|
||||||
"@pushrocks/smartcli": "^3.0.12",
|
"@pushrocks/smartcli": "^3.0.14",
|
||||||
"@pushrocks/smartfile": "^8.0.0",
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
"@pushrocks/smartlog": "^2.0.36",
|
"@pushrocks/smartlog": "^2.0.44",
|
||||||
"@pushrocks/smartpath": "^4.0.3",
|
"@pushrocks/smartpath": "^4.0.3",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"typescript": "^3.9.7"
|
"typescript": "^4.3.5"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"typescript": {
|
|
||||||
"version": "3.9.10",
|
|
||||||
"resolved": "https://verdaccio.lossless.one/typescript/-/typescript-3.9.10.tgz",
|
|
||||||
"integrity": "sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q==",
|
|
||||||
"dev": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@gitzone/tsbundle": {
|
"@gitzone/tsbundle": {
|
||||||
@ -17018,9 +17049,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "16.6.0",
|
"version": "16.6.1",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-16.6.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-16.6.1.tgz",
|
||||||
"integrity": "sha512-OyiZPohMMjZEYqcVo/UJ04GyAxXOJEZO/FpzyXxcH4r/ArrVoXHf4MbUrkLp0Tz7/p1mMKpo5zJ6ZHl8XBNthQ==",
|
"integrity": "sha512-Sr7BhXEAer9xyGuCN3Ek9eg9xPviCF2gfu9kTfuU2HkTVAMYSDeX40fvpmo72n5nansg3nsBjuQBrsS28r+NUw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/parcel-bundler": {
|
"@types/parcel-bundler": {
|
||||||
@ -17032,6 +17063,11 @@
|
|||||||
"@types/express-serve-static-core": "*"
|
"@types/express-serve-static-core": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/pidusage": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/@types%2fpidusage/-/pidusage-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-tYYcz/+5v/EGYT83C0pIXrJGOiVBLksQvxgJboG4nGqx/gZTvq0Ro4SkAjECqMk7L4Ww58VWB4j48qeYh4/YJg=="
|
||||||
|
},
|
||||||
"@types/puppeteer": {
|
"@types/puppeteer": {
|
||||||
"version": "5.4.4",
|
"version": "5.4.4",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fpuppeteer/-/puppeteer-5.4.4.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fpuppeteer/-/puppeteer-5.4.4.tgz",
|
||||||
@ -22566,6 +22602,26 @@
|
|||||||
"integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==",
|
"integrity": "sha512-lY1Q/PiJGC2zOv/z391WOTD+Z02bCgsFfvxoXXf6h7kv9o+WmsmzYqrAwY63sNgOxE4xEdq0WyUnXfKeBrSvYw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"pidtree": {
|
||||||
|
"version": "0.5.0",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/pidtree/-/pidtree-0.5.0.tgz",
|
||||||
|
"integrity": "sha512-9nxspIM7OpZuhBxPg73Zvyq7j1QMPMPsGKTqRc2XOaFQauDvoNz9fM1Wdkjmeo7l9GXOZiRs97sPkuayl39wjA=="
|
||||||
|
},
|
||||||
|
"pidusage": {
|
||||||
|
"version": "2.0.21",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/pidusage/-/pidusage-2.0.21.tgz",
|
||||||
|
"integrity": "sha512-cv3xAQos+pugVX+BfXpHsbyz/dLzX+lr44zNMsYiGxUw+kV5sgQCIcLd1z+0vq+KyC7dJ+/ts2PsfgWfSC3WXA==",
|
||||||
|
"requires": {
|
||||||
|
"safe-buffer": "^5.2.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"safe-buffer": {
|
||||||
|
"version": "5.2.1",
|
||||||
|
"resolved": "https://verdaccio.lossless.one/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||||
|
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"pkg-dir": {
|
"pkg-dir": {
|
||||||
"version": "4.2.0",
|
"version": "4.2.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/pkg-dir/-/pkg-dir-4.2.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/pkg-dir/-/pkg-dir-4.2.0.tgz",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartmetrics",
|
"name": "@pushrocks/smartmetrics",
|
||||||
"version": "1.0.2",
|
"version": "1.0.17",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "easy system metrics",
|
"description": "easy system metrics",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -12,11 +12,11 @@
|
|||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.26",
|
||||||
"@gitzone/tsbundle": "^1.0.78",
|
"@gitzone/tsbundle": "^1.0.78",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tstest": "^1.0.44",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^16.6.0",
|
"@types/node": "^16.6.1",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
@ -38,6 +38,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@pushrocks/smartdelay": "^2.0.13",
|
||||||
"@pushrocks/smartlog": "^2.0.44",
|
"@pushrocks/smartlog": "^2.0.44",
|
||||||
|
"@types/pidusage": "^2.0.1",
|
||||||
|
"pidtree": "^0.5.0",
|
||||||
|
"pidusage": "^2.0.21",
|
||||||
"prom-client": "^13.2.0"
|
"prom-client": "^13.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@ tap.test('should start smartmetrics', async () => {
|
|||||||
testSmartMetrics.start();
|
testSmartMetrics.start();
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should produce valid metrics', async () => {
|
tap.test('should produce valid metrics', async (tools) => {
|
||||||
|
console.log('calling .getMetrics from Testfile:')
|
||||||
console.log(await testSmartMetrics.getMetrics());
|
console.log(await testSmartMetrics.getMetrics());
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import * as plugins from './smartmetrics.plugins';
|
import * as plugins from './smartmetrics.plugins';
|
||||||
import * as interfaces from './smartmetrics.interfaces';
|
import * as interfaces from './smartmetrics.interfaces';
|
||||||
import { Cipher } from 'crypto';
|
|
||||||
|
|
||||||
export class SmartMetrics {
|
export class SmartMetrics {
|
||||||
public started = false;
|
public started = false;
|
||||||
@ -20,44 +19,21 @@ export class SmartMetrics {
|
|||||||
this.setup();
|
this.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async start() {
|
public start() {
|
||||||
if (this.started) {
|
const unattendedStart = async () => {
|
||||||
return;
|
if (this.started) {
|
||||||
}
|
return;
|
||||||
this.started = true;
|
}
|
||||||
while (this.started) {
|
this.started = true;
|
||||||
this.logger.log('info', `sending heartbeat for ${this.sourceNameArg}`, {
|
while (this.started) {
|
||||||
metrics: await this.getMetrics(),
|
this.logger.log('info', `sending heartbeat for ${this.sourceNameArg} with metrics`, {
|
||||||
});
|
eventType: 'heartbeat',
|
||||||
await plugins.smartdelay.delayFor(60000, null, true);
|
metrics: await this.getMetrics(),
|
||||||
}
|
});
|
||||||
}
|
await plugins.smartdelay.delayFor(20000, null, true);
|
||||||
|
}
|
||||||
public getCpuUsagePercentage() {
|
};
|
||||||
// Take the first CPU, considering every CPUs have the same specs
|
unattendedStart();
|
||||||
// and every NodeJS process only uses one at a time.
|
|
||||||
const cpus = plugins.os.cpus();
|
|
||||||
let total: number = 0;
|
|
||||||
|
|
||||||
for (const cpu of cpus) {
|
|
||||||
total +=
|
|
||||||
cpu.times.user +
|
|
||||||
cpu.times.sys +
|
|
||||||
cpu.times.nice +
|
|
||||||
cpu.times.nice +
|
|
||||||
cpu.times.irq +
|
|
||||||
cpu.times.idle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normalize the one returned by process.cpuUsage()
|
|
||||||
// (microseconds VS miliseconds)
|
|
||||||
const usage = process.cpuUsage();
|
|
||||||
const currentCPUUsage = (usage.user + usage.system) * 1000;
|
|
||||||
|
|
||||||
// Find out the percentage used for this specific CPU
|
|
||||||
const perc = (currentCPUUsage / total) * 100;
|
|
||||||
|
|
||||||
return perc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public formatBytes(bytes: number, decimals = 2) {
|
public formatBytes(bytes: number, decimals = 2) {
|
||||||
@ -74,8 +50,29 @@ export class SmartMetrics {
|
|||||||
|
|
||||||
public async getMetrics() {
|
public async getMetrics() {
|
||||||
const originalMetrics = await this.registry.getMetricsAsJSON();
|
const originalMetrics = await this.registry.getMetricsAsJSON();
|
||||||
|
const pids = await plugins.pidtree(process.pid);
|
||||||
|
const stats = await plugins.pidusage([process.pid, ...pids]);
|
||||||
|
|
||||||
|
// lets compute cpu usage
|
||||||
|
let cpuPercentage = 0;
|
||||||
|
for (const stat of Object.keys(stats)) {
|
||||||
|
if (!stats[stat]) continue;
|
||||||
|
cpuPercentage += stats[stat].cpu;
|
||||||
|
}
|
||||||
|
let cpuUsageText = `${Math.round(cpuPercentage * 100) / 100} %`;
|
||||||
|
|
||||||
|
// lets compute memory usage
|
||||||
|
let memoryUsageBytes = 0;
|
||||||
|
for (const stat of Object.keys(stats)) {
|
||||||
|
if (!stats[stat]) continue;
|
||||||
|
memoryUsageBytes += stats[stat].memory;
|
||||||
|
}
|
||||||
|
let memoryPercentage = Math.round((memoryUsageBytes / 1000000000) * 100 * 100) / 100;
|
||||||
|
let memoryUsageText = `${memoryPercentage}% | ${this.formatBytes(memoryUsageBytes)} / ${this.formatBytes(1000000000)}`;
|
||||||
|
|
||||||
|
console.log(`${cpuUsageText} ||| ${memoryUsageText} `);
|
||||||
|
|
||||||
const returnMetrics: interfaces.IMetricsSnapshot = {
|
const returnMetrics: interfaces.IMetricsSnapshot = {
|
||||||
originalMetrics,
|
|
||||||
process_cpu_seconds_total: (
|
process_cpu_seconds_total: (
|
||||||
originalMetrics.find((metricSet) => metricSet.name === 'process_cpu_seconds_total') as any
|
originalMetrics.find((metricSet) => metricSet.name === 'process_cpu_seconds_total') as any
|
||||||
).values[0].value,
|
).values[0].value,
|
||||||
@ -92,25 +89,16 @@ export class SmartMetrics {
|
|||||||
(metricSet) => metricSet.name === 'nodejs_heap_size_total_bytes'
|
(metricSet) => metricSet.name === 'nodejs_heap_size_total_bytes'
|
||||||
) as any
|
) as any
|
||||||
).values[0].value,
|
).values[0].value,
|
||||||
cpuPercentage: Math.round(this.getCpuUsagePercentage() * 100) / 100,
|
cpuPercentage,
|
||||||
memoryUsageText: this.formatBytes(
|
cpuUsageText,
|
||||||
(
|
memoryPercentage,
|
||||||
originalMetrics.find(
|
memoryUsageBytes,
|
||||||
(metricSet) => metricSet.name === 'nodejs_heap_size_total_bytes'
|
memoryUsageText,
|
||||||
) as any
|
|
||||||
).values[0].value
|
|
||||||
),
|
|
||||||
memoryPercentage:
|
|
||||||
Math.round(((
|
|
||||||
originalMetrics.find(
|
|
||||||
(metricSet) => metricSet.name === 'nodejs_heap_size_total_bytes'
|
|
||||||
) as any
|
|
||||||
).values[0].value /
|
|
||||||
plugins.os.totalmem()) *
|
|
||||||
100 * 100) / 100,
|
|
||||||
};
|
};
|
||||||
return returnMetrics;
|
return returnMetrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async stop() {}
|
public stop() {
|
||||||
|
this.started = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
// this might be extracted into a package @pushrocks/smartmetrics-interfaces in the future
|
// this might be extracted into a package @pushrocks/smartmetrics-interfaces in the future
|
||||||
export interface IMetricsSnapshot {
|
export interface IMetricsSnapshot {
|
||||||
originalMetrics: any[];
|
|
||||||
process_cpu_seconds_total: number;
|
process_cpu_seconds_total: number;
|
||||||
nodejs_active_handles_total: number;
|
nodejs_active_handles_total: number;
|
||||||
nodejs_active_requests_total: number;
|
nodejs_active_requests_total: number;
|
||||||
nodejs_heap_size_total_bytes: number;
|
nodejs_heap_size_total_bytes: number;
|
||||||
cpuPercentage: number;
|
cpuPercentage: number;
|
||||||
|
cpuUsageText: string;
|
||||||
memoryPercentage: number;
|
memoryPercentage: number;
|
||||||
|
memoryUsageBytes: number;
|
||||||
memoryUsageText: string;
|
memoryUsageText: string;
|
||||||
}
|
}
|
@ -15,8 +15,12 @@ export {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
|
import pidusage from 'pidusage';
|
||||||
|
import pidtree from 'pidtree';
|
||||||
import * as promClient from 'prom-client';
|
import * as promClient from 'prom-client';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
pidusage,
|
||||||
|
pidtree,
|
||||||
promClient
|
promClient
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user