@promster/metrics 7.0.2 → 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.
@@ -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,2 @@
1
+ import { createGcMetrics } from './create-gc-metrics';
2
+ 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,2 @@
1
+ import { createGraphQlMetrics } from './create-graphql-metrics';
2
+ 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 };
@@ -0,0 +1,2 @@
1
+ import { createHttpMetrics } from './create-http-metrics';
2
+ export { createHttpMetrics };
@@ -1,18 +1,14 @@
1
- import type { TPromsterOptions, TLabelValues, TMetricTypes } from '@promster/types';
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
- (metricTypes: TMetricTypes, options?: TPromsterOptions): TRequestRecorder;
11
+ (metrics: THttpMetrics, options?: TPromsterOptions): TRequestRecorder;
16
12
  defaultOptions: TPromsterOptions;
17
13
  };
18
14
  export { createRequestRecorder, sortLabels, endMeasurementFrom };
@@ -0,0 +1,5 @@
1
+ import type { TRequestTiming } from '@promster/types';
2
+ declare function endMeasurementFrom(start: TRequestTiming): {
3
+ durationS: number;
4
+ };
5
+ export { endMeasurementFrom };
@@ -0,0 +1,2 @@
1
+ import { endMeasurementFrom } from './end-measurement-from';
2
+ export { endMeasurementFrom };
@@ -0,0 +1,3 @@
1
+ import { isRunningInKubernetes } from './kubernetes';
2
+ import { skipMetricsInEnvironment } from './skip-metrics-in-environment';
3
+ export { isRunningInKubernetes, skipMetricsInEnvironment };
@@ -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 { createMetricTypes } from './create-metric-types';
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 './kubernetes';
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, createMetricTypes, getSummary, getContentType, createRequestRecorder, createGcObserver, defaultNormalizers, normalizeStatusCode, normalizePath, normalizeMethod, isRunningInKubernetes, };
13
+ export { Prometheus, defaultRegister, createHttpMetrics, createGraphQlMetrics, createGcMetrics, getSummary, getContentType, createRequestRecorder, createGcObserver, defaultNormalizers, normalizeStatusCode, normalizePath, normalizeMethod, isRunningInKubernetes, skipMetricsInEnvironment, endMeasurementFrom, sortLabels, };
@@ -0,0 +1,2 @@
1
+ import { sortLabels } from './sort-labels';
2
+ export { sortLabels };
@@ -0,0 +1,3 @@
1
+ import type { TLabelValues } from '@promster/types';
2
+ declare function sortLabels(unsortedLabels: TLabelValues): TLabelValues;
3
+ export { 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 shouldSkipMetricsByEnvironment = options.detectKubernetes === true && !isRunningInKubernetes();
48
+ const shouldSkipMetricsInEnvironment = skipMetricsInEnvironment(options);
47
49
 
48
- if (!shouldSkipMetricsByEnvironment) {
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 defaultRequestLabels = ['path', 'status_code', 'method'];
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 shouldObserveMetricsInMilliseconds = options => options.accuracies.includes('ms');
60
+ const asArray$2 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
66
61
 
67
62
  const shouldObserveHttpRequestsAsSummary = options => options.metricTypes.includes('httpRequestsSummary');
68
63
 
@@ -70,216 +65,275 @@ const shouldObserveHttpRequestsAsHistogram = options => options.metricTypes.incl
70
65
 
71
66
  const shouldObserveHttpRequestsAsCounter = options => options.metricTypes.includes('httpRequestsTotal');
72
67
 
73
- const defaultOptions$1 = {
68
+ const shouldObserveHttpContentLengthAsHistogram = options => options.metricTypes.includes('httpContentLengthHistogram');
69
+
70
+ const defaultOptions$4 = {
74
71
  getLabelValues: () => ({}),
75
72
  labels: [],
76
- accuracies: ['s'],
77
73
  metricPrefix: '',
78
74
  metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],
79
75
  metricNames: {
80
- up: ['up'],
81
- countOfGcs: ['nodejs_gc_runs_total'],
82
- durationOfGc: ['nodejs_gc_pause_seconds_total'],
83
- reclaimedInGc: ['nodejs_gc_reclaimed_bytes_total'],
84
76
  httpRequestsTotal: ['http_requests_total'],
85
- httpRequestDurationPerPercentileInMilliseconds: ['http_request_duration_per_percentile_milliseconds'],
86
77
  httpRequestDurationPerPercentileInSeconds: ['http_request_duration_per_percentile_seconds'],
87
78
  httpRequestDurationInSeconds: ['http_request_duration_seconds'],
88
- httpRequestDurationInMilliseconds: ['http_request_duration_milliseconds'],
89
79
  httpRequestContentLengthInBytes: ['http_request_content_length_bytes'],
90
80
  httpResponseContentLengthInBytes: ['http_response_content_length_bytes']
91
81
  }
92
82
  };
93
83
 
94
- const getDefaultMetrics = options => ({
95
- up: asArray(options.metricNames.up).map(nameOfUpMetric => new Prometheus__namespace.Gauge({
96
- name: `${options.metricPrefix}${nameOfUpMetric}`,
97
- help: '1 = up, 0 = not up'
98
- })),
99
- countOfGcs: asArray(options.metricNames.countOfGcs).map(nameOfCountOfGcsMetric => new Prometheus__namespace.Counter({
100
- name: `${options.metricPrefix}${nameOfCountOfGcsMetric}`,
101
- help: 'Count of total garbage collections.',
102
- labelNames: defaultGcLabels
103
- })),
104
- durationOfGc: asArray(options.metricNames.durationOfGc).map(nameOfDurationOfGcMetric => new Prometheus__namespace.Counter({
105
- name: `${options.metricPrefix}${nameOfDurationOfGcMetric}`,
106
- help: 'Time spent in GC Pause in seconds.',
107
- labelNames: defaultGcLabels
108
- })),
109
- reclaimedInGc: asArray(options.metricNames.reclaimedInGc).map(nameOfReclaimedInGcMetric => new Prometheus__namespace.Counter({
110
- name: `${options.metricPrefix}${nameOfReclaimedInGcMetric}`,
111
- help: 'Total number of bytes reclaimed by GC.',
112
- labelNames: defaultGcLabels
113
- })),
114
- httpRequestContentLengthInBytes: 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({
115
86
  name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
116
87
  help: 'The HTTP request content length in bytes.',
117
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
88
+ labelNames: defaultLabels$2.concat(options.labels).sort(),
118
89
  buckets: options.buckets || defaultHttpContentLengthInBytes
119
- })),
120
- httpResponseContentLengthInBytes: asArray(options.metricNames.httpResponseContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
90
+ })) : undefined,
91
+ httpResponseContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray$2(options.metricNames.httpResponseContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
121
92
  name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
122
93
  help: 'The HTTP response content length in bytes.',
123
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
94
+ labelNames: defaultLabels$2.concat(options.labels).sort(),
124
95
  buckets: options.buckets || defaultHttpContentLengthInBytes
125
- }))
126
- });
127
-
128
- const getHttpRequestLatencyMetricsInMilliseconds = options => ({
129
- httpRequestDurationPerPercentileInMilliseconds: shouldObserveHttpRequestsAsSummary(options) && asArray(options.metricNames.httpRequestDurationPerPercentileInMilliseconds).map(nameOfHttpRequestDurationPerPercentileInMillisecondsMetric => new Prometheus__namespace.Summary({
130
- name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInMillisecondsMetric}`,
131
- help: 'The HTTP request latencies in milliseconds.',
132
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
133
- percentiles: options.percentiles || defaultHttpRequestDurationPercentilesInMillieconds
134
- })),
135
- httpRequestDurationInMilliseconds: shouldObserveHttpRequestsAsHistogram(options) && asArray(options.metricNames.httpRequestDurationInMilliseconds).map(nameOfHttpRequestDurationInMillisecondsMetric => new Prometheus__namespace.Histogram({
136
- name: `${options.metricPrefix}${nameOfHttpRequestDurationInMillisecondsMetric}`,
137
- help: 'The HTTP request latencies in milliseconds.',
138
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
139
- buckets: options.buckets || defaultHttpRequestDurationInMilliseconds
140
- }))
96
+ })) : undefined
141
97
  });
142
98
 
143
99
  const getHttpRequestLatencyMetricsInSeconds = options => ({
144
- httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) && asArray(options.metricNames.httpRequestDurationPerPercentileInSeconds).map(nameOfHttpRequestDurationPerPercentileInSeconds => new Prometheus__namespace.Summary({
100
+ httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) ? asArray$2(options.metricNames.httpRequestDurationPerPercentileInSeconds).map(nameOfHttpRequestDurationPerPercentileInSeconds => new Prometheus__namespace.Summary({
145
101
  name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInSeconds}`,
146
102
  help: 'The HTTP request latencies in seconds.',
147
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
103
+ labelNames: defaultLabels$2.concat(options.labels).sort(),
148
104
  percentiles: options.percentiles || defaultHttpRequestDurationPercentileInSeconds
149
- })),
150
- httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options) && asArray(options.metricNames.httpRequestDurationInSeconds).map(nameOfHttpRequestDurationInSecondsMetric => new Prometheus__namespace.Histogram({
105
+ })) : undefined,
106
+ httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options) ? asArray$2(options.metricNames.httpRequestDurationInSeconds).map(nameOfHttpRequestDurationInSecondsMetric => new Prometheus__namespace.Histogram({
151
107
  name: `${options.metricPrefix}${nameOfHttpRequestDurationInSecondsMetric}`,
152
108
  help: 'The HTTP request latencies in seconds.',
153
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
109
+ labelNames: defaultLabels$2.concat(options.labels).sort(),
154
110
  buckets: options.buckets || defaultHttpRequestDurationInSeconds
155
- }))
111
+ })) : undefined
156
112
  });
157
113
 
158
114
  const getHttpRequestCounterMetric = options => ({
159
- httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) && asArray(options.metricNames.httpRequestsTotal).map(nameOfHttpRequestsTotalMetric => new Prometheus__namespace.Counter({
115
+ httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) ? asArray$2(options.metricNames.httpRequestsTotal).map(nameOfHttpRequestsTotalMetric => new Prometheus__namespace.Counter({
160
116
  name: `${options.metricPrefix}${nameOfHttpRequestsTotalMetric}`,
161
117
  help: 'The total HTTP requests.',
162
- labelNames: defaultRequestLabels.concat(options.labels).sort()
163
- }))
118
+ labelNames: defaultLabels$2.concat(options.labels).sort()
119
+ })) : undefined
164
120
  });
165
121
 
166
- const createMetricTypes = options => {
167
- const defaultedOptions = merge__default["default"](defaultOptions$1, options);
122
+ const createHttpMetrics = options => {
123
+ const defaultedOptions = merge__default["default"](defaultOptions$4, options);
168
124
  configure({
169
125
  prefix: defaultedOptions.metricPrefix
170
126
  });
171
- const defaultMetrics = getDefaultMetrics(defaultedOptions);
172
- const httpRequestLatencyMetricsInMilliseconds = shouldObserveMetricsInMilliseconds(defaultedOptions) && getHttpRequestLatencyMetricsInMilliseconds(defaultedOptions);
173
- const httpRequestLatencyMetricsInSeconds = shouldObserveMetricsInSeconds(defaultedOptions) && getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
127
+ const metrics = getMetrics$2(defaultedOptions);
128
+ const httpRequestLatencyMetricsInSeconds = getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
174
129
  const httpRequestCounterMetric = getHttpRequestCounterMetric(defaultedOptions);
175
- return Object.assign({}, defaultMetrics, httpRequestLatencyMetricsInMilliseconds, httpRequestLatencyMetricsInSeconds, httpRequestCounterMetric);
130
+ return Object.assign({}, metrics, httpRequestLatencyMetricsInSeconds, httpRequestCounterMetric);
176
131
  };
177
132
 
178
- createMetricTypes.defaultOptions = defaultOptions$1;
133
+ createHttpMetrics.defaultOptions = defaultOptions$4;
179
134
 
180
- const getSummary = async () => defaultRegister.metrics();
135
+ const defaultGraphQlPercentiles = [0.5, 0.9, 0.95, 0.98, 0.99];
136
+ const defaultLabels$1 = ['operation_name'];
181
137
 
182
- const getContentType = () => defaultRegister.contentType;
138
+ const asArray$1 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
183
139
 
184
- const NS_PER_SEC = 1e9;
185
- const NS_PER_MS = 1e6;
140
+ const shouldObserveGraphQlParseDurationAsHistogram = options => options.metricTypes.includes('graphQlParseDurationHistogram');
186
141
 
187
- const sortLabels = unsortedLabels => Object.keys(unsortedLabels).sort((a, b) => {
188
- if (a < b) {
189
- return -1;
190
- }
142
+ const shouldObserveGraphQlValidationDurationAsHistogram = options => options.metricTypes.includes('graphQlValidationDurationHistogram');
191
143
 
192
- if (a > b) {
193
- return 1;
144
+ const shouldObserveGraphQlResolveFieldDurationAsHistogram = options => options.metricTypes.includes('graphQlResolveFieldDurationHistogram');
145
+
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']
194
161
  }
162
+ };
195
163
 
196
- return 0;
197
- }).reduce((sortedLabels, labelName) => {
198
- sortedLabels[labelName] = unsortedLabels[labelName];
199
- return sortedLabels;
200
- }, {});
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
+ });
201
195
 
202
- const endMeasurementFrom = start => {
203
- const [seconds, nanoseconds] = process.hrtime(start);
204
- return {
205
- durationMs: Math.round((seconds * NS_PER_SEC + nanoseconds) / NS_PER_MS),
206
- durationS: (seconds * NS_PER_SEC + nanoseconds) / NS_PER_SEC
207
- };
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;
208
203
  };
209
204
 
210
- const shouldObserveMetricType = metricType => options => {
211
- var _options$metricTypes;
205
+ createGraphQlMetrics.defaultOptions = defaultOptions$3;
212
206
 
213
- return (_options$metricTypes = options.metricTypes) === null || _options$metricTypes === void 0 ? void 0 : _options$metricTypes.includes(metricType);
207
+ const defaultLabels = ['gc_type'];
208
+
209
+ const asArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
210
+
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
+ }
214
221
  };
215
222
 
216
- const shouldObserveMetricAccuracy = accuracy => options => {
217
- var _options$accuracies;
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
+ });
218
244
 
219
- return (_options$accuracies = options.accuracies) === null || _options$accuracies === void 0 ? void 0 : _options$accuracies.includes(accuracy);
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;
220
252
  };
221
253
 
222
- const defaultOptions = {
223
- accuracies: ['s'],
224
- metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],
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 = {
225
287
  skip: () => false,
226
288
  detectKubernetes: false
227
289
  };
228
290
 
229
- const createRequestRecorder = (metricTypes, options = defaultOptions) => {
230
- const defaultedRecorderOptions = merge__default["default"](defaultOptions, options);
231
- const shouldSkipMetricsByEnvironment = defaultedRecorderOptions.detectKubernetes && !isRunningInKubernetes();
232
- const shouldObserveInSeconds = shouldObserveMetricAccuracy('s')(defaultedRecorderOptions);
233
- const shouldObserveInMilliseconds = shouldObserveMetricAccuracy('ms')(defaultedRecorderOptions);
234
- const shouldObserveInSummary = shouldObserveMetricType('httpRequestsSummary')(defaultedRecorderOptions);
235
- const shouldObserveInHistogram = shouldObserveMetricType('httpRequestsHistogram')(defaultedRecorderOptions);
236
- const shouldObserveInCounter = shouldObserveMetricType('httpRequestsTotal')(defaultedRecorderOptions);
291
+ const createRequestRecorder = (metrics, options = defaultOptions$1) => {
292
+ const defaultedRecorderOptions = merge__default["default"](defaultOptions$1, options);
293
+ const shouldSkipMetricsByEnvironment = skipMetricsInEnvironment(defaultedRecorderOptions);
237
294
  return (start, recordingOptions) => {
238
295
  const {
239
- durationMs,
240
296
  durationS
241
297
  } = endMeasurementFrom(start);
242
298
  const labels = sortLabels(recordingOptions.labels);
243
299
 
244
- if (shouldObserveInMilliseconds && shouldObserveInHistogram && !shouldSkipMetricsByEnvironment) {
245
- metricTypes.httpRequestDurationInMilliseconds.forEach(httpRequestDurationInMillisecondsMetricType => {
246
- httpRequestDurationInMillisecondsMetricType.observe(labels, durationMs);
247
- });
248
- }
249
-
250
- if (shouldObserveInMilliseconds && shouldObserveInSummary && !shouldSkipMetricsByEnvironment) {
251
- metricTypes.httpRequestDurationPerPercentileInMilliseconds.forEach(httpRequestDurationPerPercentileInMillisecondsMetricType => {
252
- httpRequestDurationPerPercentileInMillisecondsMetricType.observe(labels, durationMs);
253
- });
254
- }
300
+ if (!shouldSkipMetricsByEnvironment) {
301
+ var _metrics$httpRequestD;
255
302
 
256
- if (shouldObserveInSeconds && shouldObserveInHistogram && !shouldSkipMetricsByEnvironment) {
257
- metricTypes.httpRequestDurationInSeconds.forEach(httpRequestDurationInSecondsMetricType => {
303
+ (_metrics$httpRequestD = metrics.httpRequestDurationInSeconds) === null || _metrics$httpRequestD === void 0 ? void 0 : _metrics$httpRequestD.forEach(httpRequestDurationInSecondsMetricType => {
258
304
  httpRequestDurationInSecondsMetricType.observe(labels, durationS);
259
305
  });
260
306
  }
261
307
 
262
- if (shouldObserveInSeconds && shouldObserveInSummary && !shouldSkipMetricsByEnvironment) {
263
- metricTypes.httpRequestDurationPerPercentileInSeconds.forEach(httpRequestDurationPerPercentileInSecondsMetricType => {
308
+ if (!shouldSkipMetricsByEnvironment) {
309
+ var _metrics$httpRequestD2;
310
+
311
+ (_metrics$httpRequestD2 = metrics.httpRequestDurationPerPercentileInSeconds) === null || _metrics$httpRequestD2 === void 0 ? void 0 : _metrics$httpRequestD2.forEach(httpRequestDurationPerPercentileInSecondsMetricType => {
264
312
  httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS);
265
313
  });
266
314
  }
267
315
 
268
- if (shouldObserveInCounter && !shouldSkipMetricsByEnvironment) {
269
- metricTypes.httpRequestsTotal.forEach(httpRequestsTotalMetricType => {
316
+ if (!shouldSkipMetricsByEnvironment) {
317
+ var _metrics$httpRequests;
318
+
319
+ (_metrics$httpRequests = metrics.httpRequestsTotal) === null || _metrics$httpRequests === void 0 ? void 0 : _metrics$httpRequests.forEach(httpRequestsTotalMetricType => {
270
320
  httpRequestsTotalMetricType.inc(labels);
271
321
  });
272
322
  }
273
323
 
274
- if (metricTypes.httpRequestContentLengthInBytes && recordingOptions.requestContentLength) {
275
- metricTypes.httpRequestContentLengthInBytes.forEach(httpRequestContentLengthInBytesMetricType => {
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 => {
276
328
  httpRequestContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
277
329
  recordingOptions.requestContentLength);
278
330
  });
279
331
  }
280
332
 
281
- if (metricTypes.httpResponseContentLengthInBytes && recordingOptions.responseContentLength) {
282
- metricTypes.httpResponseContentLengthInBytes.forEach(httpResponseContentLengthInBytesMetricType => {
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 => {
283
337
  httpResponseContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
284
338
  recordingOptions.responseContentLength);
285
339
  });
@@ -287,7 +341,7 @@ const createRequestRecorder = (metricTypes, options = defaultOptions) => {
287
341
  };
288
342
  };
289
343
 
290
- createRequestRecorder.defaultOptions = defaultOptions;
344
+ createRequestRecorder.defaultOptions = defaultOptions$1;
291
345
 
292
346
  const gc = requireOptional__default["default"]('@sematext/gc-stats');
293
347
  const gcTypes = {
@@ -299,27 +353,32 @@ const gcTypes = {
299
353
  8: 'weak_phantom',
300
354
  15: 'all'
301
355
  };
302
- const createGcObserver = once__default["default"](metricTypes => () => {
356
+ const defaultOptions = {
357
+ disableGcMetrics: false
358
+ };
359
+ const createGcObserver = once__default["default"]((metrics, options) => () => {
303
360
  if (typeof gc !== 'function') {
304
361
  return;
305
362
  }
306
363
 
364
+ if (options.disableGcMetrics) return;
307
365
  gc().on('stats', stats => {
308
366
  const gcType = gcTypes[stats.gctype];
309
- metricTypes.countOfGcs.forEach(countOfGcMetricType => {
367
+ metrics.countOfGcs.forEach(countOfGcMetricType => {
310
368
  countOfGcMetricType.labels(gcType).inc();
311
369
  });
312
- metricTypes.durationOfGc.forEach(durationOfGcMetricType => {
370
+ metrics.durationOfGc.forEach(durationOfGcMetricType => {
313
371
  durationOfGcMetricType.labels(gcType).inc(stats.pause / 1e9);
314
372
  });
315
373
 
316
374
  if (stats.diff.usedHeapSize < 0) {
317
- metricTypes.reclaimedInGc.forEach(reclaimedInGcMetricType => {
375
+ metrics.reclaimedInGc.forEach(reclaimedInGcMetricType => {
318
376
  reclaimedInGcMetricType.labels(gcType).inc(stats.diff.usedHeapSize * -1);
319
377
  });
320
378
  }
321
379
  });
322
380
  });
381
+ createGcObserver.defaultOptions = defaultOptions;
323
382
 
324
383
  const normalizeStatusCode = statusCode => statusCode;
325
384
 
@@ -336,14 +395,19 @@ const defaultNormalizers = {
336
395
  };
337
396
 
338
397
  exports.Prometheus = Prometheus__namespace;
398
+ exports.createGcMetrics = createGcMetrics;
339
399
  exports.createGcObserver = createGcObserver;
340
- exports.createMetricTypes = createMetricTypes;
400
+ exports.createGraphQlMetrics = createGraphQlMetrics;
401
+ exports.createHttpMetrics = createHttpMetrics;
341
402
  exports.createRequestRecorder = createRequestRecorder;
342
403
  exports.defaultNormalizers = defaultNormalizers;
343
404
  exports.defaultRegister = defaultRegister;
405
+ exports.endMeasurementFrom = endMeasurementFrom;
344
406
  exports.getContentType = getContentType;
345
407
  exports.getSummary = getSummary;
346
408
  exports.isRunningInKubernetes = isRunningInKubernetes;
347
409
  exports.normalizeMethod = normalizeMethod;
348
410
  exports.normalizePath = normalizePath;
349
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 shouldSkipMetricsByEnvironment = options.detectKubernetes === true && !isRunningInKubernetes();
48
+ const shouldSkipMetricsInEnvironment = skipMetricsInEnvironment(options);
47
49
 
48
- if (!shouldSkipMetricsByEnvironment) {
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 defaultRequestLabels = ['path', 'status_code', 'method'];
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 shouldObserveMetricsInMilliseconds = options => options.accuracies.includes('ms');
60
+ const asArray$2 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
66
61
 
67
62
  const shouldObserveHttpRequestsAsSummary = options => options.metricTypes.includes('httpRequestsSummary');
68
63
 
@@ -70,216 +65,275 @@ const shouldObserveHttpRequestsAsHistogram = options => options.metricTypes.incl
70
65
 
71
66
  const shouldObserveHttpRequestsAsCounter = options => options.metricTypes.includes('httpRequestsTotal');
72
67
 
73
- const defaultOptions$1 = {
68
+ const shouldObserveHttpContentLengthAsHistogram = options => options.metricTypes.includes('httpContentLengthHistogram');
69
+
70
+ const defaultOptions$4 = {
74
71
  getLabelValues: () => ({}),
75
72
  labels: [],
76
- accuracies: ['s'],
77
73
  metricPrefix: '',
78
74
  metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],
79
75
  metricNames: {
80
- up: ['up'],
81
- countOfGcs: ['nodejs_gc_runs_total'],
82
- durationOfGc: ['nodejs_gc_pause_seconds_total'],
83
- reclaimedInGc: ['nodejs_gc_reclaimed_bytes_total'],
84
76
  httpRequestsTotal: ['http_requests_total'],
85
- httpRequestDurationPerPercentileInMilliseconds: ['http_request_duration_per_percentile_milliseconds'],
86
77
  httpRequestDurationPerPercentileInSeconds: ['http_request_duration_per_percentile_seconds'],
87
78
  httpRequestDurationInSeconds: ['http_request_duration_seconds'],
88
- httpRequestDurationInMilliseconds: ['http_request_duration_milliseconds'],
89
79
  httpRequestContentLengthInBytes: ['http_request_content_length_bytes'],
90
80
  httpResponseContentLengthInBytes: ['http_response_content_length_bytes']
91
81
  }
92
82
  };
93
83
 
94
- const getDefaultMetrics = options => ({
95
- up: asArray(options.metricNames.up).map(nameOfUpMetric => new Prometheus__namespace.Gauge({
96
- name: `${options.metricPrefix}${nameOfUpMetric}`,
97
- help: '1 = up, 0 = not up'
98
- })),
99
- countOfGcs: asArray(options.metricNames.countOfGcs).map(nameOfCountOfGcsMetric => new Prometheus__namespace.Counter({
100
- name: `${options.metricPrefix}${nameOfCountOfGcsMetric}`,
101
- help: 'Count of total garbage collections.',
102
- labelNames: defaultGcLabels
103
- })),
104
- durationOfGc: asArray(options.metricNames.durationOfGc).map(nameOfDurationOfGcMetric => new Prometheus__namespace.Counter({
105
- name: `${options.metricPrefix}${nameOfDurationOfGcMetric}`,
106
- help: 'Time spent in GC Pause in seconds.',
107
- labelNames: defaultGcLabels
108
- })),
109
- reclaimedInGc: asArray(options.metricNames.reclaimedInGc).map(nameOfReclaimedInGcMetric => new Prometheus__namespace.Counter({
110
- name: `${options.metricPrefix}${nameOfReclaimedInGcMetric}`,
111
- help: 'Total number of bytes reclaimed by GC.',
112
- labelNames: defaultGcLabels
113
- })),
114
- httpRequestContentLengthInBytes: 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({
115
86
  name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
116
87
  help: 'The HTTP request content length in bytes.',
117
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
88
+ labelNames: defaultLabels$2.concat(options.labels).sort(),
118
89
  buckets: options.buckets || defaultHttpContentLengthInBytes
119
- })),
120
- httpResponseContentLengthInBytes: asArray(options.metricNames.httpResponseContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
90
+ })) : undefined,
91
+ httpResponseContentLengthInBytes: shouldObserveHttpContentLengthAsHistogram(options) ? asArray$2(options.metricNames.httpResponseContentLengthInBytes).map(nameOfHttpContentLengthMetric => new Prometheus__namespace.Histogram({
121
92
  name: `${options.metricPrefix}${nameOfHttpContentLengthMetric}`,
122
93
  help: 'The HTTP response content length in bytes.',
123
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
94
+ labelNames: defaultLabels$2.concat(options.labels).sort(),
124
95
  buckets: options.buckets || defaultHttpContentLengthInBytes
125
- }))
126
- });
127
-
128
- const getHttpRequestLatencyMetricsInMilliseconds = options => ({
129
- httpRequestDurationPerPercentileInMilliseconds: shouldObserveHttpRequestsAsSummary(options) && asArray(options.metricNames.httpRequestDurationPerPercentileInMilliseconds).map(nameOfHttpRequestDurationPerPercentileInMillisecondsMetric => new Prometheus__namespace.Summary({
130
- name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInMillisecondsMetric}`,
131
- help: 'The HTTP request latencies in milliseconds.',
132
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
133
- percentiles: options.percentiles || defaultHttpRequestDurationPercentilesInMillieconds
134
- })),
135
- httpRequestDurationInMilliseconds: shouldObserveHttpRequestsAsHistogram(options) && asArray(options.metricNames.httpRequestDurationInMilliseconds).map(nameOfHttpRequestDurationInMillisecondsMetric => new Prometheus__namespace.Histogram({
136
- name: `${options.metricPrefix}${nameOfHttpRequestDurationInMillisecondsMetric}`,
137
- help: 'The HTTP request latencies in milliseconds.',
138
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
139
- buckets: options.buckets || defaultHttpRequestDurationInMilliseconds
140
- }))
96
+ })) : undefined
141
97
  });
142
98
 
143
99
  const getHttpRequestLatencyMetricsInSeconds = options => ({
144
- httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) && asArray(options.metricNames.httpRequestDurationPerPercentileInSeconds).map(nameOfHttpRequestDurationPerPercentileInSeconds => new Prometheus__namespace.Summary({
100
+ httpRequestDurationPerPercentileInSeconds: shouldObserveHttpRequestsAsSummary(options) ? asArray$2(options.metricNames.httpRequestDurationPerPercentileInSeconds).map(nameOfHttpRequestDurationPerPercentileInSeconds => new Prometheus__namespace.Summary({
145
101
  name: `${options.metricPrefix}${nameOfHttpRequestDurationPerPercentileInSeconds}`,
146
102
  help: 'The HTTP request latencies in seconds.',
147
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
103
+ labelNames: defaultLabels$2.concat(options.labels).sort(),
148
104
  percentiles: options.percentiles || defaultHttpRequestDurationPercentileInSeconds
149
- })),
150
- httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options) && asArray(options.metricNames.httpRequestDurationInSeconds).map(nameOfHttpRequestDurationInSecondsMetric => new Prometheus__namespace.Histogram({
105
+ })) : undefined,
106
+ httpRequestDurationInSeconds: shouldObserveHttpRequestsAsHistogram(options) ? asArray$2(options.metricNames.httpRequestDurationInSeconds).map(nameOfHttpRequestDurationInSecondsMetric => new Prometheus__namespace.Histogram({
151
107
  name: `${options.metricPrefix}${nameOfHttpRequestDurationInSecondsMetric}`,
152
108
  help: 'The HTTP request latencies in seconds.',
153
- labelNames: defaultRequestLabels.concat(options.labels).sort(),
109
+ labelNames: defaultLabels$2.concat(options.labels).sort(),
154
110
  buckets: options.buckets || defaultHttpRequestDurationInSeconds
155
- }))
111
+ })) : undefined
156
112
  });
157
113
 
158
114
  const getHttpRequestCounterMetric = options => ({
159
- httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) && asArray(options.metricNames.httpRequestsTotal).map(nameOfHttpRequestsTotalMetric => new Prometheus__namespace.Counter({
115
+ httpRequestsTotal: shouldObserveHttpRequestsAsCounter(options) ? asArray$2(options.metricNames.httpRequestsTotal).map(nameOfHttpRequestsTotalMetric => new Prometheus__namespace.Counter({
160
116
  name: `${options.metricPrefix}${nameOfHttpRequestsTotalMetric}`,
161
117
  help: 'The total HTTP requests.',
162
- labelNames: defaultRequestLabels.concat(options.labels).sort()
163
- }))
118
+ labelNames: defaultLabels$2.concat(options.labels).sort()
119
+ })) : undefined
164
120
  });
165
121
 
166
- const createMetricTypes = options => {
167
- const defaultedOptions = merge__default["default"](defaultOptions$1, options);
122
+ const createHttpMetrics = options => {
123
+ const defaultedOptions = merge__default["default"](defaultOptions$4, options);
168
124
  configure({
169
125
  prefix: defaultedOptions.metricPrefix
170
126
  });
171
- const defaultMetrics = getDefaultMetrics(defaultedOptions);
172
- const httpRequestLatencyMetricsInMilliseconds = shouldObserveMetricsInMilliseconds(defaultedOptions) && getHttpRequestLatencyMetricsInMilliseconds(defaultedOptions);
173
- const httpRequestLatencyMetricsInSeconds = shouldObserveMetricsInSeconds(defaultedOptions) && getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
127
+ const metrics = getMetrics$2(defaultedOptions);
128
+ const httpRequestLatencyMetricsInSeconds = getHttpRequestLatencyMetricsInSeconds(defaultedOptions);
174
129
  const httpRequestCounterMetric = getHttpRequestCounterMetric(defaultedOptions);
175
- return Object.assign({}, defaultMetrics, httpRequestLatencyMetricsInMilliseconds, httpRequestLatencyMetricsInSeconds, httpRequestCounterMetric);
130
+ return Object.assign({}, metrics, httpRequestLatencyMetricsInSeconds, httpRequestCounterMetric);
176
131
  };
177
132
 
178
- createMetricTypes.defaultOptions = defaultOptions$1;
133
+ createHttpMetrics.defaultOptions = defaultOptions$4;
179
134
 
180
- const getSummary = async () => defaultRegister.metrics();
135
+ const defaultGraphQlPercentiles = [0.5, 0.9, 0.95, 0.98, 0.99];
136
+ const defaultLabels$1 = ['operation_name'];
181
137
 
182
- const getContentType = () => defaultRegister.contentType;
138
+ const asArray$1 = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
183
139
 
184
- const NS_PER_SEC = 1e9;
185
- const NS_PER_MS = 1e6;
140
+ const shouldObserveGraphQlParseDurationAsHistogram = options => options.metricTypes.includes('graphQlParseDurationHistogram');
186
141
 
187
- const sortLabels = unsortedLabels => Object.keys(unsortedLabels).sort((a, b) => {
188
- if (a < b) {
189
- return -1;
190
- }
142
+ const shouldObserveGraphQlValidationDurationAsHistogram = options => options.metricTypes.includes('graphQlValidationDurationHistogram');
191
143
 
192
- if (a > b) {
193
- return 1;
144
+ const shouldObserveGraphQlResolveFieldDurationAsHistogram = options => options.metricTypes.includes('graphQlResolveFieldDurationHistogram');
145
+
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']
194
161
  }
162
+ };
195
163
 
196
- return 0;
197
- }).reduce((sortedLabels, labelName) => {
198
- sortedLabels[labelName] = unsortedLabels[labelName];
199
- return sortedLabels;
200
- }, {});
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
+ });
201
195
 
202
- const endMeasurementFrom = start => {
203
- const [seconds, nanoseconds] = process.hrtime(start);
204
- return {
205
- durationMs: Math.round((seconds * NS_PER_SEC + nanoseconds) / NS_PER_MS),
206
- durationS: (seconds * NS_PER_SEC + nanoseconds) / NS_PER_SEC
207
- };
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;
208
203
  };
209
204
 
210
- const shouldObserveMetricType = metricType => options => {
211
- var _options$metricTypes;
205
+ createGraphQlMetrics.defaultOptions = defaultOptions$3;
212
206
 
213
- return (_options$metricTypes = options.metricTypes) === null || _options$metricTypes === void 0 ? void 0 : _options$metricTypes.includes(metricType);
207
+ const defaultLabels = ['gc_type'];
208
+
209
+ const asArray = maybeArray => Array.isArray(maybeArray) ? maybeArray : [maybeArray];
210
+
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
+ }
214
221
  };
215
222
 
216
- const shouldObserveMetricAccuracy = accuracy => options => {
217
- var _options$accuracies;
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
+ });
218
244
 
219
- return (_options$accuracies = options.accuracies) === null || _options$accuracies === void 0 ? void 0 : _options$accuracies.includes(accuracy);
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;
220
252
  };
221
253
 
222
- const defaultOptions = {
223
- accuracies: ['s'],
224
- metricTypes: ['httpRequestsTotal', 'httpRequestsHistogram'],
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 = {
225
287
  skip: () => false,
226
288
  detectKubernetes: false
227
289
  };
228
290
 
229
- const createRequestRecorder = (metricTypes, options = defaultOptions) => {
230
- const defaultedRecorderOptions = merge__default["default"](defaultOptions, options);
231
- const shouldSkipMetricsByEnvironment = defaultedRecorderOptions.detectKubernetes && !isRunningInKubernetes();
232
- const shouldObserveInSeconds = shouldObserveMetricAccuracy('s')(defaultedRecorderOptions);
233
- const shouldObserveInMilliseconds = shouldObserveMetricAccuracy('ms')(defaultedRecorderOptions);
234
- const shouldObserveInSummary = shouldObserveMetricType('httpRequestsSummary')(defaultedRecorderOptions);
235
- const shouldObserveInHistogram = shouldObserveMetricType('httpRequestsHistogram')(defaultedRecorderOptions);
236
- const shouldObserveInCounter = shouldObserveMetricType('httpRequestsTotal')(defaultedRecorderOptions);
291
+ const createRequestRecorder = (metrics, options = defaultOptions$1) => {
292
+ const defaultedRecorderOptions = merge__default["default"](defaultOptions$1, options);
293
+ const shouldSkipMetricsByEnvironment = skipMetricsInEnvironment(defaultedRecorderOptions);
237
294
  return (start, recordingOptions) => {
238
295
  const {
239
- durationMs,
240
296
  durationS
241
297
  } = endMeasurementFrom(start);
242
298
  const labels = sortLabels(recordingOptions.labels);
243
299
 
244
- if (shouldObserveInMilliseconds && shouldObserveInHistogram && !shouldSkipMetricsByEnvironment) {
245
- metricTypes.httpRequestDurationInMilliseconds.forEach(httpRequestDurationInMillisecondsMetricType => {
246
- httpRequestDurationInMillisecondsMetricType.observe(labels, durationMs);
247
- });
248
- }
249
-
250
- if (shouldObserveInMilliseconds && shouldObserveInSummary && !shouldSkipMetricsByEnvironment) {
251
- metricTypes.httpRequestDurationPerPercentileInMilliseconds.forEach(httpRequestDurationPerPercentileInMillisecondsMetricType => {
252
- httpRequestDurationPerPercentileInMillisecondsMetricType.observe(labels, durationMs);
253
- });
254
- }
300
+ if (!shouldSkipMetricsByEnvironment) {
301
+ var _metrics$httpRequestD;
255
302
 
256
- if (shouldObserveInSeconds && shouldObserveInHistogram && !shouldSkipMetricsByEnvironment) {
257
- metricTypes.httpRequestDurationInSeconds.forEach(httpRequestDurationInSecondsMetricType => {
303
+ (_metrics$httpRequestD = metrics.httpRequestDurationInSeconds) === null || _metrics$httpRequestD === void 0 ? void 0 : _metrics$httpRequestD.forEach(httpRequestDurationInSecondsMetricType => {
258
304
  httpRequestDurationInSecondsMetricType.observe(labels, durationS);
259
305
  });
260
306
  }
261
307
 
262
- if (shouldObserveInSeconds && shouldObserveInSummary && !shouldSkipMetricsByEnvironment) {
263
- metricTypes.httpRequestDurationPerPercentileInSeconds.forEach(httpRequestDurationPerPercentileInSecondsMetricType => {
308
+ if (!shouldSkipMetricsByEnvironment) {
309
+ var _metrics$httpRequestD2;
310
+
311
+ (_metrics$httpRequestD2 = metrics.httpRequestDurationPerPercentileInSeconds) === null || _metrics$httpRequestD2 === void 0 ? void 0 : _metrics$httpRequestD2.forEach(httpRequestDurationPerPercentileInSecondsMetricType => {
264
312
  httpRequestDurationPerPercentileInSecondsMetricType.observe(labels, durationS);
265
313
  });
266
314
  }
267
315
 
268
- if (shouldObserveInCounter && !shouldSkipMetricsByEnvironment) {
269
- metricTypes.httpRequestsTotal.forEach(httpRequestsTotalMetricType => {
316
+ if (!shouldSkipMetricsByEnvironment) {
317
+ var _metrics$httpRequests;
318
+
319
+ (_metrics$httpRequests = metrics.httpRequestsTotal) === null || _metrics$httpRequests === void 0 ? void 0 : _metrics$httpRequests.forEach(httpRequestsTotalMetricType => {
270
320
  httpRequestsTotalMetricType.inc(labels);
271
321
  });
272
322
  }
273
323
 
274
- if (metricTypes.httpRequestContentLengthInBytes && recordingOptions.requestContentLength) {
275
- metricTypes.httpRequestContentLengthInBytes.forEach(httpRequestContentLengthInBytesMetricType => {
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 => {
276
328
  httpRequestContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
277
329
  recordingOptions.requestContentLength);
278
330
  });
279
331
  }
280
332
 
281
- if (metricTypes.httpResponseContentLengthInBytes && recordingOptions.responseContentLength) {
282
- metricTypes.httpResponseContentLengthInBytes.forEach(httpResponseContentLengthInBytesMetricType => {
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 => {
283
337
  httpResponseContentLengthInBytesMetricType.observe(labels, // @ts-expect-error
284
338
  recordingOptions.responseContentLength);
285
339
  });
@@ -287,7 +341,7 @@ const createRequestRecorder = (metricTypes, options = defaultOptions) => {
287
341
  };
288
342
  };
289
343
 
290
- createRequestRecorder.defaultOptions = defaultOptions;
344
+ createRequestRecorder.defaultOptions = defaultOptions$1;
291
345
 
292
346
  const gc = requireOptional__default["default"]('@sematext/gc-stats');
293
347
  const gcTypes = {
@@ -299,27 +353,32 @@ const gcTypes = {
299
353
  8: 'weak_phantom',
300
354
  15: 'all'
301
355
  };
302
- const createGcObserver = once__default["default"](metricTypes => () => {
356
+ const defaultOptions = {
357
+ disableGcMetrics: false
358
+ };
359
+ const createGcObserver = once__default["default"]((metrics, options) => () => {
303
360
  if (typeof gc !== 'function') {
304
361
  return;
305
362
  }
306
363
 
364
+ if (options.disableGcMetrics) return;
307
365
  gc().on('stats', stats => {
308
366
  const gcType = gcTypes[stats.gctype];
309
- metricTypes.countOfGcs.forEach(countOfGcMetricType => {
367
+ metrics.countOfGcs.forEach(countOfGcMetricType => {
310
368
  countOfGcMetricType.labels(gcType).inc();
311
369
  });
312
- metricTypes.durationOfGc.forEach(durationOfGcMetricType => {
370
+ metrics.durationOfGc.forEach(durationOfGcMetricType => {
313
371
  durationOfGcMetricType.labels(gcType).inc(stats.pause / 1e9);
314
372
  });
315
373
 
316
374
  if (stats.diff.usedHeapSize < 0) {
317
- metricTypes.reclaimedInGc.forEach(reclaimedInGcMetricType => {
375
+ metrics.reclaimedInGc.forEach(reclaimedInGcMetricType => {
318
376
  reclaimedInGcMetricType.labels(gcType).inc(stats.diff.usedHeapSize * -1);
319
377
  });
320
378
  }
321
379
  });
322
380
  });
381
+ createGcObserver.defaultOptions = defaultOptions;
323
382
 
324
383
  const normalizeStatusCode = statusCode => statusCode;
325
384
 
@@ -336,14 +395,19 @@ const defaultNormalizers = {
336
395
  };
337
396
 
338
397
  exports.Prometheus = Prometheus__namespace;
398
+ exports.createGcMetrics = createGcMetrics;
339
399
  exports.createGcObserver = createGcObserver;
340
- exports.createMetricTypes = createMetricTypes;
400
+ exports.createGraphQlMetrics = createGraphQlMetrics;
401
+ exports.createHttpMetrics = createHttpMetrics;
341
402
  exports.createRequestRecorder = createRequestRecorder;
342
403
  exports.defaultNormalizers = defaultNormalizers;
343
404
  exports.defaultRegister = defaultRegister;
405
+ exports.endMeasurementFrom = endMeasurementFrom;
344
406
  exports.getContentType = getContentType;
345
407
  exports.getSummary = getSummary;
346
408
  exports.isRunningInKubernetes = isRunningInKubernetes;
347
409
  exports.normalizeMethod = normalizeMethod;
348
410
  exports.normalizePath = normalizePath;
349
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": "7.0.2",
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",
@@ -17,12 +16,13 @@
17
16
  "access": "public"
18
17
  },
19
18
  "engines": {
20
- "node": ">=9",
21
- "npm": ">=3"
19
+ "node": ">=14",
20
+ "npm": ">=6"
22
21
  },
23
22
  "repository": {
24
23
  "type": "git",
25
- "url": "git+https://github.com/tdeekens/promster.git"
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,14 +46,15 @@
46
46
  "url-value-parser": "2.0.3"
47
47
  },
48
48
  "devDependencies": {
49
- "@promster/types": "^3.1.2",
50
- "@types/lodash": "4.14.175",
51
- "prom-client": "13.2.0"
49
+ "@promster/types": "^3.2.0",
50
+ "@types/lodash": "4.14.176",
51
+ "prom-client": "14.0.1",
52
+ "typescript": "4.4.4"
52
53
  },
53
54
  "optionalDependencies": {
54
55
  "@sematext/gc-stats": "1.5.5"
55
56
  },
56
57
  "peerDependencies": {
57
- "prom-client": "13.x.x"
58
+ "prom-client": "13.x.x || 14.x"
58
59
  }
59
60
  }
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><br />
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 };
@@ -1,2 +0,0 @@
1
- import { createMetricTypes } from './create-metric-types';
2
- export { createMetricTypes };
@@ -1,2 +0,0 @@
1
- import { isRunningInKubernetes } from './kubernetes';
2
- export { isRunningInKubernetes };