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.5.0 to 0.5.1

34

dist/index.js

@@ -297,2 +297,26 @@ 'use strict';

function memo(func) {
return (function (func) {
let cache = {};
const keyGenerator = (...rest) => rest.join('-');
const clear = () => {
cache = {};
};
const memoized = (...rest) => {
const key = keyGenerator(...rest);
if (!cache[key]) {
cache[key] = func(...rest);
}
return cache[key];
};
memoized.clear = clear;
return memoized;
})(func);
}
class MetricsHistory extends observable.Observer {

@@ -305,2 +329,5 @@ #options = { limit: 60 };

this.#options = { ...this.#options, ...options };
this.percentileMemo = memo((...rest) => this.percentile(...rest));
this.trendMemo = memo((...rest) => this.trend(...rest));
}

@@ -312,2 +339,6 @@

get current() {
return this.#history[this.#history.length - 1];
}
complete() {

@@ -323,2 +354,5 @@ this.#history = [];

}
this.percentileMemo.clear();
this.trendMemo.clear();
}

@@ -325,0 +359,0 @@

2

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

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

@@ -25,4 +25,4 @@ # Monitor

const { unsubscribe } = monitor.subscribe((metrics) => {
console.log(metrics);
const { unsubscribe } = monitor.subscribe((metric) => {
console.log(metric);
// {

@@ -71,5 +71,8 @@ // cpuUsage: { user: 1692, system: 925, percent: 0.26 },

console.log(metricsHistory.percentile('memoryUsage.rss', 80)); // 61
console.log(metricsHistory.trend('memoryUsage.rss').predict()); // 65
}, 5000);
setTimeout(() => {
console.log(metricsHistory.size) // 15;
console.log(metricsHistory.current) // return last captured metric structure
unsubscribe();

@@ -159,2 +162,5 @@ monitor.stop();

#### percentileMemo(key, number)
Memoized version of percentile function. Cache is cleared after capture new metric.
#### trend(key, limit)

@@ -173,2 +179,5 @@ Returns linear regression variables `slope`, `yIntercept` and `predict` function for measured metric.

Defined how much records use for calculating linear regression. Default is use all records from FIFO array.
Defined how much records use for calculating linear regression. Default is use all records from FIFO array.
#### trendMemo(key, number)
Memoized version of trend function. Cache is cleared after capture new metric.

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