Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
537df1d53e | |||
352d0f8a1e | |||
8454244f3b | |||
4b6d6feea1 | |||
01306ed3f9 | |||
2a2ca66708 | |||
299e50cbf7 | |||
1e6af24df0 | |||
66f0dc6815 | |||
7d703fe57e | |||
2ddccdaab1 | |||
173b3e2b19 | |||
df7a499c1d | |||
173df91528 | |||
057a0a329e | |||
e53bebf7a1 | |||
c4f5e9338a | |||
dad2bc26fc | |||
29609eb5ba | |||
0292d9bc13 | |||
69af53a30a | |||
121bfdad43 |
66
.gitea/workflows/default_nottags.yaml
Normal file
66
.gitea/workflows/default_nottags.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
name: Default (not tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags-ignore:
|
||||||
|
- '**'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install pnpm and npmci
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
|
||||||
|
- name: Run npm prepare
|
||||||
|
run: npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
124
.gitea/workflows/default_tags.yaml
Normal file
124
.gitea/workflows/default_tags.yaml
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
name: Default (tags)
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
|
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@gitea.lossless.digital/${{gitea.repository}}.git
|
||||||
|
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
|
||||||
|
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
|
||||||
|
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
|
||||||
|
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
security:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
continue-on-error: true
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Audit production dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --prod
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
- name: Audit development dependencies
|
||||||
|
run: |
|
||||||
|
npmci command npm config set registry https://registry.npmjs.org
|
||||||
|
npmci command pnpm audit --audit-level=high --dev
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
test:
|
||||||
|
if: ${{ always() }}
|
||||||
|
needs: security
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Test stable
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm test
|
||||||
|
|
||||||
|
- name: Test build
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
npmci npm build
|
||||||
|
|
||||||
|
release:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Release
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm publish
|
||||||
|
|
||||||
|
metadata:
|
||||||
|
needs: test
|
||||||
|
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
container:
|
||||||
|
image: ${{ env.IMAGE }}
|
||||||
|
continue-on-error: true
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Prepare
|
||||||
|
run: |
|
||||||
|
pnpm install -g pnpm
|
||||||
|
pnpm install -g @shipzone/npmci
|
||||||
|
npmci npm prepare
|
||||||
|
|
||||||
|
- name: Code quality
|
||||||
|
run: |
|
||||||
|
npmci command npm install -g typescript
|
||||||
|
npmci npm install
|
||||||
|
|
||||||
|
- name: Trigger
|
||||||
|
run: npmci trigger
|
||||||
|
|
||||||
|
- name: Build docs and upload artifacts
|
||||||
|
run: |
|
||||||
|
npmci node install stable
|
||||||
|
npmci npm install
|
||||||
|
pnpm install -g @gitzone/tsdoc
|
||||||
|
npmci command tsdoc
|
||||||
|
continue-on-error: true
|
@ -12,20 +12,12 @@ stages:
|
|||||||
- release
|
- release
|
||||||
- metadata
|
- metadata
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- npm install -g @shipzone/npmci
|
||||||
|
|
||||||
# ====================
|
# ====================
|
||||||
# security stage
|
# security stage
|
||||||
# ====================
|
# ====================
|
||||||
mirror:
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci git mirror
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
auditProductionDependencies:
|
auditProductionDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
stage: security
|
stage: security
|
||||||
@ -36,6 +28,7 @@ auditProductionDependencies:
|
|||||||
- npmci command npm audit --audit-level=high --only=prod --production
|
- npmci command npm audit --audit-level=high --only=prod --production
|
||||||
tags:
|
tags:
|
||||||
- docker
|
- docker
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
auditDevDependencies:
|
auditDevDependencies:
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||||
@ -96,10 +89,9 @@ codequality:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
script:
|
script:
|
||||||
- npmci command npm install -g tslint typescript
|
- npmci command npm install -g typescript
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
@ -119,11 +111,10 @@ trigger:
|
|||||||
pages:
|
pages:
|
||||||
stage: metadata
|
stage: metadata
|
||||||
script:
|
script:
|
||||||
- npmci node install lts
|
- npmci node install stable
|
||||||
- npmci command npm install -g @gitzone/tsdoc
|
|
||||||
- npmci npm prepare
|
- npmci npm prepare
|
||||||
- npmci npm install
|
- npmci npm install
|
||||||
- npmci command tsdoc
|
- npmci command npm run buildDocs
|
||||||
tags:
|
tags:
|
||||||
- lossless
|
- lossless
|
||||||
- docker
|
- docker
|
||||||
|
24
.vscode/launch.json
vendored
24
.vscode/launch.json
vendored
@ -2,28 +2,10 @@
|
|||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"configurations": [
|
||||||
{
|
{
|
||||||
"name": "current file",
|
"command": "npm test",
|
||||||
"type": "node",
|
"name": "Run npm test",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"args": [
|
"type": "node-terminal"
|
||||||
"${relativeFile}"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "test.ts",
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"args": [
|
|
||||||
"test/test.ts"
|
|
||||||
],
|
|
||||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
|
||||||
"cwd": "${workspaceRoot}",
|
|
||||||
"protocol": "inspector",
|
|
||||||
"internalConsoleOptions": "openOnSessionStart"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"githost": "gitlab.com",
|
"githost": "gitlab.com",
|
||||||
"gitscope": "pushrocks",
|
"gitscope": "pushrocks",
|
||||||
"gitrepo": "smartmetrics",
|
"gitrepo": "smartmetrics",
|
||||||
"shortDescription": "easy system metrics",
|
"description": "easy system metrics",
|
||||||
"npmPackagename": "@pushrocks/smartmetrics",
|
"npmPackagename": "@pushrocks/smartmetrics",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"projectDomain": "push.rocks"
|
"projectDomain": "push.rocks"
|
||||||
|
25869
package-lock.json
generated
25869
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
33
package.json
33
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartmetrics",
|
"name": "@pushrocks/smartmetrics",
|
||||||
"version": "1.0.13",
|
"version": "2.0.6",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "easy system metrics",
|
"description": "easy system metrics",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@ -9,16 +9,16 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/ --web)",
|
"test": "(tstest test/ --web)",
|
||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)",
|
||||||
|
"buildDocs": "tsdoc"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.66",
|
||||||
"@gitzone/tsbundle": "^1.0.78",
|
"@gitzone/tsbundle": "^2.0.8",
|
||||||
"@gitzone/tstest": "^1.0.44",
|
"@gitzone/tsrun": "^1.2.42",
|
||||||
"@pushrocks/tapbundle": "^3.2.9",
|
"@gitzone/tstest": "^1.0.74",
|
||||||
"@types/node": "^16.6.1",
|
"@pushrocks/tapbundle": "^5.0.8",
|
||||||
"tslint": "^6.1.3",
|
"@types/node": "^20.3.3"
|
||||||
"tslint-config-prettier": "^1.15.0"
|
|
||||||
},
|
},
|
||||||
"browserslist": [
|
"browserslist": [
|
||||||
"last 1 chrome versions"
|
"last 1 chrome versions"
|
||||||
@ -36,11 +36,12 @@
|
|||||||
"readme.md"
|
"readme.md"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartdelay": "^2.0.13",
|
"@pushrocks/smartdelay": "^3.0.1",
|
||||||
"@pushrocks/smartlog": "^2.0.44",
|
"@pushrocks/smartlog": "^3.0.2",
|
||||||
"@types/pidusage": "^2.0.1",
|
"@types/pidusage": "^2.0.2",
|
||||||
"pidtree": "^0.5.0",
|
"pidtree": "^0.6.0",
|
||||||
"pidusage": "^2.0.21",
|
"pidusage": "^3.0.2",
|
||||||
"prom-client": "^13.2.0"
|
"prom-client": "^14.2.0"
|
||||||
}
|
},
|
||||||
|
"type": "module"
|
||||||
}
|
}
|
||||||
|
4605
pnpm-lock.yaml
generated
Normal file
4605
pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -21,7 +21,6 @@ Code Style | [](htt
|
|||||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
@ -33,7 +32,6 @@ We are always happy for code contributions. If you are not the code contributing
|
|||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
## Legal
|
||||||
|
> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
|
|
||||||
export {
|
export { smartlog };
|
||||||
smartlog
|
|
||||||
}
|
|
||||||
|
12
test/test.ts
12
test/test.ts
@ -1,18 +1,18 @@
|
|||||||
import * as plugins from './plugins';
|
import * as plugins from './plugins.js';
|
||||||
|
|
||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartmetrics from '../ts/index';
|
import * as smartmetrics from '../ts/index.js';
|
||||||
|
|
||||||
let testSmartMetrics: smartmetrics.SmartMetrics;
|
let testSmartMetrics: smartmetrics.SmartMetrics;
|
||||||
|
|
||||||
tap.test('should create a smartmetrics instance', async () => {
|
tap.test('should create a smartmetrics instance', async () => {
|
||||||
const logger = new plugins.smartlog.Smartlog({
|
const logger = new plugins.smartlog.Smartlog({
|
||||||
logContext: null,
|
logContext: null,
|
||||||
minimumLogLevel: 'silly'
|
minimumLogLevel: 'silly',
|
||||||
});
|
});
|
||||||
logger.enableConsole();
|
logger.enableConsole();
|
||||||
testSmartMetrics = new smartmetrics.SmartMetrics(logger, 'testContainer');
|
testSmartMetrics = new smartmetrics.SmartMetrics(logger, 'testContainer');
|
||||||
expect(testSmartMetrics).to.be.instanceOf(smartmetrics.SmartMetrics);
|
expect(testSmartMetrics).toBeInstanceOf(smartmetrics.SmartMetrics);
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should start smartmetrics', async () => {
|
tap.test('should start smartmetrics', async () => {
|
||||||
@ -20,8 +20,8 @@ tap.test('should start smartmetrics', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should produce valid metrics', async (tools) => {
|
tap.test('should produce valid metrics', async (tools) => {
|
||||||
console.log('calling .getMetrics from Testfile:')
|
console.log('calling .getMetrics from Testfile:');
|
||||||
console.log(await testSmartMetrics.getMetrics());
|
console.log(await testSmartMetrics.getMetrics());
|
||||||
})
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* autocreated commitinfo by @pushrocks/commitinfo
|
||||||
|
*/
|
||||||
|
export const commitinfo = {
|
||||||
|
name: '@pushrocks/smartmetrics',
|
||||||
|
version: '2.0.6',
|
||||||
|
description: 'easy system metrics'
|
||||||
|
}
|
@ -1,2 +1,2 @@
|
|||||||
export * from './smartmetrics.interfaces';
|
export * from './smartmetrics.interfaces.js';
|
||||||
export * from './smartmetrics.classes.smartmetrics';
|
export * from './smartmetrics.classes.smartmetrics.js';
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import * as plugins from './smartmetrics.plugins';
|
import * as plugins from './smartmetrics.plugins.js';
|
||||||
import * as interfaces from './smartmetrics.interfaces';
|
import * as interfaces from './smartmetrics.interfaces.js';
|
||||||
import { Cipher } from 'crypto';
|
|
||||||
|
|
||||||
export class SmartMetrics {
|
export class SmartMetrics {
|
||||||
public started = false;
|
public started = false;
|
||||||
public sourceNameArg: string;
|
public sourceNameArg: string;
|
||||||
public logger: plugins.smartlog.Smartlog;
|
public logger: plugins.smartlog.Smartlog;
|
||||||
public registry: plugins.promClient.Registry;
|
public registry: plugins.promClient.Registry;
|
||||||
|
public maxMemoryMB: number;
|
||||||
|
|
||||||
public async setup() {
|
public async setup() {
|
||||||
const collectDefaultMetrics = plugins.promClient.collectDefaultMetrics;
|
const collectDefaultMetrics = plugins.promClient.collectDefaultMetrics;
|
||||||
@ -18,6 +18,32 @@ export class SmartMetrics {
|
|||||||
this.logger = loggerArg;
|
this.logger = loggerArg;
|
||||||
this.sourceNameArg = sourceNameArg;
|
this.sourceNameArg = sourceNameArg;
|
||||||
this.setup();
|
this.setup();
|
||||||
|
this.checkMemoryLimits();
|
||||||
|
}
|
||||||
|
|
||||||
|
private checkMemoryLimits() {
|
||||||
|
let heapStats = plugins.v8.getHeapStatistics();
|
||||||
|
let maxHeapSizeMB = heapStats.heap_size_limit / 1024 / 1024;
|
||||||
|
let totalSystemMemoryMB = plugins.os.totalmem() / 1024 / 1024;
|
||||||
|
|
||||||
|
let dockerMemoryLimitMB = totalSystemMemoryMB;
|
||||||
|
try {
|
||||||
|
let dockerMemoryLimitBytes = plugins.fs.readFileSync(
|
||||||
|
'/sys/fs/cgroup/memory/memory.limit_in_bytes',
|
||||||
|
'utf8'
|
||||||
|
);
|
||||||
|
dockerMemoryLimitMB = parseInt(dockerMemoryLimitBytes, 10) / 1024 / 1024;
|
||||||
|
} catch (error) {
|
||||||
|
// Ignore - this will fail if not running in a Docker container
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the maximum memory to the lower value between the Docker limit and the total system memory
|
||||||
|
this.maxMemoryMB = Math.min(totalSystemMemoryMB, dockerMemoryLimitMB, maxHeapSizeMB);
|
||||||
|
|
||||||
|
// If the maximum old space size limit is greater than the maximum available memory, throw an error
|
||||||
|
if (maxHeapSizeMB > this.maxMemoryMB) {
|
||||||
|
throw new Error('Node.js process can use more memory than is available');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public start() {
|
public start() {
|
||||||
@ -31,7 +57,7 @@ export class SmartMetrics {
|
|||||||
eventType: 'heartbeat',
|
eventType: 'heartbeat',
|
||||||
metrics: await this.getMetrics(),
|
metrics: await this.getMetrics(),
|
||||||
});
|
});
|
||||||
await plugins.smartdelay.delayFor(10000, null, true);
|
await plugins.smartdelay.delayFor(20000, null, true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
unattendedStart();
|
unattendedStart();
|
||||||
@ -54,7 +80,6 @@ export class SmartMetrics {
|
|||||||
const pids = await plugins.pidtree(process.pid);
|
const pids = await plugins.pidtree(process.pid);
|
||||||
const stats = await plugins.pidusage([process.pid, ...pids]);
|
const stats = await plugins.pidusage([process.pid, ...pids]);
|
||||||
|
|
||||||
// lets compute cpu usage
|
|
||||||
let cpuPercentage = 0;
|
let cpuPercentage = 0;
|
||||||
for (const stat of Object.keys(stats)) {
|
for (const stat of Object.keys(stats)) {
|
||||||
if (!stats[stat]) continue;
|
if (!stats[stat]) continue;
|
||||||
@ -62,19 +87,21 @@ export class SmartMetrics {
|
|||||||
}
|
}
|
||||||
let cpuUsageText = `${Math.round(cpuPercentage * 100) / 100} %`;
|
let cpuUsageText = `${Math.round(cpuPercentage * 100) / 100} %`;
|
||||||
|
|
||||||
// lets compute memory usage
|
|
||||||
let memoryUsageBytes = 0;
|
let memoryUsageBytes = 0;
|
||||||
for (const stat of Object.keys(stats)) {
|
for (const stat of Object.keys(stats)) {
|
||||||
if (!stats[stat]) continue;
|
if (!stats[stat]) continue;
|
||||||
memoryUsageBytes += stats[stat].memory;
|
memoryUsageBytes += stats[stat].memory;
|
||||||
}
|
}
|
||||||
let memoryPercentage = Math.round((memoryUsageBytes / 1000000000) * 100);
|
|
||||||
let memoryUsageText = `${memoryPercentage}% | ${this.formatBytes(memoryUsageBytes)} / ${this.formatBytes(1000000000)}`;
|
let memoryPercentage =
|
||||||
|
Math.round((memoryUsageBytes / (this.maxMemoryMB * 1024 * 1024)) * 100 * 100) / 100;
|
||||||
|
let memoryUsageText = `${memoryPercentage}% | ${this.formatBytes(
|
||||||
|
memoryUsageBytes
|
||||||
|
)} / ${this.formatBytes(this.maxMemoryMB * 1024 * 1024)}`;
|
||||||
|
|
||||||
console.log(`${cpuUsageText} ||| ${memoryUsageText} `);
|
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,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
// 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;
|
||||||
|
@ -1,26 +1,19 @@
|
|||||||
// node native
|
// node native
|
||||||
|
import * as v8 from 'v8';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
|
import * as fs from 'fs';
|
||||||
|
|
||||||
export {
|
export { v8, os, fs };
|
||||||
os
|
|
||||||
}
|
|
||||||
|
|
||||||
// pushrocks scope
|
// pushrocks scope
|
||||||
import * as smartdelay from '@pushrocks/smartdelay';
|
import * as smartdelay from '@pushrocks/smartdelay';
|
||||||
import * as smartlog from '@pushrocks/smartlog';
|
import * as smartlog from '@pushrocks/smartlog';
|
||||||
|
|
||||||
export {
|
export { smartdelay, smartlog };
|
||||||
smartdelay,
|
|
||||||
smartlog
|
|
||||||
}
|
|
||||||
|
|
||||||
// third party scope
|
// third party scope
|
||||||
import pidusage from 'pidusage';
|
import pidusage from 'pidusage';
|
||||||
import pidtree from 'pidtree';
|
import pidtree from 'pidtree';
|
||||||
import * as promClient from 'prom-client';
|
import * as promClient from 'prom-client';
|
||||||
|
|
||||||
export {
|
export { pidusage, pidtree, promClient };
|
||||||
pidusage,
|
|
||||||
pidtree,
|
|
||||||
promClient
|
|
||||||
}
|
|
||||||
|
11
tsconfig.json
Normal file
11
tsconfig.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"verbatimModuleSyntax": true,
|
||||||
|
}
|
||||||
|
}
|
17
tslint.json
17
tslint.json
@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": ["tslint:latest", "tslint-config-prettier"],
|
|
||||||
"rules": {
|
|
||||||
"semicolon": [true, "always"],
|
|
||||||
"no-console": false,
|
|
||||||
"ordered-imports": false,
|
|
||||||
"object-literal-sort-keys": false,
|
|
||||||
"member-ordering": {
|
|
||||||
"options":{
|
|
||||||
"order": [
|
|
||||||
"static-method"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"defaultSeverity": "warning"
|
|
||||||
}
|
|
Reference in New Issue
Block a user