Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@esmj/monitor

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esmj/monitor - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

53

dist/index.js

@@ -329,5 +329,22 @@ 'use strict';

return this.#calculate(array, number);
return this.#calculatePercentile(array, number);
}
trend(key, limit) {
let array = this.#getValues(key);
array = array.slice(
!limit || limit > array.length ? 0 : array.length - limit,
array.length
);
const { slope, yIntercept } = this.#getLinearRegression(array);
return {
slope,
yIntercept,
predict: (x = array.length + 1) => slope * x + yIntercept,
};
}
#getValues(key) {

@@ -343,3 +360,35 @@ const keys = key?.split('.') ?? [];

#calculate(array, number) {
#getLinearRegression(array) {
const { sumY, sumX, sumX2, sumXY } = array.reduce(
(result, value, index) => {
const x = value?.x ?? index + 1;
const y = value?.y ?? value;
result.sumX += x;
result.sumY += y;
result.sumX2 += x * x;
result.sumXY += x * y;
return result;
},
{
sumY: 0,
sumX: 0,
sumX2: 0,
sumXY: 0,
}
);
const divisor = array.length * sumX2 - sumX * sumX;
if (divisor === 0) {
return { slope: 0, yIntercept: 0 };
}
const yIntercept = (sumY * sumX2 - sumX * sumXY) / divisor;
const slope = (array.length * sumXY - sumX * sumY) / divisor;
return { slope, yIntercept };
}
#calculatePercentile(array, number) {
if (!array.length) {

@@ -346,0 +395,0 @@ return undefined;

2

package.json
{
"name": "@esmj/monitor",
"version": "0.3.0",
"version": "0.4.0",
"description": "Node.js performance measurement metrics (cpu, memory, event loop, gc)",

@@ -5,0 +5,0 @@ "keywords": [

@@ -114,3 +114,3 @@ # Monitor

#### add(metric)
Monitoring start measure node metric.
Monitoring add measure new metric.

@@ -141,6 +141,6 @@ ##### metric

FIFO size of array for calculating percentile.
FIFO size of array for calculating percentile and linear regressions.
#### percentile(key, value)
Monitoring start measure node metric.
#### percentile(key, number)
Returns defined percentile for measured metric

@@ -153,6 +153,21 @@ ##### key

##### value
##### number
Type: `Number`
Percentile number for FIFO array
Percentile number for FIFO array
#### trend(key, limit)
Returns linear regression variables `slope`, `yIntercept` and `predict` function for measured metric.
##### key
Type: `String`
Path in measured metric structure.
##### limit
Type: `Number`
Defined how much records use for calculating linear regression. Default is use all records from FIFO array.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc