tsoa
This commit is contained in:
11
node_modules/@hapi/heavy/LICENSE.md
generated
vendored
Executable file
11
node_modules/@hapi/heavy/LICENSE.md
generated
vendored
Executable file
@@ -0,0 +1,11 @@
|
||||
Copyright (c) 2013-2022, Project contributors
|
||||
Copyright (c) 2013-2020, Sideway Inc
|
||||
Copyright (c) 2013-2014, Walmart.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
* The names of any contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS OFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
17
node_modules/@hapi/heavy/README.md
generated
vendored
Executable file
17
node_modules/@hapi/heavy/README.md
generated
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
<a href="http://hapijs.com"><img src="https://raw.githubusercontent.com/hapijs/assets/master/images/family.png" width="180px" align="right" /></a>
|
||||
|
||||
# @hapi/heavy
|
||||
|
||||
#### Measure process load.
|
||||
|
||||
**heavy** is part of the **hapi** ecosystem and was designed to work seamlessly with the [hapi web framework](https://hapi.dev) and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out [hapi](https://hapi.dev) – they work even better together.
|
||||
|
||||
### Visit the [hapi.dev](https://hapi.dev) Developer Portal for tutorials, documentation, and support
|
||||
|
||||
## Useful resources
|
||||
|
||||
- [Documentation and API](https://hapi.dev/family/heavy/)
|
||||
- [Version status](https://hapi.dev/resources/status/#heavy) (builds, dependencies, node versions, licenses, eol)
|
||||
- [Changelog](https://hapi.dev/family/heavy/changelog/)
|
||||
- [Project policies](https://hapi.dev/policies/)
|
||||
- [Free and commercial support options](https://hapi.dev/support/)
|
||||
131
node_modules/@hapi/heavy/lib/index.js
generated
vendored
Executable file
131
node_modules/@hapi/heavy/lib/index.js
generated
vendored
Executable file
@@ -0,0 +1,131 @@
|
||||
'use strict';
|
||||
|
||||
const PerfHooks = require('perf_hooks');
|
||||
const Boom = require('@hapi/boom');
|
||||
const Hoek = require('@hapi/hoek');
|
||||
const Validate = require('@hapi/validate');
|
||||
|
||||
|
||||
const internals = {};
|
||||
|
||||
|
||||
internals.schema = Validate.object({
|
||||
sampleInterval: Validate.number().min(0),
|
||||
maxHeapUsedBytes: Validate.number().min(0),
|
||||
maxEventLoopDelay: Validate.number().min(0),
|
||||
maxEventLoopUtilization: Validate.number().min(0),
|
||||
maxRssBytes: Validate.number().min(0)
|
||||
})
|
||||
.unknown();
|
||||
|
||||
|
||||
internals.defaults = {
|
||||
sampleInterval: 0, // Frequency of load sampling in milliseconds (zero is no sampling)
|
||||
maxHeapUsedBytes: 0, // Reject requests when V8 heap is over size in bytes (zero is no max)
|
||||
maxRssBytes: 0, // Reject requests when process RSS is over size in bytes (zero is no max)
|
||||
maxEventLoopDelay: 0, // Milliseconds of delay after which requests are rejected (zero is no max)
|
||||
maxEventLoopUtilization: 0 // Max event loop utilization value after which requests are rejected (zero is no max)
|
||||
};
|
||||
|
||||
|
||||
exports.Heavy = class Heavy {
|
||||
|
||||
constructor(options) {
|
||||
|
||||
options = options || {};
|
||||
|
||||
Validate.assert(options, internals.schema, 'Invalid load monitoring options');
|
||||
this.settings = Hoek.applyToDefaults(internals.defaults, options);
|
||||
Hoek.assert(this.settings.sampleInterval || (!this.settings.maxEventLoopDelay && !this.settings.maxHeapUsedBytes && !this.settings.maxRssBytes && !this.settings.maxEventLoopUtilization), 'Load sample interval must be set to enable load limits');
|
||||
|
||||
this._eventLoopTimer = null;
|
||||
this._eventLoopUtilization = PerfHooks.performance.eventLoopUtilization();
|
||||
this._loadBench = new Hoek.Bench();
|
||||
this.load = {
|
||||
eventLoopDelay: 0,
|
||||
eventLoopUtilization: 0,
|
||||
heapUsed: 0,
|
||||
rss: 0
|
||||
};
|
||||
}
|
||||
|
||||
start() {
|
||||
|
||||
if (!this.settings.sampleInterval) {
|
||||
return;
|
||||
}
|
||||
|
||||
const loopSample = () => {
|
||||
|
||||
this._loadBench.reset();
|
||||
const measure = () => {
|
||||
|
||||
const mem = process.memoryUsage();
|
||||
|
||||
// Retain the same this.load object to keep external references valid
|
||||
|
||||
this._eventLoopUtilization = PerfHooks.performance.eventLoopUtilization(this._eventLoopUtilization);
|
||||
|
||||
this.load.eventLoopDelay = (this._loadBench.elapsed() - this.settings.sampleInterval);
|
||||
this.load.eventLoopUtilization = this._eventLoopUtilization.utilization;
|
||||
this.load.heapUsed = mem.heapUsed;
|
||||
this.load.rss = mem.rss;
|
||||
|
||||
loopSample();
|
||||
};
|
||||
|
||||
this._eventLoopTimer = setTimeout(measure, this.settings.sampleInterval);
|
||||
};
|
||||
|
||||
loopSample();
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
||||
clearTimeout(this._eventLoopTimer);
|
||||
this._eventLoopTimer = null;
|
||||
}
|
||||
|
||||
check() {
|
||||
|
||||
if (!this.settings.sampleInterval) {
|
||||
return;
|
||||
}
|
||||
|
||||
Hoek.assert(this._eventLoopTimer, 'Cannot check load when sampler is not started');
|
||||
|
||||
const elapsed = this._loadBench.elapsed();
|
||||
const load = this.load;
|
||||
|
||||
if (elapsed > this.settings.sampleInterval) {
|
||||
this._eventLoopUtilization = PerfHooks.performance.eventLoopUtilization(this._eventLoopUtilization);
|
||||
|
||||
load.eventLoopDelay = Math.max(load.eventLoopDelay, elapsed - this.settings.sampleInterval);
|
||||
load.eventLoopUtilization = this._eventLoopUtilization.utilization;
|
||||
}
|
||||
|
||||
if (this.settings.maxEventLoopDelay &&
|
||||
load.eventLoopDelay > this.settings.maxEventLoopDelay) {
|
||||
|
||||
throw Boom.serverUnavailable('Server under heavy load (event loop)', load);
|
||||
}
|
||||
|
||||
if (this.settings.maxEventLoopUtilization &&
|
||||
load.eventLoopUtilization > this.settings.maxEventLoopUtilization) {
|
||||
|
||||
throw Boom.serverUnavailable('Server under heavy load (event loop utilization)', load);
|
||||
}
|
||||
|
||||
if (this.settings.maxHeapUsedBytes &&
|
||||
load.heapUsed > this.settings.maxHeapUsedBytes) {
|
||||
|
||||
throw Boom.serverUnavailable('Server under heavy load (heap)', load);
|
||||
}
|
||||
|
||||
if (this.settings.maxRssBytes &&
|
||||
load.rss > this.settings.maxRssBytes) {
|
||||
|
||||
throw Boom.serverUnavailable('Server under heavy load (rss)', load);
|
||||
}
|
||||
}
|
||||
};
|
||||
37
node_modules/@hapi/heavy/package.json
generated
vendored
Executable file
37
node_modules/@hapi/heavy/package.json
generated
vendored
Executable file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"name": "@hapi/heavy",
|
||||
"description": "Measure process load",
|
||||
"version": "8.0.1",
|
||||
"repository": "git://github.com/hapijs/heavy",
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
"lib"
|
||||
],
|
||||
"keywords": [
|
||||
"process",
|
||||
"load",
|
||||
"measure",
|
||||
"delay",
|
||||
"memory"
|
||||
],
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"plugin:@hapi/module"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"@hapi/boom": "^10.0.1",
|
||||
"@hapi/hoek": "^11.0.2",
|
||||
"@hapi/validate": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@hapi/code": "^9.0.3",
|
||||
"@hapi/eslint-plugin": "*",
|
||||
"@hapi/lab": "^25.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "lab -t 100 -a @hapi/code -L",
|
||||
"test-cov-html": "lab -t 100 -a @hapi/code -L -r html -o coverage.html"
|
||||
},
|
||||
"license": "BSD-3-Clause"
|
||||
}
|
||||
Reference in New Issue
Block a user