under-pressure
Advanced tools
Comparing version 5.3.0 to 5.4.0
@@ -23,3 +23,3 @@ import { | ||
interface FastifyInstance { | ||
memoryUsage(): { heapUsed: number; rssBytes: number; eventLoopDelay: number }; | ||
memoryUsage(): { heapUsed: number; rssBytes: number; eventLoopDelay: number; eventLoopUtilized: number }; | ||
} | ||
@@ -26,0 +26,0 @@ } |
11
index.js
@@ -42,3 +42,3 @@ 'use strict' | ||
let elu | ||
let eventLoopUtilizationVal = 0 | ||
let eventLoopUtilized = 0 | ||
@@ -143,5 +143,5 @@ if (monitorEventLoopDelay) { | ||
if (elu) { | ||
eventLoopUtilizationVal = eventLoopUtilization(elu).utilization | ||
eventLoopUtilized = eventLoopUtilization(elu).utilization | ||
} else { | ||
eventLoopUtilizationVal = 0 | ||
eventLoopUtilized = 0 | ||
} | ||
@@ -179,3 +179,3 @@ } | ||
if (checkMaxEventLoopUtilization && eventLoopUtilizationVal > maxEventLoopUtilization) { | ||
if (checkMaxEventLoopUtilization && eventLoopUtilized > maxEventLoopUtilization) { | ||
sendError(reply, next) | ||
@@ -197,3 +197,4 @@ return | ||
rssBytes, | ||
heapUsed | ||
heapUsed, | ||
eventLoopUtilized | ||
} | ||
@@ -200,0 +201,0 @@ } |
{ | ||
"name": "under-pressure", | ||
"version": "5.3.0", | ||
"version": "5.4.0", | ||
"description": "Measure process load with automatic handling of 'Service Unavailable' plugin for Fastify.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -7,3 +7,3 @@ # under-pressure | ||
Measure process load with automatic handling of *"Service Unavailable"* plugin for Fastify. | ||
It can check `maxEventLoopDelay`, `maxHeapUsedBytes` and `maxRssBytes` values. | ||
It can check `maxEventLoopDelay`, `maxHeapUsedBytes`, `maxRssBytes` and `maxEventLoopUtilization` values. | ||
You can also specify custom health check, to verify the status of | ||
@@ -33,3 +33,4 @@ external resources. | ||
maxHeapUsedBytes: 100000000, | ||
maxRssBytes: 100000000 | ||
maxRssBytes: 100000000, | ||
maxEventLoopUtilization:0.98 | ||
}) | ||
@@ -71,9 +72,11 @@ | ||
The default value for `maxEventLoopDelay`, `maxHeapUsedBytes` and `maxRssBytes` is `0`. | ||
The default value for `maxEventLoopDelay`, `maxHeapUsedBytes`, `maxRssBytes` and `maxEventLoopUtilization` is `0`. | ||
If the value is `0` the check will not be performed. | ||
Since [`eventLoopUtilization`](https://nodejs.org/api/perf_hooks.html#perf_hooks_performance_eventlooputilization_utilization1_utilization2) is only available in Node version 14.0.0 and 12.19.0 the check will be disbaled in other versions. | ||
Thanks to the encapsulation model of Fastify, you can selectively use this plugin in some subset of routes or even with different thresholds in different plugins. | ||
#### `memoryUsage` | ||
This plugin also exposes a function that will tell you the current values of `heapUsed`, `rssBytes` and `eventLoopDelay`. | ||
This plugin also exposes a function that will tell you the current values of `heapUsed`, `rssBytes`, `eventLoopDelay` and `eventLoopUtilized`. | ||
```js | ||
@@ -80,0 +83,0 @@ console.log(fastify.memoryUsage()) |
@@ -254,3 +254,3 @@ 'use strict' | ||
test('memoryUsage name space', t => { | ||
t.plan(8) | ||
t.plan(9) | ||
@@ -261,3 +261,4 @@ const fastify = Fastify() | ||
maxHeapUsedBytes: 100000000, | ||
maxRssBytes: 100000000 | ||
maxRssBytes: 100000000, | ||
maxEventLoopUtilization: 0.85 | ||
}) | ||
@@ -269,2 +270,3 @@ | ||
t.true(fastify.memoryUsage().rssBytes > 0) | ||
t.true(fastify.memoryUsage().eventLoopUtilized >= 0) | ||
reply.send({ hello: 'world' }) | ||
@@ -299,3 +301,3 @@ }) | ||
test('memoryUsage name space (without check)', t => { | ||
t.plan(8) | ||
t.plan(9) | ||
@@ -309,2 +311,3 @@ const fastify = Fastify() | ||
t.true(fastify.memoryUsage().rssBytes > 0) | ||
t.true(fastify.memoryUsage().eventLoopUtilized >= 0) | ||
reply.send({ hello: 'world' }) | ||
@@ -311,0 +314,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35899
927
157