@autofleet/nitur 1.3.1 → 1.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/alive-endpoint/index.d.ts +6 -0
- package/lib/alive-endpoint/index.js +44 -0
- package/lib/cloud-profiler/index.d.ts +1 -0
- package/lib/cloud-profiler/index.js +16 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +31 -0
- package/lib/logger.d.ts +2 -0
- package/lib/logger.js +4 -0
- package/lib/newrelic/index.d.ts +4 -0
- package/lib/newrelic/index.js +38 -0
- package/package.json +1 -1
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const logger_1 = __importDefault(require("../logger"));
|
|
16
|
+
exports.default = ({ rabbit = null, sequelize = null, redis = null, }) => (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
try {
|
|
18
|
+
if (rabbit) {
|
|
19
|
+
const isRabbitAlive = yield rabbit.isConnected();
|
|
20
|
+
if (!isRabbitAlive) {
|
|
21
|
+
throw new Error('Rabbit is not alive');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (sequelize) {
|
|
25
|
+
const [[{ status }]] = yield sequelize.query('select \'ok\' as status');
|
|
26
|
+
if (status !== 'ok') {
|
|
27
|
+
throw new Error('Sequelize is not alive');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (redis) {
|
|
31
|
+
yield redis.ping();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch (err) {
|
|
35
|
+
res.status(500);
|
|
36
|
+
res.json({ err });
|
|
37
|
+
logger_1.default.error('Error on alive endpoint', { err });
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
res.json({
|
|
41
|
+
status: 'ok',
|
|
42
|
+
});
|
|
43
|
+
return true;
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const cloudProfilerReporter: (options?: any) => void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cloudProfilerReporter = void 0;
|
|
4
|
+
const profiler_1 = require("@google-cloud/profiler");
|
|
5
|
+
const defaultOptions = {
|
|
6
|
+
service: `${process.env.ENV_NAME}.${process.env.AF_SERVICE_NAME}`,
|
|
7
|
+
version: process.env.VERSION,
|
|
8
|
+
};
|
|
9
|
+
exports.cloudProfilerReporter = (options) => {
|
|
10
|
+
profiler_1.start({
|
|
11
|
+
serviceContext: {
|
|
12
|
+
service: (options === null || options === void 0 ? void 0 : options.service) || defaultOptions.service,
|
|
13
|
+
version: (options === null || options === void 0 ? void 0 : options.version) || defaultOptions.version,
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
package/lib/index.d.ts
ADDED
package/lib/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.cloudProfiler = exports.aliveEndpoint = exports.newrelic = void 0;
|
|
26
|
+
const newrelic = __importStar(require("./newrelic"));
|
|
27
|
+
exports.newrelic = newrelic;
|
|
28
|
+
const alive_endpoint_1 = __importDefault(require("./alive-endpoint"));
|
|
29
|
+
exports.aliveEndpoint = alive_endpoint_1.default;
|
|
30
|
+
const cloudProfiler = __importStar(require("./cloud-profiler"));
|
|
31
|
+
exports.cloudProfiler = cloudProfiler;
|
package/lib/logger.d.ts
ADDED
package/lib/logger.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const connectionPoolReporter: (sequelize: any, interval?: number) => any;
|
|
2
|
+
export declare const stopConnectionPoolReporter: (intervalId: any) => void;
|
|
3
|
+
export declare const nonHeapMemoryReporter: (interval?: number) => any;
|
|
4
|
+
export declare const stopNonHeapMemoryReporter: (intervalId: any) => void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.stopNonHeapMemoryReporter = exports.nonHeapMemoryReporter = exports.stopConnectionPoolReporter = exports.connectionPoolReporter = void 0;
|
|
7
|
+
if (!process.env.NEW_RELIC_KEY) {
|
|
8
|
+
console.log('New Relic key not found. Skipping New Relic initialization.');
|
|
9
|
+
process.env.NEW_RELIC_ENABLED = 'false';
|
|
10
|
+
}
|
|
11
|
+
const newrelic_1 = __importDefault(require("newrelic"));
|
|
12
|
+
const { memoryUsage } = process;
|
|
13
|
+
const parseBytes = bytes => bytes / 1024 / 1024;
|
|
14
|
+
exports.connectionPoolReporter = (sequelize, interval = 5000) => {
|
|
15
|
+
if (process.env.NEW_RELIC_KEY) {
|
|
16
|
+
const intervalId = setInterval(() => {
|
|
17
|
+
newrelic_1.default.recordMetric('SequelizePool/WaitingConnections', sequelize.connectionManager.pool.waiting);
|
|
18
|
+
newrelic_1.default.recordMetric('SequelizePool/UsingConnections', sequelize.connectionManager.pool.using);
|
|
19
|
+
newrelic_1.default.recordMetric('SequelizePool/AvailableConnections', sequelize.connectionManager.pool.available);
|
|
20
|
+
newrelic_1.default.recordMetric('SequelizePool/Utilization', sequelize.connectionManager.pool.using / sequelize.connectionManager.pool.available);
|
|
21
|
+
}, interval);
|
|
22
|
+
return intervalId;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
exports.stopConnectionPoolReporter = (intervalId) => clearInterval(intervalId);
|
|
26
|
+
exports.nonHeapMemoryReporter = (interval = 5000) => {
|
|
27
|
+
if (process.env.NEW_RELIC_KEY) {
|
|
28
|
+
const intervalId = setInterval(() => {
|
|
29
|
+
const { rss, heapUsed, arrayBuffers, external, } = memoryUsage();
|
|
30
|
+
newrelic_1.default.recordMetric('MemoryUsage/rss', parseBytes(rss));
|
|
31
|
+
newrelic_1.default.recordMetric('MemoryUsage/heapUsed', parseBytes(heapUsed));
|
|
32
|
+
newrelic_1.default.recordMetric('MemoryUsage/arrayBuffers', parseBytes(arrayBuffers));
|
|
33
|
+
newrelic_1.default.recordMetric('MemoryUsage/external', parseBytes(external));
|
|
34
|
+
}, interval);
|
|
35
|
+
return intervalId;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.stopNonHeapMemoryReporter = (intervalId) => clearInterval(intervalId);
|