@promster/metrics 8.0.0 → 9.0.0
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/dist/declarations/src/create-gc-metrics/create-gc-metrics.d.ts +16 -0
- package/dist/declarations/src/create-gc-metrics/index.d.ts +2 -0
- package/dist/declarations/src/create-graphql-metrics/create-graphql-metrics.d.ts +18 -0
- package/dist/declarations/src/create-graphql-metrics/index.d.ts +2 -0
- package/dist/declarations/src/create-http-metrics/create-http-metrics.d.ts +18 -0
- package/dist/declarations/src/create-http-metrics/index.d.ts +2 -0
- package/dist/declarations/src/create-request-recorder/create-request-recorder.d.ts +4 -8
- package/dist/declarations/src/end-measurement-from/end-measurement-from.d.ts +5 -0
- package/dist/declarations/src/end-measurement-from/index.d.ts +2 -0
- package/dist/declarations/src/environment/index.d.ts +3 -0
- package/dist/declarations/src/{kubernetes → environment}/kubernetes.d.ts +0 -0
- package/dist/declarations/src/environment/skip-metrics-in-environment.d.ts +6 -0
- package/dist/declarations/src/index.d.ts +7 -3
- package/dist/declarations/src/sort-labels/index.d.ts +2 -0
- package/dist/declarations/src/sort-labels/sort-labels.d.ts +3 -0
- package/dist/promster-metrics.cjs.dev.js +204 -144
- package/dist/promster-metrics.cjs.prod.js +204 -144
- package/package.json +5 -5
- package/readme.md +1 -2
- package/dist/declarations/src/create-metric-types/create-metric-types.d.ts +0 -25
- package/dist/declarations/src/create-metric-types/index.d.ts +0 -2
- package/dist/declarations/src/kubernetes/index.d.ts +0 -2
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TDefaultedPromsterOptions, TGcMetrics } from '@promster/types';
|
|
2
|
+
declare const createGcMetrics: {
|
|
3
|
+
(options: TDefaultedPromsterOptions): TGcMetrics;
|
|
4
|
+
defaultOptions: {
|
|
5
|
+
getLabelValues: () => {};
|
|
6
|
+
labels: never[];
|
|
7
|
+
metricPrefix: string;
|
|
8
|
+
metricNames: {
|
|
9
|
+
up: string[];
|
|
10
|
+
countOfGcs: string[];
|
|
11
|
+
durationOfGc: string[];
|
|
12
|
+
reclaimedInGc: string[];
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export { createGcMetrics };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TDefaultedPromsterOptions, TGraphQlMetrics } from '@promster/types';
|
|
2
|
+
declare const createGraphQlMetrics: {
|
|
3
|
+
(options: TDefaultedPromsterOptions): TGraphQlMetrics;
|
|
4
|
+
defaultOptions: {
|
|
5
|
+
getLabelValues: () => {};
|
|
6
|
+
labels: never[];
|
|
7
|
+
metricPrefix: string;
|
|
8
|
+
metricTypes: string[];
|
|
9
|
+
metricNames: {
|
|
10
|
+
graphQlParseDuration: string[];
|
|
11
|
+
graphQlValidationDuration: string[];
|
|
12
|
+
graphQlResolveFieldDuration: string[];
|
|
13
|
+
graphQlRequestDuration: string[];
|
|
14
|
+
graphQlErrorsTotal: string[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export { createGraphQlMetrics };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TDefaultedPromsterOptions, THttpMetrics } from '@promster/types';
|
|
2
|
+
declare const createHttpMetrics: {
|
|
3
|
+
(options: TDefaultedPromsterOptions): THttpMetrics;
|
|
4
|
+
defaultOptions: {
|
|
5
|
+
getLabelValues: () => {};
|
|
6
|
+
labels: never[];
|
|
7
|
+
metricPrefix: string;
|
|
8
|
+
metricTypes: string[];
|
|
9
|
+
metricNames: {
|
|
10
|
+
httpRequestsTotal: string[];
|
|
11
|
+
httpRequestDurationPerPercentileInSeconds: string[];
|
|
12
|
+
httpRequestDurationInSeconds: string[];
|
|
13
|
+
httpRequestContentLengthInBytes: string[];
|
|
14
|
+
httpResponseContentLengthInBytes: string[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export { createHttpMetrics };
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import type { TPromsterOptions, TLabelValues,
|
|
1
|
+
import type { TPromsterOptions, TLabelValues, THttpMetrics, TRequestTiming } from '@promster/types';
|
|
2
|
+
import { sortLabels } from '../sort-labels';
|
|
3
|
+
import { endMeasurementFrom } from '../end-measurement-from';
|
|
2
4
|
declare type TRecordingOptions = {
|
|
3
5
|
labels: TLabelValues;
|
|
4
6
|
requestContentLength?: number;
|
|
5
7
|
responseContentLength?: number;
|
|
6
8
|
};
|
|
7
|
-
declare type TRequestTiming = [number, number];
|
|
8
9
|
export declare type TRequestRecorder = (start: TRequestTiming, recordingOptions: TRecordingOptions) => void;
|
|
9
|
-
declare const sortLabels: (unsortedLabels: TLabelValues) => TLabelValues;
|
|
10
|
-
declare const endMeasurementFrom: (start: TRequestTiming) => {
|
|
11
|
-
durationMs: number;
|
|
12
|
-
durationS: number;
|
|
13
|
-
};
|
|
14
10
|
declare const createRequestRecorder: {
|
|
15
|
-
(
|
|
11
|
+
(metrics: THttpMetrics, options?: TPromsterOptions): TRequestRecorder;
|
|
16
12
|
defaultOptions: TPromsterOptions;
|
|
17
13
|
};
|
|
18
14
|
export { createRequestRecorder, sortLabels, endMeasurementFrom };
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TPromsterOptions } from '@promster/types';
|
|
2
|
+
declare type TSkipMetricsInEnvironmentOptions = {
|
|
3
|
+
detectKubernetes?: TPromsterOptions['detectKubernetes'];
|
|
4
|
+
};
|
|
5
|
+
declare const skipMetricsInEnvironment: (options: TSkipMetricsInEnvironmentOptions) => boolean;
|
|
6
|
+
export { skipMetricsInEnvironment };
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { Prometheus, defaultRegister } from './client';
|
|
2
|
-
import {
|
|
2
|
+
import { createHttpMetrics } from './create-http-metrics';
|
|
3
|
+
import { createGraphQlMetrics } from './create-graphql-metrics';
|
|
4
|
+
import { createGcMetrics } from './create-gc-metrics';
|
|
3
5
|
import { getSummary, getContentType } from './summary';
|
|
4
6
|
import { createRequestRecorder } from './create-request-recorder';
|
|
5
7
|
import { createGcObserver } from './create-gc-observer';
|
|
6
8
|
import { defaultNormalizers, normalizeStatusCode, normalizePath, normalizeMethod } from './normalizers';
|
|
7
|
-
import { isRunningInKubernetes } from './
|
|
9
|
+
import { isRunningInKubernetes, skipMetricsInEnvironment } from './environment';
|
|
10
|
+
import { endMeasurementFrom } from './end-measurement-from';
|
|
11
|
+
import { sortLabels } from './sort-labels';
|
|
8
12
|
export type { TRequestRecorder } from './create-request-recorder';
|
|
9
|
-
export { Prometheus, defaultRegister,
|
|
13
|
+
export { Prometheus, defaultRegister, createHttpMetrics, createGraphQlMetrics, createGcMetrics, getSummary, getContentType, createRequestRecorder, createGcObserver, defaultNormalizers, normalizeStatusCode, normalizePath, normalizeMethod, isRunningInKubernetes, skipMetricsInEnvironment, endMeasurementFrom, sortLabels, };
|
|
@@ -38,31 +38,26 @@ var UrlValueParser__default = /*#__PURE__*/_interopDefault(UrlValueParser);
|
|
|
38
38
|
|
|
39
39
|
const isRunningInKubernetes = () => Boolean(process.env.KUBERNETES_SERVICE_HOST);
|
|
40
40
|
|
|
41
|
+
const skipMetricsInEnvironment = options => options.detectKubernetes === true && !isRunningInKubernetes();
|
|
42
|
+
|
|
41
43
|
// This is the `globalRegistry` provided by the `prom-client`
|
|
42
44
|
// We could create multiple registries with `new Prometheus.registry()`.
|
|
43
45
|
|
|
44
46
|
const defaultRegister = Prometheus__namespace.register;
|
|
45
47
|
const configure = once__default["default"](options => {
|
|
46
|
-
const
|
|
48
|
+
const shouldSkipMetricsInEnvironment = skipMetricsInEnvironment(options);
|
|
47
49
|
|
|
48
|
-
if (!
|
|
50
|
+
if (!shouldSkipMetricsInEnvironment) {
|
|
49
51
|
Prometheus__namespace.collectDefaultMetrics(options);
|
|
50
52
|
}
|
|
51
53
|
});
|
|
52
54
|
|
|
53
|
-
const defaultHttpRequestDurationPercentilesInMillieconds = [0.5, 0.9, 0.95, 0.98, 0.99];
|
|
54
|
-
const defaultHttpRequestDurationInMilliseconds = [50, 100, 300, 500, 800, 1000, 1500, 2000, 3000, 5000, 10000];
|
|
55
55
|
const defaultHttpRequestDurationPercentileInSeconds = [0.5, 0.9, 0.95, 0.98, 0.99];
|
|
56
56
|
const defaultHttpRequestDurationInSeconds = [0.05, 0.1, 0.3, 0.5, 0.8, 1, 1.5, 2, 3, 10];
|
|
57
57
|
const defaultHttpContentLengthInBytes = [100000, 200000, 500000, 1000000, 1500000, 2000000, 3000000, 5000000, 10000000];
|
|
58
|
-
const
|
|
59
|
-
const defaultGcLabels = ['gc_type'];
|
|
60
|
-
|
|
61
|
-
const asArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
62
|
-
|
|
63
|
-
const shouldObserveMetricsInSeconds = options => options.accuracies.includes('s');
|
|
58
|
+
const defaultLabels$2 = ['path', 'status_code', 'method'];
|
|
64
59
|
|
|
65
|
-
const
|
|
60
|
+
const asArray$2 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
66
61
|
|
|
67
62
|
const shouldObserveHttpRequestsAsSummary = options => options.metricTypes.includes('httpRequestsSummary');
|
|
68
63
|
|
|
@@ -72,218 +67,273 @@ const shouldObserveHttpRequestsAsCounter = options => options.metricTypes.includ
|
|
|
72
67
|
|
|
73
68
|
const shouldObserveHttpContentLengthAsHistogram = options => options.metricTypes.includes('httpContentLengthHistogram');
|
|
74
69
|
|
|
75
|
-
const defaultOptions$
|
|
70
|
+
const defaultOptions$4 = {
|
|
76
71
|
getLabelValues: () => ({}),
|
|
77
72
|
labels: [],
|
|
78
|
-
accuracies: ['s'],
|
|
79
73
|
metricPrefix: '',
|
|
80
74
|
metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],
|
|
81
75
|
metricNames: {
|
|
82
|
-
up: ['up'],
|
|
83
|
-
countOfGcs: ['nodejs_gc_runs_total'],
|
|
84
|
-
durationOfGc: ['nodejs_gc_pause_seconds_total'],
|
|
85
|
-
reclaimedInGc: ['nodejs_gc_reclaimed_bytes_total'],
|
|
86
76
|
httpRequestsTotal: ['http_requests_total'],
|
|
87
|
-
httpRequestDurationPerPercentileInMilliseconds: ['http_request_duration_per_percentile_milliseconds'],
|
|
88
77
|
httpRequestDurationPerPercentileInSeconds: ['http_request_duration_per_percentile_seconds'],
|
|
89
78
|
httpRequestDurationInSeconds: ['http_request_duration_seconds'],
|
|
90
|
-
httpRequestDurationInMilliseconds: ['http_request_duration_milliseconds'],
|
|
91
79
|
httpRequestContentLengthInBytes: ['http_request_content_length_bytes'],
|
|
92
80
|
httpResponseContentLengthInBytes: ['http_response_content_length_bytes']
|
|
93
81
|
}
|
|
94
82
|
};
|
|
95
83
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
name: `${options.metricPrefix}${nameOfUpMetric}`,
|
|
99
|
-
help: '1 = up, 0 = not up'
|
|
100
|
-
})),
|
|
101
|
-
countOfGcs: asArray(options.metricNames.countOfGcs).map(nameOfCountOfGcsMetric => new Prometheus__namespace.Counter({
|
|
102
|
-
name: `${options.metricPrefix}${nameOfCountOfGcsMetric}`,
|
|
103
|
-
help: 'Count of total garbage collections.',
|
|
104
|
-
labelNames: defaultGcLabels
|
|
105
|
-
})),
|
|
106
|
-
durationOfGc: asArray(options.metricNames.durationOfGc).map(nameOfDurationOfGcMetric => new Prometheus__namespace.Counter({
|
|
107
|
-
name: `${options.metricPrefix}${nameOfDurationOfGcMetric}`,
|
|
108
|
-
help: 'Time spent in GC Pause in seconds.',
|
|
109
|
-
labelNames: defaultGcLabels
|
|
110
|
-
})),
|
|
111
|
-
reclaimedInGc: asArray(options.metricNames.reclaimedInGc).map(nameOfReclaimedInGcMetric => new Prometheus__namespace.Counter({
|
|
112
|
-
name: `${options.metricPrefix}${nameOfReclaimedInGcMetric}`,
|
|
113
|
-
help: 'Total number of bytes reclaimed by GC.',
|
|
114
|
-
labelNames: defaultGcLabels
|
|
115
|
-
})),
|
|
116
|
-
httpRequestContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) && asArray(options.metricNames.httpRequestContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
|
|
84
|
+
const getMetrics$2 = options => ({
|
|
85
|
+
httpRequestContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray$2(options.metricNames.httpRequestContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
|
|
117
86
|
name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
|
|
118
87
|
help: 'The HTTP request content length in bytes.',
|
|
119
|
-
labelNames:
|
|
88
|
+
labelNames: defaultLabels$2.concat(options.labels).sort(),
|
|
120
89
|
buckets: options.buckets || defaultHttpContentLengthInBytes
|
|
121
|
-
})),
|
|
122
|
-
httpResponseContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options)
|
|
90
|
+
})) : undefined,
|
|
91
|
+
httpResponseContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray$2(options.metricNames.httpResponseContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
|
|
123
92
|
name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
|
|
124
93
|
help: 'The HTTP response content length in bytes.',
|
|
125
|
-
labelNames:
|
|
94
|
+
labelNames: defaultLabels$2.concat(options.labels).sort(),
|
|
126
95
|
buckets: options.buckets || defaultHttpContentLengthInBytes
|
|
127
|
-
}))
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
const getHttpRequestLatencyMetricsInMilliseconds = options => ({
|
|
131
|
-
httpRequestDurationPerPercentileInMilliseconds: shouldObserveHttpRequestsAsSummary(options) && asArray(options.metricNames.httpRequestDurationPerPercentileInMilliseconds).map(nameOfHttpRequestDurationPerPercentileInMillisecondsMetric => new Prometheus__namespace.Summary({
|
|
132
|
-
name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInMillisecondsMetric}`,
|
|
133
|
-
help: 'The HTTP request latencies in milliseconds.',
|
|
134
|
-
labelNames: defaultRequestLabels.concat(options.labels).sort(),
|
|
135
|
-
percentiles: options.percentiles || defaultHttpRequestDurationPercentilesInMillieconds
|
|
136
|
-
})),
|
|
137
|
-
httpRequestDurationInMilliseconds: shouldObserveHttpRequestsAsHistogram(options) && asArray(options.metricNames.httpRequestDurationInMilliseconds).map(nameOfHttpRequestDurationInMillisecondsMetric => new Prometheus__namespace.Histogram({
|
|
138
|
-
name: `${options.metricPrefix}${nameOfHttpRequestDurationInMillisecondsMetric}`,
|
|
139
|
-
help: 'The HTTP request latencies in milliseconds.',
|
|
140
|
-
labelNames: defaultRequestLabels.concat(options.labels).sort(),
|
|
141
|
-
buckets: options.buckets || defaultHttpRequestDurationInMilliseconds
|
|
142
|
-
}))
|
|
96
|
+
})) : undefined
|
|
143
97
|
});
|
|
144
98
|
|
|
145
99
|
const getHttpRequestLatencyMetricsInSeconds = options => ({
|
|
146
|
-
httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options)
|
|
100
|
+
httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) ? asArray$2(options.metricNames.httpRequestDurationPerPercentileInSeconds).map(nameOfHttpRequestDurationPerPercentileInSeconds => new Prometheus__namespace.Summary({
|
|
147
101
|
name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInSeconds}`,
|
|
148
102
|
help: 'The HTTP request latencies in seconds.',
|
|
149
|
-
labelNames:
|
|
103
|
+
labelNames: defaultLabels$2.concat(options.labels).sort(),
|
|
150
104
|
percentiles: options.percentiles || defaultHttpRequestDurationPercentileInSeconds
|
|
151
|
-
})),
|
|
152
|
-
httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options)
|
|
105
|
+
})) : undefined,
|
|
106
|
+
httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options) ? asArray$2(options.metricNames.httpRequestDurationInSeconds).map(nameOfHttpRequestDurationInSecondsMetric => new Prometheus__namespace.Histogram({
|
|
153
107
|
name: `${options.metricPrefix}${nameOfHttpRequestDurationInSecondsMetric}`,
|
|
154
108
|
help: 'The HTTP request latencies in seconds.',
|
|
155
|
-
labelNames:
|
|
109
|
+
labelNames: defaultLabels$2.concat(options.labels).sort(),
|
|
156
110
|
buckets: options.buckets || defaultHttpRequestDurationInSeconds
|
|
157
|
-
}))
|
|
111
|
+
})) : undefined
|
|
158
112
|
});
|
|
159
113
|
|
|
160
114
|
const getHttpRequestCounterMetric = options => ({
|
|
161
|
-
httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options)
|
|
115
|
+
httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) ? asArray$2(options.metricNames.httpRequestsTotal).map(nameOfHttpRequestsTotalMetric => new Prometheus__namespace.Counter({
|
|
162
116
|
name: `${options.metricPrefix}${nameOfHttpRequestsTotalMetric}`,
|
|
163
117
|
help: 'The total HTTP requests.',
|
|
164
|
-
labelNames:
|
|
165
|
-
}))
|
|
118
|
+
labelNames: defaultLabels$2.concat(options.labels).sort()
|
|
119
|
+
})) : undefined
|
|
166
120
|
});
|
|
167
121
|
|
|
168
|
-
const
|
|
169
|
-
const defaultedOptions = merge__default["default"](defaultOptions$
|
|
122
|
+
const createHttpMetrics = options => {
|
|
123
|
+
const defaultedOptions = merge__default["default"](defaultOptions$4, options);
|
|
170
124
|
configure({
|
|
171
125
|
prefix: defaultedOptions.metricPrefix
|
|
172
126
|
});
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
const httpRequestLatencyMetricsInSeconds = shouldObserveMetricsInSeconds(defaultedOptions) && getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
|
|
127
|
+
const metrics = getMetrics$2(defaultedOptions);
|
|
128
|
+
const httpRequestLatencyMetricsInSeconds = getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
|
|
176
129
|
const httpRequestCounterMetric = getHttpRequestCounterMetric(defaultedOptions);
|
|
177
|
-
return Object.assign({},
|
|
130
|
+
return Object.assign({}, metrics, httpRequestLatencyMetricsInSeconds, httpRequestCounterMetric);
|
|
178
131
|
};
|
|
179
132
|
|
|
180
|
-
|
|
133
|
+
createHttpMetrics.defaultOptions = defaultOptions$4;
|
|
181
134
|
|
|
182
|
-
const
|
|
135
|
+
const defaultGraphQlPercentiles = [0.5, 0.9, 0.95, 0.98, 0.99];
|
|
136
|
+
const defaultLabels$1 = ['operation_name'];
|
|
183
137
|
|
|
184
|
-
const
|
|
138
|
+
const asArray$1 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
185
139
|
|
|
186
|
-
const
|
|
187
|
-
const NS_PER_MS = 1e6;
|
|
140
|
+
const shouldObserveGraphQlParseDurationAsHistogram = options => options.metricTypes.includes('graphQlParseDurationHistogram');
|
|
188
141
|
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
142
|
+
const shouldObserveGraphQlValidationDurationAsHistogram = options => options.metricTypes.includes('graphQlValidationDurationHistogram');
|
|
143
|
+
|
|
144
|
+
const shouldObserveGraphQlResolveFieldDurationAsHistogram = options => options.metricTypes.includes('graphQlResolveFieldDurationHistogram');
|
|
193
145
|
|
|
194
|
-
|
|
195
|
-
|
|
146
|
+
const shouldObserveGraphQlRequestDurationAsHistogram = options => options.metricTypes.includes('graphQlRequestDurationHistogram');
|
|
147
|
+
|
|
148
|
+
const shouldObserveGraphQlErrorsTotalAsCounter = options => options.metricTypes.includes('graphQlErrorsTotal');
|
|
149
|
+
|
|
150
|
+
const defaultOptions$3 = {
|
|
151
|
+
getLabelValues: () => ({}),
|
|
152
|
+
labels: [],
|
|
153
|
+
metricPrefix: '',
|
|
154
|
+
metricTypes: ['graphQlParseDurationHistogram', 'graphQlValidationDurationHistogram', 'graphQlResolveFieldDurationHistogram', 'graphQlRequestDurationHistogram', 'graphQlErrorsTotal'],
|
|
155
|
+
metricNames: {
|
|
156
|
+
graphQlParseDuration: ['graphql_parse_duration_seconds'],
|
|
157
|
+
graphQlValidationDuration: ['graphql_validation_duration_seconds'],
|
|
158
|
+
graphQlResolveFieldDuration: ['graphql_resolve_field_duration_seconds'],
|
|
159
|
+
graphQlRequestDuration: ['graphql_request_duration_seconds'],
|
|
160
|
+
graphQlErrorsTotal: ['graphql_errors_total']
|
|
196
161
|
}
|
|
162
|
+
};
|
|
197
163
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
164
|
+
const getMetrics$1 = options => ({
|
|
165
|
+
graphQlParseDuration: shouldObserveGraphQlParseDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlParseDuration).map(nameOfGraphQlParseDuration => new Prometheus__namespace.Histogram({
|
|
166
|
+
name: `${options.metricPrefix}${nameOfGraphQlParseDuration}`,
|
|
167
|
+
help: 'The GraphQL request parse time in seconds.',
|
|
168
|
+
labelNames: defaultLabels$1.concat(options.labels).sort(),
|
|
169
|
+
buckets: options.buckets || defaultGraphQlPercentiles
|
|
170
|
+
})) : undefined,
|
|
171
|
+
graphQlValidationDuration: shouldObserveGraphQlValidationDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlValidationDuration).map(nameOfGraphQlValidationDuration => new Prometheus__namespace.Histogram({
|
|
172
|
+
name: `${options.metricPrefix}${nameOfGraphQlValidationDuration}`,
|
|
173
|
+
help: 'The GraphQL request validation time in seconds.',
|
|
174
|
+
labelNames: defaultLabels$1.concat(options.labels).sort(),
|
|
175
|
+
buckets: options.buckets || defaultGraphQlPercentiles
|
|
176
|
+
})) : undefined,
|
|
177
|
+
graphQlResolveFieldDuration: shouldObserveGraphQlResolveFieldDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlResolveFieldDuration).map(nameOfGraphQlResolveFieldDuration => new Prometheus__namespace.Histogram({
|
|
178
|
+
name: `${options.metricPrefix}${nameOfGraphQlResolveFieldDuration}`,
|
|
179
|
+
help: 'The GraphQL field resolving time in seconds.',
|
|
180
|
+
labelNames: defaultLabels$1.concat(['field_name']).concat(options.labels).sort(),
|
|
181
|
+
buckets: options.buckets || defaultGraphQlPercentiles
|
|
182
|
+
})) : undefined,
|
|
183
|
+
graphQlRequestDuration: shouldObserveGraphQlRequestDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlRequestDuration).map(nameOfGraphQlRequestDuration => new Prometheus__namespace.Histogram({
|
|
184
|
+
name: `${options.metricPrefix}${nameOfGraphQlRequestDuration}`,
|
|
185
|
+
help: 'The GraphQL request duration time in seconds.',
|
|
186
|
+
labelNames: defaultLabels$1.concat(options.labels).sort(),
|
|
187
|
+
buckets: options.buckets || defaultGraphQlPercentiles
|
|
188
|
+
})) : undefined,
|
|
189
|
+
graphQlErrorsTotal: shouldObserveGraphQlErrorsTotalAsCounter(options) ? asArray$1(options.metricNames.graphQlErrorsTotal).map(nameOfGraphQlErrorsCount => new Prometheus__namespace.Counter({
|
|
190
|
+
name: `${options.metricPrefix}${nameOfGraphQlErrorsCount}`,
|
|
191
|
+
help: 'Count of errors while parsing, validating, or executing a GraphQL operation.',
|
|
192
|
+
labelNames: defaultLabels$1.concat(['phase']).concat(options.labels).sort()
|
|
193
|
+
})) : undefined
|
|
194
|
+
});
|
|
203
195
|
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
196
|
+
const createGraphQlMetrics = options => {
|
|
197
|
+
const defaultedOptions = merge__default["default"](defaultOptions$3, options);
|
|
198
|
+
configure({
|
|
199
|
+
prefix: defaultedOptions.metricPrefix
|
|
200
|
+
});
|
|
201
|
+
const metrics = getMetrics$1(defaultedOptions);
|
|
202
|
+
return metrics;
|
|
210
203
|
};
|
|
211
204
|
|
|
212
|
-
|
|
213
|
-
|
|
205
|
+
createGraphQlMetrics.defaultOptions = defaultOptions$3;
|
|
206
|
+
|
|
207
|
+
const defaultLabels = ['gc_type'];
|
|
208
|
+
|
|
209
|
+
const asArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
214
210
|
|
|
215
|
-
|
|
211
|
+
const defaultOptions$2 = {
|
|
212
|
+
getLabelValues: () => ({}),
|
|
213
|
+
labels: [],
|
|
214
|
+
metricPrefix: '',
|
|
215
|
+
metricNames: {
|
|
216
|
+
up: ['up'],
|
|
217
|
+
countOfGcs: ['nodejs_gc_runs_total'],
|
|
218
|
+
durationOfGc: ['nodejs_gc_pause_seconds_total'],
|
|
219
|
+
reclaimedInGc: ['nodejs_gc_reclaimed_bytes_total']
|
|
220
|
+
}
|
|
216
221
|
};
|
|
217
222
|
|
|
218
|
-
const
|
|
219
|
-
|
|
223
|
+
const getMetrics = options => ({
|
|
224
|
+
up: asArray(options.metricNames.up).map(nameOfUpMetric => new Prometheus__namespace.Gauge({
|
|
225
|
+
name: `${options.metricPrefix}${nameOfUpMetric}`,
|
|
226
|
+
help: '1 = up, 0 = not up'
|
|
227
|
+
})),
|
|
228
|
+
countOfGcs: asArray(options.metricNames.countOfGcs).map(nameOfCountOfGcsMetric => new Prometheus__namespace.Counter({
|
|
229
|
+
name: `${options.metricPrefix}${nameOfCountOfGcsMetric}`,
|
|
230
|
+
help: 'Count of total garbage collections.',
|
|
231
|
+
labelNames: defaultLabels
|
|
232
|
+
})),
|
|
233
|
+
durationOfGc: asArray(options.metricNames.durationOfGc).map(nameOfDurationOfGcMetric => new Prometheus__namespace.Counter({
|
|
234
|
+
name: `${options.metricPrefix}${nameOfDurationOfGcMetric}`,
|
|
235
|
+
help: 'Time spent in GC Pause in seconds.',
|
|
236
|
+
labelNames: defaultLabels
|
|
237
|
+
})),
|
|
238
|
+
reclaimedInGc: asArray(options.metricNames.reclaimedInGc).map(nameOfReclaimedInGcMetric => new Prometheus__namespace.Counter({
|
|
239
|
+
name: `${options.metricPrefix}${nameOfReclaimedInGcMetric}`,
|
|
240
|
+
help: 'Total number of bytes reclaimed by GC.',
|
|
241
|
+
labelNames: defaultLabels
|
|
242
|
+
}))
|
|
243
|
+
});
|
|
220
244
|
|
|
221
|
-
|
|
245
|
+
const createGcMetrics = options => {
|
|
246
|
+
const defaultedOptions = merge__default["default"](defaultOptions$2, options);
|
|
247
|
+
configure({
|
|
248
|
+
prefix: defaultedOptions.metricPrefix
|
|
249
|
+
});
|
|
250
|
+
const gcMetrics = getMetrics(defaultedOptions);
|
|
251
|
+
return gcMetrics;
|
|
222
252
|
};
|
|
223
253
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
254
|
+
createGcMetrics.defaultOptions = defaultOptions$2;
|
|
255
|
+
|
|
256
|
+
const getSummary = async () => defaultRegister.metrics();
|
|
257
|
+
|
|
258
|
+
const getContentType = () => defaultRegister.contentType;
|
|
259
|
+
|
|
260
|
+
function sortLabels(unsortedLabels) {
|
|
261
|
+
return Object.keys(unsortedLabels).sort((a, b) => {
|
|
262
|
+
if (a < b) {
|
|
263
|
+
return -1;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (a > b) {
|
|
267
|
+
return 1;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return 0;
|
|
271
|
+
}).reduce((sortedLabels, labelName) => {
|
|
272
|
+
sortedLabels[labelName] = unsortedLabels[labelName];
|
|
273
|
+
return sortedLabels;
|
|
274
|
+
}, {});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const NS_PER_SEC = 1e9;
|
|
278
|
+
|
|
279
|
+
function endMeasurementFrom(start) {
|
|
280
|
+
const [seconds, nanoseconds] = process.hrtime(start);
|
|
281
|
+
return {
|
|
282
|
+
durationS: (seconds * NS_PER_SEC + nanoseconds) / NS_PER_SEC
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const defaultOptions$1 = {
|
|
227
287
|
skip: () => false,
|
|
228
288
|
detectKubernetes: false
|
|
229
289
|
};
|
|
230
290
|
|
|
231
|
-
const createRequestRecorder = (
|
|
232
|
-
const defaultedRecorderOptions = merge__default["default"](defaultOptions, options);
|
|
233
|
-
const shouldSkipMetricsByEnvironment = defaultedRecorderOptions
|
|
234
|
-
const shouldObserveInSeconds = shouldObserveMetricAccuracy('s')(defaultedRecorderOptions);
|
|
235
|
-
const shouldObserveInMilliseconds = shouldObserveMetricAccuracy('ms')(defaultedRecorderOptions);
|
|
236
|
-
const shouldObserveInSummary = shouldObserveMetricType('httpRequestsSummary')(defaultedRecorderOptions);
|
|
237
|
-
const shouldObserveInHistogram = shouldObserveMetricType('httpRequestsHistogram')(defaultedRecorderOptions);
|
|
238
|
-
const shouldObserveInCounter = shouldObserveMetricType('httpRequestsTotal')(defaultedRecorderOptions);
|
|
239
|
-
const shouldObserveContentLengthInHistogram = shouldObserveMetricType('httpContentLengthHistogram')(defaultedRecorderOptions); // eslint-disable-next-line complexity
|
|
240
|
-
|
|
291
|
+
const createRequestRecorder = (metrics, options = defaultOptions$1) => {
|
|
292
|
+
const defaultedRecorderOptions = merge__default["default"](defaultOptions$1, options);
|
|
293
|
+
const shouldSkipMetricsByEnvironment = skipMetricsInEnvironment(defaultedRecorderOptions);
|
|
241
294
|
return (start, recordingOptions) => {
|
|
242
295
|
const {
|
|
243
|
-
durationMs,
|
|
244
296
|
durationS
|
|
245
297
|
} = endMeasurementFrom(start);
|
|
246
298
|
const labels = sortLabels(recordingOptions.labels);
|
|
247
299
|
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
httpRequestDurationInMillisecondsMetricType.observe(labels, durationMs);
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (shouldObserveInMilliseconds && shouldObserveInSummary && !shouldSkipMetricsByEnvironment) {
|
|
255
|
-
metricTypes.httpRequestDurationPerPercentileInMilliseconds.forEach(httpRequestDurationPerPercentileInMillisecondsMetricType => {
|
|
256
|
-
httpRequestDurationPerPercentileInMillisecondsMetricType.observe(labels, durationMs);
|
|
257
|
-
});
|
|
258
|
-
}
|
|
300
|
+
if (!shouldSkipMetricsByEnvironment) {
|
|
301
|
+
var _metrics$httpRequestD;
|
|
259
302
|
|
|
260
|
-
|
|
261
|
-
metricTypes.httpRequestDurationInSeconds.forEach(httpRequestDurationInSecondsMetricType => {
|
|
303
|
+
(_metrics$httpRequestD = metrics.httpRequestDurationInSeconds) === null || _metrics$httpRequestD === void 0 ? void 0 : _metrics$httpRequestD.forEach(httpRequestDurationInSecondsMetricType => {
|
|
262
304
|
httpRequestDurationInSecondsMetricType.observe(labels, durationS);
|
|
263
305
|
});
|
|
264
306
|
}
|
|
265
307
|
|
|
266
|
-
if (
|
|
267
|
-
|
|
308
|
+
if (!shouldSkipMetricsByEnvironment) {
|
|
309
|
+
var _metrics$httpRequestD2;
|
|
310
|
+
|
|
311
|
+
(_metrics$httpRequestD2 = metrics.httpRequestDurationPerPercentileInSeconds) === null || _metrics$httpRequestD2 === void 0 ? void 0 : _metrics$httpRequestD2.forEach(httpRequestDurationPerPercentileInSecondsMetricType => {
|
|
268
312
|
httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS);
|
|
269
313
|
});
|
|
270
314
|
}
|
|
271
315
|
|
|
272
|
-
if (
|
|
273
|
-
|
|
316
|
+
if (!shouldSkipMetricsByEnvironment) {
|
|
317
|
+
var _metrics$httpRequests;
|
|
318
|
+
|
|
319
|
+
(_metrics$httpRequests = metrics.httpRequestsTotal) === null || _metrics$httpRequests === void 0 ? void 0 : _metrics$httpRequests.forEach(httpRequestsTotalMetricType => {
|
|
274
320
|
httpRequestsTotalMetricType.inc(labels);
|
|
275
321
|
});
|
|
276
322
|
}
|
|
277
323
|
|
|
278
|
-
if (
|
|
279
|
-
|
|
324
|
+
if (recordingOptions.requestContentLength) {
|
|
325
|
+
var _metrics$httpRequestC;
|
|
326
|
+
|
|
327
|
+
(_metrics$httpRequestC = metrics.httpRequestContentLengthInBytes) === null || _metrics$httpRequestC === void 0 ? void 0 : _metrics$httpRequestC.forEach(httpRequestContentLengthInBytesMetricType => {
|
|
280
328
|
httpRequestContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
|
|
281
329
|
recordingOptions.requestContentLength);
|
|
282
330
|
});
|
|
283
331
|
}
|
|
284
332
|
|
|
285
|
-
if (
|
|
286
|
-
|
|
333
|
+
if (recordingOptions.responseContentLength) {
|
|
334
|
+
var _metrics$httpResponse;
|
|
335
|
+
|
|
336
|
+
(_metrics$httpResponse = metrics.httpResponseContentLengthInBytes) === null || _metrics$httpResponse === void 0 ? void 0 : _metrics$httpResponse.forEach(httpResponseContentLengthInBytesMetricType => {
|
|
287
337
|
httpResponseContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
|
|
288
338
|
recordingOptions.responseContentLength);
|
|
289
339
|
});
|
|
@@ -291,7 +341,7 @@ const createRequestRecorder = (metricTypes, options = defaultOptions) => {
|
|
|
291
341
|
};
|
|
292
342
|
};
|
|
293
343
|
|
|
294
|
-
createRequestRecorder.defaultOptions = defaultOptions;
|
|
344
|
+
createRequestRecorder.defaultOptions = defaultOptions$1;
|
|
295
345
|
|
|
296
346
|
const gc = requireOptional__default["default"]('@sematext/gc-stats');
|
|
297
347
|
const gcTypes = {
|
|
@@ -303,27 +353,32 @@ const gcTypes = {
|
|
|
303
353
|
8: 'weak_phantom',
|
|
304
354
|
15: 'all'
|
|
305
355
|
};
|
|
306
|
-
const
|
|
356
|
+
const defaultOptions = {
|
|
357
|
+
disableGcMetrics: false
|
|
358
|
+
};
|
|
359
|
+
const createGcObserver = once__default["default"]((metrics, options) => () => {
|
|
307
360
|
if (typeof gc !== 'function') {
|
|
308
361
|
return;
|
|
309
362
|
}
|
|
310
363
|
|
|
364
|
+
if (options.disableGcMetrics) return;
|
|
311
365
|
gc().on('stats', stats => {
|
|
312
366
|
const gcType = gcTypes[stats.gctype];
|
|
313
|
-
|
|
367
|
+
metrics.countOfGcs.forEach(countOfGcMetricType => {
|
|
314
368
|
countOfGcMetricType.labels(gcType).inc();
|
|
315
369
|
});
|
|
316
|
-
|
|
370
|
+
metrics.durationOfGc.forEach(durationOfGcMetricType => {
|
|
317
371
|
durationOfGcMetricType.labels(gcType).inc(stats.pause / 1e9);
|
|
318
372
|
});
|
|
319
373
|
|
|
320
374
|
if (stats.diff.usedHeapSize < 0) {
|
|
321
|
-
|
|
375
|
+
metrics.reclaimedInGc.forEach(reclaimedInGcMetricType => {
|
|
322
376
|
reclaimedInGcMetricType.labels(gcType).inc(stats.diff.usedHeapSize * -1);
|
|
323
377
|
});
|
|
324
378
|
}
|
|
325
379
|
});
|
|
326
380
|
});
|
|
381
|
+
createGcObserver.defaultOptions = defaultOptions;
|
|
327
382
|
|
|
328
383
|
const normalizeStatusCode = statusCode => statusCode;
|
|
329
384
|
|
|
@@ -340,14 +395,19 @@ const defaultNormalizers = {
|
|
|
340
395
|
};
|
|
341
396
|
|
|
342
397
|
exports.Prometheus = Prometheus__namespace;
|
|
398
|
+
exports.createGcMetrics = createGcMetrics;
|
|
343
399
|
exports.createGcObserver = createGcObserver;
|
|
344
|
-
exports.
|
|
400
|
+
exports.createGraphQlMetrics = createGraphQlMetrics;
|
|
401
|
+
exports.createHttpMetrics = createHttpMetrics;
|
|
345
402
|
exports.createRequestRecorder = createRequestRecorder;
|
|
346
403
|
exports.defaultNormalizers = defaultNormalizers;
|
|
347
404
|
exports.defaultRegister = defaultRegister;
|
|
405
|
+
exports.endMeasurementFrom = endMeasurementFrom;
|
|
348
406
|
exports.getContentType = getContentType;
|
|
349
407
|
exports.getSummary = getSummary;
|
|
350
408
|
exports.isRunningInKubernetes = isRunningInKubernetes;
|
|
351
409
|
exports.normalizeMethod = normalizeMethod;
|
|
352
410
|
exports.normalizePath = normalizePath;
|
|
353
411
|
exports.normalizeStatusCode = normalizeStatusCode;
|
|
412
|
+
exports.skipMetricsInEnvironment = skipMetricsInEnvironment;
|
|
413
|
+
exports.sortLabels = sortLabels;
|
|
@@ -38,31 +38,26 @@ var UrlValueParser__default = /*#__PURE__*/_interopDefault(UrlValueParser);
|
|
|
38
38
|
|
|
39
39
|
const isRunningInKubernetes = () => Boolean(process.env.KUBERNETES_SERVICE_HOST);
|
|
40
40
|
|
|
41
|
+
const skipMetricsInEnvironment = options => options.detectKubernetes === true && !isRunningInKubernetes();
|
|
42
|
+
|
|
41
43
|
// This is the `globalRegistry` provided by the `prom-client`
|
|
42
44
|
// We could create multiple registries with `new Prometheus.registry()`.
|
|
43
45
|
|
|
44
46
|
const defaultRegister = Prometheus__namespace.register;
|
|
45
47
|
const configure = once__default["default"](options => {
|
|
46
|
-
const
|
|
48
|
+
const shouldSkipMetricsInEnvironment = skipMetricsInEnvironment(options);
|
|
47
49
|
|
|
48
|
-
if (!
|
|
50
|
+
if (!shouldSkipMetricsInEnvironment) {
|
|
49
51
|
Prometheus__namespace.collectDefaultMetrics(options);
|
|
50
52
|
}
|
|
51
53
|
});
|
|
52
54
|
|
|
53
|
-
const defaultHttpRequestDurationPercentilesInMillieconds = [0.5, 0.9, 0.95, 0.98, 0.99];
|
|
54
|
-
const defaultHttpRequestDurationInMilliseconds = [50, 100, 300, 500, 800, 1000, 1500, 2000, 3000, 5000, 10000];
|
|
55
55
|
const defaultHttpRequestDurationPercentileInSeconds = [0.5, 0.9, 0.95, 0.98, 0.99];
|
|
56
56
|
const defaultHttpRequestDurationInSeconds = [0.05, 0.1, 0.3, 0.5, 0.8, 1, 1.5, 2, 3, 10];
|
|
57
57
|
const defaultHttpContentLengthInBytes = [100000, 200000, 500000, 1000000, 1500000, 2000000, 3000000, 5000000, 10000000];
|
|
58
|
-
const
|
|
59
|
-
const defaultGcLabels = ['gc_type'];
|
|
60
|
-
|
|
61
|
-
const asArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
62
|
-
|
|
63
|
-
const shouldObserveMetricsInSeconds = options => options.accuracies.includes('s');
|
|
58
|
+
const defaultLabels$2 = ['path', 'status_code', 'method'];
|
|
64
59
|
|
|
65
|
-
const
|
|
60
|
+
const asArray$2 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
66
61
|
|
|
67
62
|
const shouldObserveHttpRequestsAsSummary = options => options.metricTypes.includes('httpRequestsSummary');
|
|
68
63
|
|
|
@@ -72,218 +67,273 @@ const shouldObserveHttpRequestsAsCounter = options => options.metricTypes.includ
|
|
|
72
67
|
|
|
73
68
|
const shouldObserveHttpContentLengthAsHistogram = options => options.metricTypes.includes('httpContentLengthHistogram');
|
|
74
69
|
|
|
75
|
-
const defaultOptions$
|
|
70
|
+
const defaultOptions$4 = {
|
|
76
71
|
getLabelValues: () => ({}),
|
|
77
72
|
labels: [],
|
|
78
|
-
accuracies: ['s'],
|
|
79
73
|
metricPrefix: '',
|
|
80
74
|
metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],
|
|
81
75
|
metricNames: {
|
|
82
|
-
up: ['up'],
|
|
83
|
-
countOfGcs: ['nodejs_gc_runs_total'],
|
|
84
|
-
durationOfGc: ['nodejs_gc_pause_seconds_total'],
|
|
85
|
-
reclaimedInGc: ['nodejs_gc_reclaimed_bytes_total'],
|
|
86
76
|
httpRequestsTotal: ['http_requests_total'],
|
|
87
|
-
httpRequestDurationPerPercentileInMilliseconds: ['http_request_duration_per_percentile_milliseconds'],
|
|
88
77
|
httpRequestDurationPerPercentileInSeconds: ['http_request_duration_per_percentile_seconds'],
|
|
89
78
|
httpRequestDurationInSeconds: ['http_request_duration_seconds'],
|
|
90
|
-
httpRequestDurationInMilliseconds: ['http_request_duration_milliseconds'],
|
|
91
79
|
httpRequestContentLengthInBytes: ['http_request_content_length_bytes'],
|
|
92
80
|
httpResponseContentLengthInBytes: ['http_response_content_length_bytes']
|
|
93
81
|
}
|
|
94
82
|
};
|
|
95
83
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
name: `${options.metricPrefix}${nameOfUpMetric}`,
|
|
99
|
-
help: '1 = up, 0 = not up'
|
|
100
|
-
})),
|
|
101
|
-
countOfGcs: asArray(options.metricNames.countOfGcs).map(nameOfCountOfGcsMetric => new Prometheus__namespace.Counter({
|
|
102
|
-
name: `${options.metricPrefix}${nameOfCountOfGcsMetric}`,
|
|
103
|
-
help: 'Count of total garbage collections.',
|
|
104
|
-
labelNames: defaultGcLabels
|
|
105
|
-
})),
|
|
106
|
-
durationOfGc: asArray(options.metricNames.durationOfGc).map(nameOfDurationOfGcMetric => new Prometheus__namespace.Counter({
|
|
107
|
-
name: `${options.metricPrefix}${nameOfDurationOfGcMetric}`,
|
|
108
|
-
help: 'Time spent in GC Pause in seconds.',
|
|
109
|
-
labelNames: defaultGcLabels
|
|
110
|
-
})),
|
|
111
|
-
reclaimedInGc: asArray(options.metricNames.reclaimedInGc).map(nameOfReclaimedInGcMetric => new Prometheus__namespace.Counter({
|
|
112
|
-
name: `${options.metricPrefix}${nameOfReclaimedInGcMetric}`,
|
|
113
|
-
help: 'Total number of bytes reclaimed by GC.',
|
|
114
|
-
labelNames: defaultGcLabels
|
|
115
|
-
})),
|
|
116
|
-
httpRequestContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) && asArray(options.metricNames.httpRequestContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
|
|
84
|
+
const getMetrics$2 = options => ({
|
|
85
|
+
httpRequestContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray$2(options.metricNames.httpRequestContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
|
|
117
86
|
name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
|
|
118
87
|
help: 'The HTTP request content length in bytes.',
|
|
119
|
-
labelNames:
|
|
88
|
+
labelNames: defaultLabels$2.concat(options.labels).sort(),
|
|
120
89
|
buckets: options.buckets || defaultHttpContentLengthInBytes
|
|
121
|
-
})),
|
|
122
|
-
httpResponseContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options)
|
|
90
|
+
})) : undefined,
|
|
91
|
+
httpResponseContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray$2(options.metricNames.httpResponseContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
|
|
123
92
|
name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
|
|
124
93
|
help: 'The HTTP response content length in bytes.',
|
|
125
|
-
labelNames:
|
|
94
|
+
labelNames: defaultLabels$2.concat(options.labels).sort(),
|
|
126
95
|
buckets: options.buckets || defaultHttpContentLengthInBytes
|
|
127
|
-
}))
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
const getHttpRequestLatencyMetricsInMilliseconds = options => ({
|
|
131
|
-
httpRequestDurationPerPercentileInMilliseconds: shouldObserveHttpRequestsAsSummary(options) && asArray(options.metricNames.httpRequestDurationPerPercentileInMilliseconds).map(nameOfHttpRequestDurationPerPercentileInMillisecondsMetric => new Prometheus__namespace.Summary({
|
|
132
|
-
name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInMillisecondsMetric}`,
|
|
133
|
-
help: 'The HTTP request latencies in milliseconds.',
|
|
134
|
-
labelNames: defaultRequestLabels.concat(options.labels).sort(),
|
|
135
|
-
percentiles: options.percentiles || defaultHttpRequestDurationPercentilesInMillieconds
|
|
136
|
-
})),
|
|
137
|
-
httpRequestDurationInMilliseconds: shouldObserveHttpRequestsAsHistogram(options) && asArray(options.metricNames.httpRequestDurationInMilliseconds).map(nameOfHttpRequestDurationInMillisecondsMetric => new Prometheus__namespace.Histogram({
|
|
138
|
-
name: `${options.metricPrefix}${nameOfHttpRequestDurationInMillisecondsMetric}`,
|
|
139
|
-
help: 'The HTTP request latencies in milliseconds.',
|
|
140
|
-
labelNames: defaultRequestLabels.concat(options.labels).sort(),
|
|
141
|
-
buckets: options.buckets || defaultHttpRequestDurationInMilliseconds
|
|
142
|
-
}))
|
|
96
|
+
})) : undefined
|
|
143
97
|
});
|
|
144
98
|
|
|
145
99
|
const getHttpRequestLatencyMetricsInSeconds = options => ({
|
|
146
|
-
httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options)
|
|
100
|
+
httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) ? asArray$2(options.metricNames.httpRequestDurationPerPercentileInSeconds).map(nameOfHttpRequestDurationPerPercentileInSeconds => new Prometheus__namespace.Summary({
|
|
147
101
|
name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInSeconds}`,
|
|
148
102
|
help: 'The HTTP request latencies in seconds.',
|
|
149
|
-
labelNames:
|
|
103
|
+
labelNames: defaultLabels$2.concat(options.labels).sort(),
|
|
150
104
|
percentiles: options.percentiles || defaultHttpRequestDurationPercentileInSeconds
|
|
151
|
-
})),
|
|
152
|
-
httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options)
|
|
105
|
+
})) : undefined,
|
|
106
|
+
httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options) ? asArray$2(options.metricNames.httpRequestDurationInSeconds).map(nameOfHttpRequestDurationInSecondsMetric => new Prometheus__namespace.Histogram({
|
|
153
107
|
name: `${options.metricPrefix}${nameOfHttpRequestDurationInSecondsMetric}`,
|
|
154
108
|
help: 'The HTTP request latencies in seconds.',
|
|
155
|
-
labelNames:
|
|
109
|
+
labelNames: defaultLabels$2.concat(options.labels).sort(),
|
|
156
110
|
buckets: options.buckets || defaultHttpRequestDurationInSeconds
|
|
157
|
-
}))
|
|
111
|
+
})) : undefined
|
|
158
112
|
});
|
|
159
113
|
|
|
160
114
|
const getHttpRequestCounterMetric = options => ({
|
|
161
|
-
httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options)
|
|
115
|
+
httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) ? asArray$2(options.metricNames.httpRequestsTotal).map(nameOfHttpRequestsTotalMetric => new Prometheus__namespace.Counter({
|
|
162
116
|
name: `${options.metricPrefix}${nameOfHttpRequestsTotalMetric}`,
|
|
163
117
|
help: 'The total HTTP requests.',
|
|
164
|
-
labelNames:
|
|
165
|
-
}))
|
|
118
|
+
labelNames: defaultLabels$2.concat(options.labels).sort()
|
|
119
|
+
})) : undefined
|
|
166
120
|
});
|
|
167
121
|
|
|
168
|
-
const
|
|
169
|
-
const defaultedOptions = merge__default["default"](defaultOptions$
|
|
122
|
+
const createHttpMetrics = options => {
|
|
123
|
+
const defaultedOptions = merge__default["default"](defaultOptions$4, options);
|
|
170
124
|
configure({
|
|
171
125
|
prefix: defaultedOptions.metricPrefix
|
|
172
126
|
});
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
const httpRequestLatencyMetricsInSeconds = shouldObserveMetricsInSeconds(defaultedOptions) && getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
|
|
127
|
+
const metrics = getMetrics$2(defaultedOptions);
|
|
128
|
+
const httpRequestLatencyMetricsInSeconds = getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
|
|
176
129
|
const httpRequestCounterMetric = getHttpRequestCounterMetric(defaultedOptions);
|
|
177
|
-
return Object.assign({},
|
|
130
|
+
return Object.assign({}, metrics, httpRequestLatencyMetricsInSeconds, httpRequestCounterMetric);
|
|
178
131
|
};
|
|
179
132
|
|
|
180
|
-
|
|
133
|
+
createHttpMetrics.defaultOptions = defaultOptions$4;
|
|
181
134
|
|
|
182
|
-
const
|
|
135
|
+
const defaultGraphQlPercentiles = [0.5, 0.9, 0.95, 0.98, 0.99];
|
|
136
|
+
const defaultLabels$1 = ['operation_name'];
|
|
183
137
|
|
|
184
|
-
const
|
|
138
|
+
const asArray$1 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
185
139
|
|
|
186
|
-
const
|
|
187
|
-
const NS_PER_MS = 1e6;
|
|
140
|
+
const shouldObserveGraphQlParseDurationAsHistogram = options => options.metricTypes.includes('graphQlParseDurationHistogram');
|
|
188
141
|
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
142
|
+
const shouldObserveGraphQlValidationDurationAsHistogram = options => options.metricTypes.includes('graphQlValidationDurationHistogram');
|
|
143
|
+
|
|
144
|
+
const shouldObserveGraphQlResolveFieldDurationAsHistogram = options => options.metricTypes.includes('graphQlResolveFieldDurationHistogram');
|
|
193
145
|
|
|
194
|
-
|
|
195
|
-
|
|
146
|
+
const shouldObserveGraphQlRequestDurationAsHistogram = options => options.metricTypes.includes('graphQlRequestDurationHistogram');
|
|
147
|
+
|
|
148
|
+
const shouldObserveGraphQlErrorsTotalAsCounter = options => options.metricTypes.includes('graphQlErrorsTotal');
|
|
149
|
+
|
|
150
|
+
const defaultOptions$3 = {
|
|
151
|
+
getLabelValues: () => ({}),
|
|
152
|
+
labels: [],
|
|
153
|
+
metricPrefix: '',
|
|
154
|
+
metricTypes: ['graphQlParseDurationHistogram', 'graphQlValidationDurationHistogram', 'graphQlResolveFieldDurationHistogram', 'graphQlRequestDurationHistogram', 'graphQlErrorsTotal'],
|
|
155
|
+
metricNames: {
|
|
156
|
+
graphQlParseDuration: ['graphql_parse_duration_seconds'],
|
|
157
|
+
graphQlValidationDuration: ['graphql_validation_duration_seconds'],
|
|
158
|
+
graphQlResolveFieldDuration: ['graphql_resolve_field_duration_seconds'],
|
|
159
|
+
graphQlRequestDuration: ['graphql_request_duration_seconds'],
|
|
160
|
+
graphQlErrorsTotal: ['graphql_errors_total']
|
|
196
161
|
}
|
|
162
|
+
};
|
|
197
163
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
164
|
+
const getMetrics$1 = options => ({
|
|
165
|
+
graphQlParseDuration: shouldObserveGraphQlParseDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlParseDuration).map(nameOfGraphQlParseDuration => new Prometheus__namespace.Histogram({
|
|
166
|
+
name: `${options.metricPrefix}${nameOfGraphQlParseDuration}`,
|
|
167
|
+
help: 'The GraphQL request parse time in seconds.',
|
|
168
|
+
labelNames: defaultLabels$1.concat(options.labels).sort(),
|
|
169
|
+
buckets: options.buckets || defaultGraphQlPercentiles
|
|
170
|
+
})) : undefined,
|
|
171
|
+
graphQlValidationDuration: shouldObserveGraphQlValidationDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlValidationDuration).map(nameOfGraphQlValidationDuration => new Prometheus__namespace.Histogram({
|
|
172
|
+
name: `${options.metricPrefix}${nameOfGraphQlValidationDuration}`,
|
|
173
|
+
help: 'The GraphQL request validation time in seconds.',
|
|
174
|
+
labelNames: defaultLabels$1.concat(options.labels).sort(),
|
|
175
|
+
buckets: options.buckets || defaultGraphQlPercentiles
|
|
176
|
+
})) : undefined,
|
|
177
|
+
graphQlResolveFieldDuration: shouldObserveGraphQlResolveFieldDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlResolveFieldDuration).map(nameOfGraphQlResolveFieldDuration => new Prometheus__namespace.Histogram({
|
|
178
|
+
name: `${options.metricPrefix}${nameOfGraphQlResolveFieldDuration}`,
|
|
179
|
+
help: 'The GraphQL field resolving time in seconds.',
|
|
180
|
+
labelNames: defaultLabels$1.concat(['field_name']).concat(options.labels).sort(),
|
|
181
|
+
buckets: options.buckets || defaultGraphQlPercentiles
|
|
182
|
+
})) : undefined,
|
|
183
|
+
graphQlRequestDuration: shouldObserveGraphQlRequestDurationAsHistogram(options) ? asArray$1(options.metricNames.graphQlRequestDuration).map(nameOfGraphQlRequestDuration => new Prometheus__namespace.Histogram({
|
|
184
|
+
name: `${options.metricPrefix}${nameOfGraphQlRequestDuration}`,
|
|
185
|
+
help: 'The GraphQL request duration time in seconds.',
|
|
186
|
+
labelNames: defaultLabels$1.concat(options.labels).sort(),
|
|
187
|
+
buckets: options.buckets || defaultGraphQlPercentiles
|
|
188
|
+
})) : undefined,
|
|
189
|
+
graphQlErrorsTotal: shouldObserveGraphQlErrorsTotalAsCounter(options) ? asArray$1(options.metricNames.graphQlErrorsTotal).map(nameOfGraphQlErrorsCount => new Prometheus__namespace.Counter({
|
|
190
|
+
name: `${options.metricPrefix}${nameOfGraphQlErrorsCount}`,
|
|
191
|
+
help: 'Count of errors while parsing, validating, or executing a GraphQL operation.',
|
|
192
|
+
labelNames: defaultLabels$1.concat(['phase']).concat(options.labels).sort()
|
|
193
|
+
})) : undefined
|
|
194
|
+
});
|
|
203
195
|
|
|
204
|
-
const
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
196
|
+
const createGraphQlMetrics = options => {
|
|
197
|
+
const defaultedOptions = merge__default["default"](defaultOptions$3, options);
|
|
198
|
+
configure({
|
|
199
|
+
prefix: defaultedOptions.metricPrefix
|
|
200
|
+
});
|
|
201
|
+
const metrics = getMetrics$1(defaultedOptions);
|
|
202
|
+
return metrics;
|
|
210
203
|
};
|
|
211
204
|
|
|
212
|
-
|
|
213
|
-
|
|
205
|
+
createGraphQlMetrics.defaultOptions = defaultOptions$3;
|
|
206
|
+
|
|
207
|
+
const defaultLabels = ['gc_type'];
|
|
208
|
+
|
|
209
|
+
const asArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
214
210
|
|
|
215
|
-
|
|
211
|
+
const defaultOptions$2 = {
|
|
212
|
+
getLabelValues: () => ({}),
|
|
213
|
+
labels: [],
|
|
214
|
+
metricPrefix: '',
|
|
215
|
+
metricNames: {
|
|
216
|
+
up: ['up'],
|
|
217
|
+
countOfGcs: ['nodejs_gc_runs_total'],
|
|
218
|
+
durationOfGc: ['nodejs_gc_pause_seconds_total'],
|
|
219
|
+
reclaimedInGc: ['nodejs_gc_reclaimed_bytes_total']
|
|
220
|
+
}
|
|
216
221
|
};
|
|
217
222
|
|
|
218
|
-
const
|
|
219
|
-
|
|
223
|
+
const getMetrics = options => ({
|
|
224
|
+
up: asArray(options.metricNames.up).map(nameOfUpMetric => new Prometheus__namespace.Gauge({
|
|
225
|
+
name: `${options.metricPrefix}${nameOfUpMetric}`,
|
|
226
|
+
help: '1 = up, 0 = not up'
|
|
227
|
+
})),
|
|
228
|
+
countOfGcs: asArray(options.metricNames.countOfGcs).map(nameOfCountOfGcsMetric => new Prometheus__namespace.Counter({
|
|
229
|
+
name: `${options.metricPrefix}${nameOfCountOfGcsMetric}`,
|
|
230
|
+
help: 'Count of total garbage collections.',
|
|
231
|
+
labelNames: defaultLabels
|
|
232
|
+
})),
|
|
233
|
+
durationOfGc: asArray(options.metricNames.durationOfGc).map(nameOfDurationOfGcMetric => new Prometheus__namespace.Counter({
|
|
234
|
+
name: `${options.metricPrefix}${nameOfDurationOfGcMetric}`,
|
|
235
|
+
help: 'Time spent in GC Pause in seconds.',
|
|
236
|
+
labelNames: defaultLabels
|
|
237
|
+
})),
|
|
238
|
+
reclaimedInGc: asArray(options.metricNames.reclaimedInGc).map(nameOfReclaimedInGcMetric => new Prometheus__namespace.Counter({
|
|
239
|
+
name: `${options.metricPrefix}${nameOfReclaimedInGcMetric}`,
|
|
240
|
+
help: 'Total number of bytes reclaimed by GC.',
|
|
241
|
+
labelNames: defaultLabels
|
|
242
|
+
}))
|
|
243
|
+
});
|
|
220
244
|
|
|
221
|
-
|
|
245
|
+
const createGcMetrics = options => {
|
|
246
|
+
const defaultedOptions = merge__default["default"](defaultOptions$2, options);
|
|
247
|
+
configure({
|
|
248
|
+
prefix: defaultedOptions.metricPrefix
|
|
249
|
+
});
|
|
250
|
+
const gcMetrics = getMetrics(defaultedOptions);
|
|
251
|
+
return gcMetrics;
|
|
222
252
|
};
|
|
223
253
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
254
|
+
createGcMetrics.defaultOptions = defaultOptions$2;
|
|
255
|
+
|
|
256
|
+
const getSummary = async () => defaultRegister.metrics();
|
|
257
|
+
|
|
258
|
+
const getContentType = () => defaultRegister.contentType;
|
|
259
|
+
|
|
260
|
+
function sortLabels(unsortedLabels) {
|
|
261
|
+
return Object.keys(unsortedLabels).sort((a, b) => {
|
|
262
|
+
if (a < b) {
|
|
263
|
+
return -1;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (a > b) {
|
|
267
|
+
return 1;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return 0;
|
|
271
|
+
}).reduce((sortedLabels, labelName) => {
|
|
272
|
+
sortedLabels[labelName] = unsortedLabels[labelName];
|
|
273
|
+
return sortedLabels;
|
|
274
|
+
}, {});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const NS_PER_SEC = 1e9;
|
|
278
|
+
|
|
279
|
+
function endMeasurementFrom(start) {
|
|
280
|
+
const [seconds, nanoseconds] = process.hrtime(start);
|
|
281
|
+
return {
|
|
282
|
+
durationS: (seconds * NS_PER_SEC + nanoseconds) / NS_PER_SEC
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const defaultOptions$1 = {
|
|
227
287
|
skip: () => false,
|
|
228
288
|
detectKubernetes: false
|
|
229
289
|
};
|
|
230
290
|
|
|
231
|
-
const createRequestRecorder = (
|
|
232
|
-
const defaultedRecorderOptions = merge__default["default"](defaultOptions, options);
|
|
233
|
-
const shouldSkipMetricsByEnvironment = defaultedRecorderOptions
|
|
234
|
-
const shouldObserveInSeconds = shouldObserveMetricAccuracy('s')(defaultedRecorderOptions);
|
|
235
|
-
const shouldObserveInMilliseconds = shouldObserveMetricAccuracy('ms')(defaultedRecorderOptions);
|
|
236
|
-
const shouldObserveInSummary = shouldObserveMetricType('httpRequestsSummary')(defaultedRecorderOptions);
|
|
237
|
-
const shouldObserveInHistogram = shouldObserveMetricType('httpRequestsHistogram')(defaultedRecorderOptions);
|
|
238
|
-
const shouldObserveInCounter = shouldObserveMetricType('httpRequestsTotal')(defaultedRecorderOptions);
|
|
239
|
-
const shouldObserveContentLengthInHistogram = shouldObserveMetricType('httpContentLengthHistogram')(defaultedRecorderOptions); // eslint-disable-next-line complexity
|
|
240
|
-
|
|
291
|
+
const createRequestRecorder = (metrics, options = defaultOptions$1) => {
|
|
292
|
+
const defaultedRecorderOptions = merge__default["default"](defaultOptions$1, options);
|
|
293
|
+
const shouldSkipMetricsByEnvironment = skipMetricsInEnvironment(defaultedRecorderOptions);
|
|
241
294
|
return (start, recordingOptions) => {
|
|
242
295
|
const {
|
|
243
|
-
durationMs,
|
|
244
296
|
durationS
|
|
245
297
|
} = endMeasurementFrom(start);
|
|
246
298
|
const labels = sortLabels(recordingOptions.labels);
|
|
247
299
|
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
httpRequestDurationInMillisecondsMetricType.observe(labels, durationMs);
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (shouldObserveInMilliseconds && shouldObserveInSummary && !shouldSkipMetricsByEnvironment) {
|
|
255
|
-
metricTypes.httpRequestDurationPerPercentileInMilliseconds.forEach(httpRequestDurationPerPercentileInMillisecondsMetricType => {
|
|
256
|
-
httpRequestDurationPerPercentileInMillisecondsMetricType.observe(labels, durationMs);
|
|
257
|
-
});
|
|
258
|
-
}
|
|
300
|
+
if (!shouldSkipMetricsByEnvironment) {
|
|
301
|
+
var _metrics$httpRequestD;
|
|
259
302
|
|
|
260
|
-
|
|
261
|
-
metricTypes.httpRequestDurationInSeconds.forEach(httpRequestDurationInSecondsMetricType => {
|
|
303
|
+
(_metrics$httpRequestD = metrics.httpRequestDurationInSeconds) === null || _metrics$httpRequestD === void 0 ? void 0 : _metrics$httpRequestD.forEach(httpRequestDurationInSecondsMetricType => {
|
|
262
304
|
httpRequestDurationInSecondsMetricType.observe(labels, durationS);
|
|
263
305
|
});
|
|
264
306
|
}
|
|
265
307
|
|
|
266
|
-
if (
|
|
267
|
-
|
|
308
|
+
if (!shouldSkipMetricsByEnvironment) {
|
|
309
|
+
var _metrics$httpRequestD2;
|
|
310
|
+
|
|
311
|
+
(_metrics$httpRequestD2 = metrics.httpRequestDurationPerPercentileInSeconds) === null || _metrics$httpRequestD2 === void 0 ? void 0 : _metrics$httpRequestD2.forEach(httpRequestDurationPerPercentileInSecondsMetricType => {
|
|
268
312
|
httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS);
|
|
269
313
|
});
|
|
270
314
|
}
|
|
271
315
|
|
|
272
|
-
if (
|
|
273
|
-
|
|
316
|
+
if (!shouldSkipMetricsByEnvironment) {
|
|
317
|
+
var _metrics$httpRequests;
|
|
318
|
+
|
|
319
|
+
(_metrics$httpRequests = metrics.httpRequestsTotal) === null || _metrics$httpRequests === void 0 ? void 0 : _metrics$httpRequests.forEach(httpRequestsTotalMetricType => {
|
|
274
320
|
httpRequestsTotalMetricType.inc(labels);
|
|
275
321
|
});
|
|
276
322
|
}
|
|
277
323
|
|
|
278
|
-
if (
|
|
279
|
-
|
|
324
|
+
if (recordingOptions.requestContentLength) {
|
|
325
|
+
var _metrics$httpRequestC;
|
|
326
|
+
|
|
327
|
+
(_metrics$httpRequestC = metrics.httpRequestContentLengthInBytes) === null || _metrics$httpRequestC === void 0 ? void 0 : _metrics$httpRequestC.forEach(httpRequestContentLengthInBytesMetricType => {
|
|
280
328
|
httpRequestContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
|
|
281
329
|
recordingOptions.requestContentLength);
|
|
282
330
|
});
|
|
283
331
|
}
|
|
284
332
|
|
|
285
|
-
if (
|
|
286
|
-
|
|
333
|
+
if (recordingOptions.responseContentLength) {
|
|
334
|
+
var _metrics$httpResponse;
|
|
335
|
+
|
|
336
|
+
(_metrics$httpResponse = metrics.httpResponseContentLengthInBytes) === null || _metrics$httpResponse === void 0 ? void 0 : _metrics$httpResponse.forEach(httpResponseContentLengthInBytesMetricType => {
|
|
287
337
|
httpResponseContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
|
|
288
338
|
recordingOptions.responseContentLength);
|
|
289
339
|
});
|
|
@@ -291,7 +341,7 @@ const createRequestRecorder = (metricTypes, options = defaultOptions) => {
|
|
|
291
341
|
};
|
|
292
342
|
};
|
|
293
343
|
|
|
294
|
-
createRequestRecorder.defaultOptions = defaultOptions;
|
|
344
|
+
createRequestRecorder.defaultOptions = defaultOptions$1;
|
|
295
345
|
|
|
296
346
|
const gc = requireOptional__default["default"]('@sematext/gc-stats');
|
|
297
347
|
const gcTypes = {
|
|
@@ -303,27 +353,32 @@ const gcTypes = {
|
|
|
303
353
|
8: 'weak_phantom',
|
|
304
354
|
15: 'all'
|
|
305
355
|
};
|
|
306
|
-
const
|
|
356
|
+
const defaultOptions = {
|
|
357
|
+
disableGcMetrics: false
|
|
358
|
+
};
|
|
359
|
+
const createGcObserver = once__default["default"]((metrics, options) => () => {
|
|
307
360
|
if (typeof gc !== 'function') {
|
|
308
361
|
return;
|
|
309
362
|
}
|
|
310
363
|
|
|
364
|
+
if (options.disableGcMetrics) return;
|
|
311
365
|
gc().on('stats', stats => {
|
|
312
366
|
const gcType = gcTypes[stats.gctype];
|
|
313
|
-
|
|
367
|
+
metrics.countOfGcs.forEach(countOfGcMetricType => {
|
|
314
368
|
countOfGcMetricType.labels(gcType).inc();
|
|
315
369
|
});
|
|
316
|
-
|
|
370
|
+
metrics.durationOfGc.forEach(durationOfGcMetricType => {
|
|
317
371
|
durationOfGcMetricType.labels(gcType).inc(stats.pause / 1e9);
|
|
318
372
|
});
|
|
319
373
|
|
|
320
374
|
if (stats.diff.usedHeapSize < 0) {
|
|
321
|
-
|
|
375
|
+
metrics.reclaimedInGc.forEach(reclaimedInGcMetricType => {
|
|
322
376
|
reclaimedInGcMetricType.labels(gcType).inc(stats.diff.usedHeapSize * -1);
|
|
323
377
|
});
|
|
324
378
|
}
|
|
325
379
|
});
|
|
326
380
|
});
|
|
381
|
+
createGcObserver.defaultOptions = defaultOptions;
|
|
327
382
|
|
|
328
383
|
const normalizeStatusCode = statusCode => statusCode;
|
|
329
384
|
|
|
@@ -340,14 +395,19 @@ const defaultNormalizers = {
|
|
|
340
395
|
};
|
|
341
396
|
|
|
342
397
|
exports.Prometheus = Prometheus__namespace;
|
|
398
|
+
exports.createGcMetrics = createGcMetrics;
|
|
343
399
|
exports.createGcObserver = createGcObserver;
|
|
344
|
-
exports.
|
|
400
|
+
exports.createGraphQlMetrics = createGraphQlMetrics;
|
|
401
|
+
exports.createHttpMetrics = createHttpMetrics;
|
|
345
402
|
exports.createRequestRecorder = createRequestRecorder;
|
|
346
403
|
exports.defaultNormalizers = defaultNormalizers;
|
|
347
404
|
exports.defaultRegister = defaultRegister;
|
|
405
|
+
exports.endMeasurementFrom = endMeasurementFrom;
|
|
348
406
|
exports.getContentType = getContentType;
|
|
349
407
|
exports.getSummary = getSummary;
|
|
350
408
|
exports.isRunningInKubernetes = isRunningInKubernetes;
|
|
351
409
|
exports.normalizeMethod = normalizeMethod;
|
|
352
410
|
exports.normalizePath = normalizePath;
|
|
353
411
|
exports.normalizeStatusCode = normalizeStatusCode;
|
|
412
|
+
exports.skipMetricsInEnvironment = skipMetricsInEnvironment;
|
|
413
|
+
exports.sortLabels = sortLabels;
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@promster/metrics",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Metrics utilities used by all other server integrations",
|
|
5
5
|
"main": "dist/promster-metrics.cjs.js",
|
|
6
6
|
"typings": "dist/promster-metrics.cjs.d.ts",
|
|
7
7
|
"types": "dist/promster-metrics.cjs.d.ts",
|
|
8
|
-
"scripts": {},
|
|
9
8
|
"files": [
|
|
10
9
|
"readme.md",
|
|
11
10
|
"package.json",
|
|
@@ -22,7 +21,8 @@
|
|
|
22
21
|
},
|
|
23
22
|
"repository": {
|
|
24
23
|
"type": "git",
|
|
25
|
-
"url": "
|
|
24
|
+
"url": "https://github.com/tdeekens/flopflip.git",
|
|
25
|
+
"directory": "packages/metrics"
|
|
26
26
|
},
|
|
27
27
|
"author": "Tobias Deekens <nerd@tdeekens.name>",
|
|
28
28
|
"license": "MIT",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"url-value-parser": "2.0.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@promster/types": "^3.
|
|
49
|
+
"@promster/types": "^3.2.0",
|
|
50
50
|
"@types/lodash": "4.14.176",
|
|
51
|
-
"prom-client": "14.0.
|
|
51
|
+
"prom-client": "14.0.1",
|
|
52
52
|
"typescript": "4.4.4"
|
|
53
53
|
},
|
|
54
54
|
"optionalDependencies": {
|
package/readme.md
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<b style="font-size: 25px">⏰ Promster - Measure metrics from Hapi/Express servers with Prometheus 🚦</b
|
|
3
|
-
<i>Promster is an Prometheus Exporter for Node.js servers written with Express or Hapi.</i>
|
|
2
|
+
<b style="font-size: 25px">⏰ Promster - Measure metrics from Hapi/Express servers with Prometheus 🚦</b>
|
|
4
3
|
</p>
|
|
5
4
|
|
|
6
5
|
### `@promster/metrics`
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { TDefaultedPromsterOptions, TMetricTypes } from '@promster/types';
|
|
2
|
-
declare const createMetricTypes: {
|
|
3
|
-
(options: TDefaultedPromsterOptions): TMetricTypes;
|
|
4
|
-
defaultOptions: {
|
|
5
|
-
getLabelValues: () => {};
|
|
6
|
-
labels: never[];
|
|
7
|
-
accuracies: string[];
|
|
8
|
-
metricPrefix: string;
|
|
9
|
-
metricTypes: string[];
|
|
10
|
-
metricNames: {
|
|
11
|
-
up: string[];
|
|
12
|
-
countOfGcs: string[];
|
|
13
|
-
durationOfGc: string[];
|
|
14
|
-
reclaimedInGc: string[];
|
|
15
|
-
httpRequestsTotal: string[];
|
|
16
|
-
httpRequestDurationPerPercentileInMilliseconds: string[];
|
|
17
|
-
httpRequestDurationPerPercentileInSeconds: string[];
|
|
18
|
-
httpRequestDurationInSeconds: string[];
|
|
19
|
-
httpRequestDurationInMilliseconds: string[];
|
|
20
|
-
httpRequestContentLengthInBytes: string[];
|
|
21
|
-
httpResponseContentLengthInBytes: string[];
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export { createMetricTypes };
|