@promster/metrics 4.1.13 → 6.0.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/CHANGELOG.md +53 -0
- package/dist/{modules → declarations/src}/client/client.d.ts +4 -4
- package/dist/{modules → declarations/src}/client/index.d.ts +2 -2
- package/dist/{modules → declarations/src}/create-gc-observer/create-gc-observer.d.ts +2 -2
- package/dist/{modules → declarations/src}/create-gc-observer/index.d.ts +2 -2
- package/dist/{modules → declarations/src}/create-metric-types/create-metric-types.d.ts +25 -25
- package/dist/{modules → declarations/src}/create-metric-types/index.d.ts +2 -2
- package/dist/{modules → declarations/src}/create-request-recorder/create-request-recorder.d.ts +23 -23
- package/dist/{modules → declarations/src}/create-request-recorder/index.d.ts +3 -3
- package/dist/{modules → declarations/src}/index.d.ts +9 -10
- package/dist/{modules → declarations/src}/kubernetes/index.d.ts +2 -2
- package/dist/{modules → declarations/src}/kubernetes/kubernetes.d.ts +2 -2
- package/dist/{modules → declarations/src}/normalizers/index.d.ts +9 -9
- package/dist/{modules → declarations/src}/normalizers/method/index.d.ts +2 -2
- package/dist/{modules → declarations/src}/normalizers/method/method.d.ts +2 -2
- package/dist/{modules → declarations/src}/normalizers/path/index.d.ts +2 -2
- package/dist/{modules → declarations/src}/normalizers/path/path.d.ts +2 -2
- package/dist/{modules → declarations/src}/normalizers/status-code/index.d.ts +2 -2
- package/dist/{modules → declarations/src}/normalizers/status-code/status-code.d.ts +2 -2
- package/dist/{modules → declarations/src}/summary/index.d.ts +2 -2
- package/dist/{modules → declarations/src}/summary/summary.d.ts +3 -3
- package/dist/promster-metrics.cjs.d.ts +1 -0
- package/dist/promster-metrics.cjs.dev.js +315 -0
- package/dist/promster-metrics.cjs.js +7 -0
- package/dist/promster-metrics.cjs.prod.js +315 -0
- package/package.json +13 -15
- package/dist/modules/client/client.js +0 -18
- package/dist/modules/client/client.js.map +0 -1
- package/dist/modules/client/index.js +0 -8
- package/dist/modules/client/index.js.map +0 -1
- package/dist/modules/create-gc-observer/create-gc-observer.js +0 -31
- package/dist/modules/create-gc-observer/create-gc-observer.js.map +0 -1
- package/dist/modules/create-gc-observer/index.js +0 -6
- package/dist/modules/create-gc-observer/index.js.map +0 -1
- package/dist/modules/create-metric-types/create-metric-types.js +0 -154
- package/dist/modules/create-metric-types/create-metric-types.js.map +0 -1
- package/dist/modules/create-metric-types/index.js +0 -6
- package/dist/modules/create-metric-types/index.js.map +0 -1
- package/dist/modules/create-request-recorder/create-request-recorder.js +0 -79
- package/dist/modules/create-request-recorder/create-request-recorder.js.map +0 -1
- package/dist/modules/create-request-recorder/index.js +0 -6
- package/dist/modules/create-request-recorder/index.js.map +0 -1
- package/dist/modules/index.js +0 -25
- package/dist/modules/index.js.map +0 -1
- package/dist/modules/kubernetes/index.js +0 -6
- package/dist/modules/kubernetes/index.js.map +0 -1
- package/dist/modules/kubernetes/kubernetes.js +0 -6
- package/dist/modules/kubernetes/kubernetes.js.map +0 -1
- package/dist/modules/normalizers/index.js +0 -16
- package/dist/modules/normalizers/index.js.map +0 -1
- package/dist/modules/normalizers/method/index.js +0 -6
- package/dist/modules/normalizers/method/index.js.map +0 -1
- package/dist/modules/normalizers/method/method.js +0 -6
- package/dist/modules/normalizers/method/method.js.map +0 -1
- package/dist/modules/normalizers/path/index.js +0 -6
- package/dist/modules/normalizers/path/index.js.map +0 -1
- package/dist/modules/normalizers/path/path.js +0 -10
- package/dist/modules/normalizers/path/path.js.map +0 -1
- package/dist/modules/normalizers/status-code/index.js +0 -6
- package/dist/modules/normalizers/status-code/index.js.map +0 -1
- package/dist/modules/normalizers/status-code/status-code.js +0 -6
- package/dist/modules/normalizers/status-code/status-code.js.map +0 -1
- package/dist/modules/summary/index.js +0 -7
- package/dist/modules/summary/index.js.map +0 -1
- package/dist/modules/summary/summary.js +0 -9
- package/dist/modules/summary/summary.js.map +0 -1
- package/dist/package.json +0 -61
- package/modules/client/client.ts +0 -24
- package/modules/client/index.ts +0 -3
- package/modules/create-gc-observer/create-gc-observer.ts +0 -50
- package/modules/create-gc-observer/index.ts +0 -3
- package/modules/create-metric-types/create-metric-types.spec.js +0 -146
- package/modules/create-metric-types/create-metric-types.ts +0 -229
- package/modules/create-metric-types/index.ts +0 -3
- package/modules/create-request-recorder/create-request-recorder.spec.js +0 -205
- package/modules/create-request-recorder/create-request-recorder.ts +0 -160
- package/modules/create-request-recorder/index.ts +0 -4
- package/modules/index.ts +0 -31
- package/modules/kubernetes/index.ts +0 -3
- package/modules/kubernetes/kubernetes.ts +0 -4
- package/modules/normalizers/index.ts +0 -16
- package/modules/normalizers/method/index.ts +0 -3
- package/modules/normalizers/method/method.spec.js +0 -13
- package/modules/normalizers/method/method.ts +0 -3
- package/modules/normalizers/path/index.ts +0 -3
- package/modules/normalizers/path/path.spec.js +0 -35
- package/modules/normalizers/path/path.ts +0 -9
- package/modules/normalizers/status-code/index.ts +0 -3
- package/modules/normalizers/status-code/status-code.spec.js +0 -12
- package/modules/normalizers/status-code/status-code.ts +0 -3
- package/modules/summary/index.ts +0 -3
- package/modules/summary/summary.spec.js +0 -37
- package/modules/summary/summary.ts +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,58 @@
|
|
|
1
1
|
# @promster/metrics
|
|
2
2
|
|
|
3
|
+
## 6.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#620](https://github.com/tdeekens/promster/pull/620) [`ec2a8f8`](https://github.com/tdeekens/promster/commit/ec2a8f83a94bbe63360cf7027eeba92895315a19) Thanks [@tdeekens](https://github.com/tdeekens)! - refactor: improve typings (not exposed part)
|
|
8
|
+
|
|
9
|
+
* [#618](https://github.com/tdeekens/promster/pull/618) [`bbab9ca`](https://github.com/tdeekens/promster/commit/bbab9cad6a3484e4894d159267d62e54e202812a) Thanks [@tdeekens](https://github.com/tdeekens)! - chore: update deps
|
|
10
|
+
|
|
11
|
+
## 6.0.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#601](https://github.com/tdeekens/promster/pull/601) [`17a24dc`](https://github.com/tdeekens/promster/commit/17a24dc0d735478001524c853b9f54f862153852) Thanks [@tdeekens](https://github.com/tdeekens)! - Update dependencies and apply eslint rule suggestions.
|
|
16
|
+
|
|
17
|
+
## 6.0.0
|
|
18
|
+
|
|
19
|
+
### Major Changes
|
|
20
|
+
|
|
21
|
+
- [`daf8605`](https://github.com/tdeekens/promster/commit/daf86055e64cb420c83dbc7abbcd5024d449c53f) [#557](https://github.com/tdeekens/promster/pull/557) Thanks [@tdeekens](https://github.com/tdeekens)! - # Breaking Changes
|
|
22
|
+
|
|
23
|
+
This requires your to update your peer dependency of `prom-client` to v13.
|
|
24
|
+
|
|
25
|
+
The new version of `prom-client` has additional small breaking changes `promster` has to incorporate which can leak into your application.
|
|
26
|
+
|
|
27
|
+
If you do not use our `@promster/server` package and have a `res.send(register.metrics())` you have to change it to `res.send(await register.metrics())`.
|
|
28
|
+
|
|
29
|
+
You can find more on the `prom-client` changes [here](https://github.com/siimon/prom-client/blob/master/CHANGELOG.md).
|
|
30
|
+
|
|
31
|
+
## 5.0.0
|
|
32
|
+
|
|
33
|
+
### Major Changes
|
|
34
|
+
|
|
35
|
+
- [`0eb64ca`](https://github.com/tdeekens/promster/commit/0eb64cac9a4a51dab1a556f46c97a2a5542bcc88) [#529](https://github.com/tdeekens/promster/pull/529) Thanks [@tdeekens](https://github.com/tdeekens)! - # Introduction
|
|
36
|
+
|
|
37
|
+
refactor: to use preconstruct for building
|
|
38
|
+
|
|
39
|
+
Prior TypeScript was used to build bundles. In all this should not affect consumers of this library. Under the hood preconstruct uses rollup and babel which is now instructed to build for Node.js v12 using the preset-env preset.
|
|
40
|
+
|
|
41
|
+
# Breaking Change
|
|
42
|
+
|
|
43
|
+
This release can _potentially_ be breaking for you. We want to respect semantic versioning and follow it strictly.
|
|
44
|
+
|
|
45
|
+
While migrating to preconstruct the `version` exports had to be removed as preconstruct's rollup will not resolve them. If you relied on this value you should either load the `package.json` of each module yourself or drop the usage.
|
|
46
|
+
|
|
47
|
+
```diff
|
|
48
|
+
- const { version } = require('@promster/server');
|
|
49
|
+
+ const { version } = require('@promster/server/package.json');
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- [`bdf75de`](https://github.com/tdeekens/promster/commit/bdf75dec8d0ce6be65ecccf5963f348e1a0a96b3) [#531](https://github.com/tdeekens/promster/pull/531) Thanks [@tdeekens](https://github.com/tdeekens)! - fix: update dependencies
|
|
55
|
+
|
|
3
56
|
## 4.1.13
|
|
4
57
|
|
|
5
58
|
### Patch Changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as Prometheus from 'prom-client';
|
|
2
|
-
declare const defaultRegister: Prometheus.Registry;
|
|
3
|
-
declare const configure: any;
|
|
4
|
-
export { Prometheus, defaultRegister, configure };
|
|
1
|
+
import * as Prometheus from 'prom-client';
|
|
2
|
+
declare const defaultRegister: Prometheus.Registry;
|
|
3
|
+
declare const configure: any;
|
|
4
|
+
export { Prometheus, defaultRegister, configure };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Prometheus, defaultRegister, configure } from './client';
|
|
2
|
-
export { Prometheus, defaultRegister, configure };
|
|
1
|
+
import { Prometheus, defaultRegister, configure } from './client';
|
|
2
|
+
export { Prometheus, defaultRegister, configure };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const createGcObserver: any;
|
|
2
|
-
export { createGcObserver };
|
|
1
|
+
declare const createGcObserver: any;
|
|
2
|
+
export { createGcObserver };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { createGcObserver } from './create-gc-observer';
|
|
2
|
-
export { createGcObserver };
|
|
1
|
+
import { createGcObserver } from './create-gc-observer';
|
|
2
|
+
export { createGcObserver };
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import type { DeepRequired } from 'ts-essentials';
|
|
2
|
-
import type { TPromsterOptions } from '@promster/types';
|
|
3
|
-
declare type TOptions = DeepRequired<TPromsterOptions>;
|
|
4
|
-
declare const createMetricTypes: {
|
|
5
|
-
(options: TOptions): any;
|
|
6
|
-
defaultOptions: {
|
|
7
|
-
getLabelValues: () => {};
|
|
8
|
-
labels: never[];
|
|
9
|
-
accuracies: string[];
|
|
10
|
-
metricPrefix: string;
|
|
11
|
-
metricTypes: string[];
|
|
12
|
-
metricNames: {
|
|
13
|
-
up: string[];
|
|
14
|
-
countOfGcs: string[];
|
|
15
|
-
durationOfGc: string[];
|
|
16
|
-
reclaimedInGc: string[];
|
|
17
|
-
httpRequestsTotal: string[];
|
|
18
|
-
httpRequestDurationPerPercentileInMilliseconds: string[];
|
|
19
|
-
httpRequestDurationPerPercentileInSeconds: string[];
|
|
20
|
-
httpRequestDurationInSeconds: string[];
|
|
21
|
-
httpRequestDurationInMilliseconds: string[];
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export { createMetricTypes };
|
|
1
|
+
import type { DeepRequired } from 'ts-essentials';
|
|
2
|
+
import type { TPromsterOptions } from '@promster/types';
|
|
3
|
+
declare type TOptions = DeepRequired<TPromsterOptions>;
|
|
4
|
+
declare const createMetricTypes: {
|
|
5
|
+
(options: TOptions): any;
|
|
6
|
+
defaultOptions: {
|
|
7
|
+
getLabelValues: () => {};
|
|
8
|
+
labels: never[];
|
|
9
|
+
accuracies: string[];
|
|
10
|
+
metricPrefix: string;
|
|
11
|
+
metricTypes: string[];
|
|
12
|
+
metricNames: {
|
|
13
|
+
up: string[];
|
|
14
|
+
countOfGcs: string[];
|
|
15
|
+
durationOfGc: string[];
|
|
16
|
+
reclaimedInGc: string[];
|
|
17
|
+
httpRequestsTotal: string[];
|
|
18
|
+
httpRequestDurationPerPercentileInMilliseconds: string[];
|
|
19
|
+
httpRequestDurationPerPercentileInSeconds: string[];
|
|
20
|
+
httpRequestDurationInSeconds: string[];
|
|
21
|
+
httpRequestDurationInMilliseconds: string[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export { createMetricTypes };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { createMetricTypes } from './create-metric-types';
|
|
2
|
-
export { createMetricTypes };
|
|
1
|
+
import { createMetricTypes } from './create-metric-types';
|
|
2
|
+
export { createMetricTypes };
|
package/dist/{modules → declarations/src}/create-request-recorder/create-request-recorder.d.ts
RENAMED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type { TLabelValues, TMetricTypes } from '@promster/types';
|
|
2
|
-
declare type TRecorderAccuracy = 'ms' | 's';
|
|
3
|
-
declare type TRecorderMetricType = 'httpRequestsTotal' | 'httpRequestsHistogram' | 'httpRequestsSummary';
|
|
4
|
-
declare type TRequestRecorderOptions = {
|
|
5
|
-
accuracies: TRecorderAccuracy[];
|
|
6
|
-
metricTypes: TRecorderMetricType[];
|
|
7
|
-
skip: () => boolean;
|
|
8
|
-
};
|
|
9
|
-
declare type TRecordingOptions = {
|
|
10
|
-
labels: TLabelValues;
|
|
11
|
-
};
|
|
12
|
-
declare type TRequestTiming = [number, number];
|
|
13
|
-
export declare type TRequestRecorder = (start: TRequestTiming, recordingOptions: TRecordingOptions) => void;
|
|
14
|
-
declare const sortLabels: (unsortedLabels: TLabelValues) => TLabelValues;
|
|
15
|
-
declare const endMeasurmentFrom: (start: TRequestTiming) => {
|
|
16
|
-
durationMs: number;
|
|
17
|
-
durationS: number;
|
|
18
|
-
};
|
|
19
|
-
declare const createRequestRecorder: {
|
|
20
|
-
(metricTypes: TMetricTypes, options?: Partial<TRequestRecorderOptions>): TRequestRecorder;
|
|
21
|
-
defaultOptions: TRequestRecorderOptions;
|
|
22
|
-
};
|
|
23
|
-
export { createRequestRecorder, sortLabels, endMeasurmentFrom };
|
|
1
|
+
import type { TLabelValues, TMetricTypes } from '@promster/types';
|
|
2
|
+
declare type TRecorderAccuracy = 'ms' | 's';
|
|
3
|
+
declare type TRecorderMetricType = 'httpRequestsTotal' | 'httpRequestsHistogram' | 'httpRequestsSummary';
|
|
4
|
+
declare type TRequestRecorderOptions = {
|
|
5
|
+
accuracies: TRecorderAccuracy[];
|
|
6
|
+
metricTypes: TRecorderMetricType[];
|
|
7
|
+
skip: () => boolean;
|
|
8
|
+
};
|
|
9
|
+
declare type TRecordingOptions = {
|
|
10
|
+
labels: TLabelValues;
|
|
11
|
+
};
|
|
12
|
+
declare type TRequestTiming = [number, number];
|
|
13
|
+
export declare type TRequestRecorder = (start: TRequestTiming, recordingOptions: TRecordingOptions) => void;
|
|
14
|
+
declare const sortLabels: (unsortedLabels: TLabelValues) => TLabelValues;
|
|
15
|
+
declare const endMeasurmentFrom: (start: TRequestTiming) => {
|
|
16
|
+
durationMs: number;
|
|
17
|
+
durationS: number;
|
|
18
|
+
};
|
|
19
|
+
declare const createRequestRecorder: {
|
|
20
|
+
(metricTypes: TMetricTypes, options?: Partial<TRequestRecorderOptions>): TRequestRecorder;
|
|
21
|
+
defaultOptions: TRequestRecorderOptions;
|
|
22
|
+
};
|
|
23
|
+
export { createRequestRecorder, sortLabels, endMeasurmentFrom };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { createRequestRecorder } from './create-request-recorder';
|
|
2
|
-
export type { TRequestRecorder } from './create-request-recorder';
|
|
3
|
-
export { createRequestRecorder };
|
|
1
|
+
import { createRequestRecorder } from './create-request-recorder';
|
|
2
|
+
export type { TRequestRecorder } from './create-request-recorder';
|
|
3
|
+
export { createRequestRecorder };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
export { version, Prometheus, defaultRegister, createMetricTypes, getSummary, getContentType, createRequestRecorder, createGcObserver, defaultNormalizers, normalizeStatusCode, normalizePath, normalizeMethod, isRunningInKubernetes, };
|
|
1
|
+
import { Prometheus, defaultRegister } from './client';
|
|
2
|
+
import { createMetricTypes } from './create-metric-types';
|
|
3
|
+
import { getSummary, getContentType } from './summary';
|
|
4
|
+
import { createRequestRecorder } from './create-request-recorder';
|
|
5
|
+
import { createGcObserver } from './create-gc-observer';
|
|
6
|
+
import { defaultNormalizers, normalizeStatusCode, normalizePath, normalizeMethod } from './normalizers';
|
|
7
|
+
import { isRunningInKubernetes } from './kubernetes';
|
|
8
|
+
export type { TRequestRecorder } from './create-request-recorder';
|
|
9
|
+
export { Prometheus, defaultRegister, createMetricTypes, getSummary, getContentType, createRequestRecorder, createGcObserver, defaultNormalizers, normalizeStatusCode, normalizePath, normalizeMethod, isRunningInKubernetes, };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { isRunningInKubernetes } from './kubernetes';
|
|
2
|
-
export { isRunningInKubernetes };
|
|
1
|
+
import { isRunningInKubernetes } from './kubernetes';
|
|
2
|
+
export { isRunningInKubernetes };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const isRunningInKubernetes: () => boolean;
|
|
2
|
-
export { isRunningInKubernetes };
|
|
1
|
+
declare const isRunningInKubernetes: () => boolean;
|
|
2
|
+
export { isRunningInKubernetes };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { normalizeStatusCode } from './status-code';
|
|
2
|
-
import { normalizePath } from './path';
|
|
3
|
-
import { normalizeMethod } from './method';
|
|
4
|
-
declare const defaultNormalizers: {
|
|
5
|
-
normalizeStatusCode: (statusCode: number) => number;
|
|
6
|
-
normalizePath: (path: string) => string;
|
|
7
|
-
normalizeMethod: (method: string) => string;
|
|
8
|
-
};
|
|
9
|
-
export { normalizeStatusCode, normalizePath, normalizeMethod, defaultNormalizers, };
|
|
1
|
+
import { normalizeStatusCode } from './status-code';
|
|
2
|
+
import { normalizePath } from './path';
|
|
3
|
+
import { normalizeMethod } from './method';
|
|
4
|
+
declare const defaultNormalizers: {
|
|
5
|
+
normalizeStatusCode: (statusCode: number) => number;
|
|
6
|
+
normalizePath: (path: string) => string;
|
|
7
|
+
normalizeMethod: (method: string) => string;
|
|
8
|
+
};
|
|
9
|
+
export { normalizeStatusCode, normalizePath, normalizeMethod, defaultNormalizers, };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { normalizeMethod } from './method';
|
|
2
|
-
export { normalizeMethod };
|
|
1
|
+
import { normalizeMethod } from './method';
|
|
2
|
+
export { normalizeMethod };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const normalizeMethod: (method: string) => string;
|
|
2
|
-
export { normalizeMethod };
|
|
1
|
+
declare const normalizeMethod: (method: string) => string;
|
|
2
|
+
export { normalizeMethod };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { normalizePath } from './path';
|
|
2
|
-
export { normalizePath };
|
|
1
|
+
import { normalizePath } from './path';
|
|
2
|
+
export { normalizePath };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const normalizePath: (path: string) => string;
|
|
2
|
-
export { normalizePath };
|
|
1
|
+
declare const normalizePath: (path: string) => string;
|
|
2
|
+
export { normalizePath };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { normalizeStatusCode } from './status-code';
|
|
2
|
-
export { normalizeStatusCode };
|
|
1
|
+
import { normalizeStatusCode } from './status-code';
|
|
2
|
+
export { normalizeStatusCode };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const normalizeStatusCode: (statusCode: number) => number;
|
|
2
|
-
export { normalizeStatusCode };
|
|
1
|
+
declare const normalizeStatusCode: (statusCode: number) => number;
|
|
2
|
+
export { normalizeStatusCode };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { getSummary, getContentType } from './summary';
|
|
2
|
-
export { getSummary, getContentType };
|
|
1
|
+
import { getSummary, getContentType } from './summary';
|
|
2
|
+
export { getSummary, getContentType };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare const getSummary: () => string
|
|
2
|
-
declare const getContentType: () => string;
|
|
3
|
-
export { getSummary, getContentType };
|
|
1
|
+
declare const getSummary: () => Promise<string>;
|
|
2
|
+
declare const getContentType: () => string;
|
|
3
|
+
export { getSummary, getContentType };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./declarations/src/index";
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var once = require('lodash.once');
|
|
6
|
+
var Prometheus = require('prom-client');
|
|
7
|
+
var merge = require('merge-options');
|
|
8
|
+
var requireOptional = require('optional');
|
|
9
|
+
var url = require('url');
|
|
10
|
+
var UrlValueParser = require('url-value-parser');
|
|
11
|
+
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return e[k];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n['default'] = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var once__default = /*#__PURE__*/_interopDefault(once);
|
|
35
|
+
var Prometheus__namespace = /*#__PURE__*/_interopNamespace(Prometheus);
|
|
36
|
+
var merge__default = /*#__PURE__*/_interopDefault(merge);
|
|
37
|
+
var requireOptional__default = /*#__PURE__*/_interopDefault(requireOptional);
|
|
38
|
+
var url__default = /*#__PURE__*/_interopDefault(url);
|
|
39
|
+
var UrlValueParser__default = /*#__PURE__*/_interopDefault(UrlValueParser);
|
|
40
|
+
|
|
41
|
+
const isRunningInKubernetes = () => Boolean(process.env.KUBERNETES_SERVICE_HOST);
|
|
42
|
+
|
|
43
|
+
// This is the `globalRegistry` provided by the `prom-client`
|
|
44
|
+
// We could create multiple registries with `new Prometheus.registry()`.
|
|
45
|
+
|
|
46
|
+
const defaultRegister = Prometheus__namespace.register;
|
|
47
|
+
const configure = once__default['default'](options => {
|
|
48
|
+
const shouldSkipMetricsByEnvironment = options.detectKubernetes === true && !isRunningInKubernetes();
|
|
49
|
+
|
|
50
|
+
if (!shouldSkipMetricsByEnvironment) {
|
|
51
|
+
Prometheus__namespace.collectDefaultMetrics(options);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const defaultHttpRequestDurationPercentilesInMillieconds = [0.5, 0.9, 0.95, 0.98, 0.99];
|
|
56
|
+
const defaultHttpRequestDurationInMilliseconds = [50, 100, 300, 500, 800, 1000, 1500, 2000, 3000, 5000, 10000];
|
|
57
|
+
const defaultHttpRequestDurationPercentileInSeconds = [0.5, 0.9, 0.95, 0.98, 0.99];
|
|
58
|
+
const defaultHttpRequestDurationInSeconds = [0.05, 0.1, 0.3, 0.5, 0.8, 1, 1.5, 2, 3, 10];
|
|
59
|
+
const defaultRequestLabels = ['path', 'status_code', 'method'];
|
|
60
|
+
const defaultGcLabels = ['gc_type'];
|
|
61
|
+
|
|
62
|
+
const asArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
63
|
+
|
|
64
|
+
const shouldObserveMetricsInSeconds = options => options.accuracies.includes('s');
|
|
65
|
+
|
|
66
|
+
const shouldObserveMetricsInMilliseconds = options => options.accuracies.includes('ms');
|
|
67
|
+
|
|
68
|
+
const shouldObserveHttpRequestsAsSummary = options => options.metricTypes.includes('httpRequestsSummary');
|
|
69
|
+
|
|
70
|
+
const shouldObserveHttpRequestsAsHistogram = options => options.metricTypes.includes('httpRequestsHistogram');
|
|
71
|
+
|
|
72
|
+
const shouldObserveHttpRequestsAsCounter = options => options.metricTypes.includes('httpRequestsTotal');
|
|
73
|
+
|
|
74
|
+
const defaultOptions$1 = {
|
|
75
|
+
getLabelValues: () => ({}),
|
|
76
|
+
labels: [],
|
|
77
|
+
accuracies: ['s'],
|
|
78
|
+
metricPrefix: '',
|
|
79
|
+
metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],
|
|
80
|
+
metricNames: {
|
|
81
|
+
up: ['up'],
|
|
82
|
+
countOfGcs: ['nodejs_gc_runs_total'],
|
|
83
|
+
durationOfGc: ['nodejs_gc_pause_seconds_total'],
|
|
84
|
+
reclaimedInGc: ['nodejs_gc_reclaimed_bytes_total'],
|
|
85
|
+
httpRequestsTotal: ['http_requests_total'],
|
|
86
|
+
httpRequestDurationPerPercentileInMilliseconds: ['http_request_duration_per_percentile_milliseconds'],
|
|
87
|
+
httpRequestDurationPerPercentileInSeconds: ['http_request_duration_per_percentile_seconds'],
|
|
88
|
+
httpRequestDurationInSeconds: ['http_request_duration_seconds'],
|
|
89
|
+
httpRequestDurationInMilliseconds: ['http_request_duration_milliseconds']
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const getDefaultMetrics = options => ({
|
|
94
|
+
up: asArray(options.metricNames.up).map(nameOfUpMetric => new Prometheus__namespace.Gauge({
|
|
95
|
+
name: `${options.metricPrefix}${nameOfUpMetric}`,
|
|
96
|
+
help: '1 = up, 0 = not up'
|
|
97
|
+
})),
|
|
98
|
+
countOfGcs: asArray(options.metricNames.countOfGcs).map(nameOfCounfOfGcsMetric => new Prometheus__namespace.Counter({
|
|
99
|
+
name: `${options.metricPrefix}${nameOfCounfOfGcsMetric}`,
|
|
100
|
+
help: 'Count of total garbage collections.',
|
|
101
|
+
labelNames: defaultGcLabels
|
|
102
|
+
})),
|
|
103
|
+
durationOfGc: asArray(options.metricNames.durationOfGc).map(nameOfDurationOfGcMetric => new Prometheus__namespace.Counter({
|
|
104
|
+
name: `${options.metricPrefix}${nameOfDurationOfGcMetric}`,
|
|
105
|
+
help: 'Time spent in GC Pause in seconds.',
|
|
106
|
+
labelNames: defaultGcLabels
|
|
107
|
+
})),
|
|
108
|
+
reclaimedInGc: asArray(options.metricNames.reclaimedInGc).map(nameOfReclaimedInGcMetric => new Prometheus__namespace.Counter({
|
|
109
|
+
name: `${options.metricPrefix}${nameOfReclaimedInGcMetric}`,
|
|
110
|
+
help: 'Total number of bytes reclaimed by GC.',
|
|
111
|
+
labelNames: defaultGcLabels
|
|
112
|
+
}))
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const getHttpRequestLatencyMetricsInMilliseconds = options => ({
|
|
116
|
+
httpRequestDurationPerPercentileInMilliseconds: shouldObserveHttpRequestsAsSummary(options) && asArray(options.metricNames.httpRequestDurationPerPercentileInMilliseconds).map(nameOfHttpRequestDurationPerPercentileInMillisecondsMetric => new Prometheus__namespace.Summary({
|
|
117
|
+
name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInMillisecondsMetric}`,
|
|
118
|
+
help: 'The HTTP request latencies in milliseconds.',
|
|
119
|
+
labelNames: defaultRequestLabels.concat(options.labels).sort(),
|
|
120
|
+
percentiles: options.percentiles || defaultHttpRequestDurationPercentilesInMillieconds
|
|
121
|
+
})),
|
|
122
|
+
httpRequestDurationInMilliseconds: shouldObserveHttpRequestsAsHistogram(options) && asArray(options.metricNames.httpRequestDurationInMilliseconds).map(nameOfHttpRequestDurationInMillisecondsMetric => new Prometheus__namespace.Histogram({
|
|
123
|
+
name: `${options.metricPrefix}${nameOfHttpRequestDurationInMillisecondsMetric}`,
|
|
124
|
+
help: 'The HTTP request latencies in milliseconds.',
|
|
125
|
+
labelNames: defaultRequestLabels.concat(options.labels).sort(),
|
|
126
|
+
buckets: options.buckets || defaultHttpRequestDurationInMilliseconds
|
|
127
|
+
}))
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const getHttpRequestLatencyMetricsInSeconds = options => ({
|
|
131
|
+
httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) && asArray(options.metricNames.httpRequestDurationPerPercentileInSeconds).map(nameOfHttpRequestDurationPerPercentileInSeconds => new Prometheus__namespace.Summary({
|
|
132
|
+
name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInSeconds}`,
|
|
133
|
+
help: 'The HTTP request latencies in seconds.',
|
|
134
|
+
labelNames: defaultRequestLabels.concat(options.labels).sort(),
|
|
135
|
+
percentiles: options.percentiles || defaultHttpRequestDurationPercentileInSeconds
|
|
136
|
+
})),
|
|
137
|
+
httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options) && asArray(options.metricNames.httpRequestDurationInSeconds).map(nameOfHttpRequestDurationInSecondsMetric => new Prometheus__namespace.Histogram({
|
|
138
|
+
name: `${options.metricPrefix}${nameOfHttpRequestDurationInSecondsMetric}`,
|
|
139
|
+
help: 'The HTTP request latencies in seconds.',
|
|
140
|
+
labelNames: defaultRequestLabels.concat(options.labels).sort(),
|
|
141
|
+
buckets: options.buckets || defaultHttpRequestDurationInSeconds
|
|
142
|
+
}))
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const getHttpRequestCounterMetric = options => ({
|
|
146
|
+
httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) && asArray(options.metricNames.httpRequestsTotal).map(nameOfHttpRequestsTotalMetric => new Prometheus__namespace.Counter({
|
|
147
|
+
name: `${options.metricPrefix}${nameOfHttpRequestsTotalMetric}`,
|
|
148
|
+
help: 'The total HTTP requests.',
|
|
149
|
+
labelNames: defaultRequestLabels.concat(options.labels).sort()
|
|
150
|
+
}))
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const createMetricTypes = options => {
|
|
154
|
+
const defaultedOptions = merge__default['default'](defaultOptions$1, options);
|
|
155
|
+
configure({
|
|
156
|
+
prefix: defaultedOptions.metricPrefix
|
|
157
|
+
});
|
|
158
|
+
const defaultMetrics = getDefaultMetrics(defaultedOptions);
|
|
159
|
+
const httpRequestLatencyMetricsInMilliseconds = shouldObserveMetricsInMilliseconds(defaultedOptions) && getHttpRequestLatencyMetricsInMilliseconds(defaultedOptions);
|
|
160
|
+
const httpRequestLatencyMetricsInSeconds = shouldObserveMetricsInSeconds(defaultedOptions) && getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
|
|
161
|
+
const httpRequestCounterMetric = getHttpRequestCounterMetric(defaultedOptions);
|
|
162
|
+
return Object.assign({}, defaultMetrics, httpRequestLatencyMetricsInMilliseconds, httpRequestLatencyMetricsInSeconds, httpRequestCounterMetric);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
createMetricTypes.defaultOptions = defaultOptions$1;
|
|
166
|
+
|
|
167
|
+
const getSummary = async () => defaultRegister.metrics();
|
|
168
|
+
|
|
169
|
+
const getContentType = () => defaultRegister.contentType;
|
|
170
|
+
|
|
171
|
+
const NS_PER_SEC = 1e9;
|
|
172
|
+
const NS_PER_MS = 1e6;
|
|
173
|
+
|
|
174
|
+
const sortLabels = unsortedLabels => {
|
|
175
|
+
return Object.keys(unsortedLabels).sort((a, b) => {
|
|
176
|
+
if (a < b) {
|
|
177
|
+
return -1;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (a > b) {
|
|
181
|
+
return 1;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return 0;
|
|
185
|
+
}).reduce((sortedLabels, labelName) => {
|
|
186
|
+
sortedLabels[labelName] = unsortedLabels[labelName];
|
|
187
|
+
return sortedLabels;
|
|
188
|
+
}, {});
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const endMeasurmentFrom = start => {
|
|
192
|
+
const [seconds, nanoseconds] = process.hrtime(start);
|
|
193
|
+
return {
|
|
194
|
+
durationMs: Math.round((seconds * NS_PER_SEC + nanoseconds) / NS_PER_MS),
|
|
195
|
+
durationS: (seconds * NS_PER_SEC + nanoseconds) / NS_PER_SEC
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const shouldObserveMetricType = metricType => options => options.metricTypes.includes(metricType);
|
|
200
|
+
|
|
201
|
+
const shouldObserveMetricAccuracy = accuracy => options => options.accuracies.includes(accuracy);
|
|
202
|
+
|
|
203
|
+
const defaultOptions = {
|
|
204
|
+
accuracies: ['s'],
|
|
205
|
+
metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],
|
|
206
|
+
skip: () => false
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const createRequestRecorder = (metricTypes, options = defaultOptions) => {
|
|
210
|
+
const defaultedRecorderOptions = merge__default['default'](defaultOptions, options);
|
|
211
|
+
const shouldSkipMetricsByEnvironment = defaultedRecorderOptions.detectKubernetes && !isRunningInKubernetes();
|
|
212
|
+
const shouldObserveInSeconds = shouldObserveMetricAccuracy('s')(defaultedRecorderOptions);
|
|
213
|
+
const shouldObserveInMilliseconds = shouldObserveMetricAccuracy('ms')(defaultedRecorderOptions);
|
|
214
|
+
const shouldObserveInSummary = shouldObserveMetricType('httpRequestsSummary')(defaultedRecorderOptions);
|
|
215
|
+
const shouldObserveInHistogram = shouldObserveMetricType('httpRequestsHistogram')(defaultedRecorderOptions);
|
|
216
|
+
const shouldObserveInCounter = shouldObserveMetricType('httpRequestsTotal')(defaultedRecorderOptions);
|
|
217
|
+
return (start, recordingOptions) => {
|
|
218
|
+
const {
|
|
219
|
+
durationMs,
|
|
220
|
+
durationS
|
|
221
|
+
} = endMeasurmentFrom(start);
|
|
222
|
+
const labels = sortLabels(recordingOptions.labels);
|
|
223
|
+
|
|
224
|
+
if (shouldObserveInMilliseconds && shouldObserveInHistogram && !shouldSkipMetricsByEnvironment) {
|
|
225
|
+
metricTypes.httpRequestDurationInMilliseconds.forEach(httpRequestDurationInMillisecondsMetricType => {
|
|
226
|
+
httpRequestDurationInMillisecondsMetricType.observe(labels, durationMs);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (shouldObserveInMilliseconds && shouldObserveInSummary && !shouldSkipMetricsByEnvironment) {
|
|
231
|
+
metricTypes.httpRequestDurationPerPercentileInMilliseconds.forEach(httpRequestDurationPerPercentileInMillisecondsMetricType => {
|
|
232
|
+
httpRequestDurationPerPercentileInMillisecondsMetricType.observe(labels, durationMs);
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (shouldObserveInSeconds && shouldObserveInHistogram && !shouldSkipMetricsByEnvironment) {
|
|
237
|
+
metricTypes.httpRequestDurationInSeconds.forEach(httpRequestDurationInSecondsMetricType => {
|
|
238
|
+
httpRequestDurationInSecondsMetricType.observe(labels, durationS);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (shouldObserveInSeconds && shouldObserveInSummary && !shouldSkipMetricsByEnvironment) {
|
|
243
|
+
metricTypes.httpRequestDurationPerPercentileInSeconds.forEach(httpRequestDurationPerPercentileInSecondsMetricType => {
|
|
244
|
+
httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (shouldObserveInCounter && !shouldSkipMetricsByEnvironment) {
|
|
249
|
+
metricTypes.httpRequestsTotal.forEach(httpRequestsTotalMetricType => {
|
|
250
|
+
httpRequestsTotalMetricType.inc(labels);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
createRequestRecorder.defaultOptions = defaultOptions;
|
|
257
|
+
|
|
258
|
+
const gc = requireOptional__default['default']('gc-stats');
|
|
259
|
+
const gcTypes = {
|
|
260
|
+
0: 'unknown',
|
|
261
|
+
1: 'scavenge',
|
|
262
|
+
2: 'mark_sweep_compact',
|
|
263
|
+
3: 'scavenge_and_mark_sweep_compact',
|
|
264
|
+
4: 'incremental_marking',
|
|
265
|
+
8: 'weak_phantom',
|
|
266
|
+
15: 'all'
|
|
267
|
+
};
|
|
268
|
+
const createGcObserver = once__default['default'](metricTypes => () => {
|
|
269
|
+
if (typeof gc !== 'function') {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
gc().on('stats', stats => {
|
|
274
|
+
const gcType = gcTypes[stats.gctype];
|
|
275
|
+
metricTypes.countOfGcs.forEach(countOfGcMetricType => {
|
|
276
|
+
countOfGcMetricType.labels(gcType).inc();
|
|
277
|
+
});
|
|
278
|
+
metricTypes.durationOfGc.forEach(durationOfGcMetricType => {
|
|
279
|
+
durationOfGcMetricType.labels(gcType).inc(stats.pause / 1e9);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
if (stats.diff.usedHeapSize < 0) {
|
|
283
|
+
metricTypes.reclaimedInGc.forEach(reclaimedInGcMetricType => {
|
|
284
|
+
reclaimedInGcMetricType.labels(gcType).inc(stats.diff.usedHeapSize * -1);
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
const normalizeStatusCode = statusCode => statusCode;
|
|
291
|
+
|
|
292
|
+
const urlValueParser = new UrlValueParser__default['default']();
|
|
293
|
+
|
|
294
|
+
const normalizePath = path => urlValueParser.replacePathValues(url__default['default'].parse(path).pathname);
|
|
295
|
+
|
|
296
|
+
const normalizeMethod = method => method.toLowerCase();
|
|
297
|
+
|
|
298
|
+
const defaultNormalizers = {
|
|
299
|
+
normalizeStatusCode,
|
|
300
|
+
normalizePath,
|
|
301
|
+
normalizeMethod
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
exports.Prometheus = Prometheus__namespace;
|
|
305
|
+
exports.createGcObserver = createGcObserver;
|
|
306
|
+
exports.createMetricTypes = createMetricTypes;
|
|
307
|
+
exports.createRequestRecorder = createRequestRecorder;
|
|
308
|
+
exports.defaultNormalizers = defaultNormalizers;
|
|
309
|
+
exports.defaultRegister = defaultRegister;
|
|
310
|
+
exports.getContentType = getContentType;
|
|
311
|
+
exports.getSummary = getSummary;
|
|
312
|
+
exports.isRunningInKubernetes = isRunningInKubernetes;
|
|
313
|
+
exports.normalizeMethod = normalizeMethod;
|
|
314
|
+
exports.normalizePath = normalizePath;
|
|
315
|
+
exports.normalizeStatusCode = normalizeStatusCode;
|