@tryghost/prometheus-metrics 3.0.2 → 3.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013-2026 Ghost Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -2,26 +2,22 @@
2
2
 
3
3
  A standalone server for exporting prometheus metrics from Ghost
4
4
 
5
-
6
5
  ## Purpose
7
6
 
8
7
  Prometheus metrics integration for exposing Ghost runtime counters, gauges, and histograms.
9
8
 
10
9
  ## Usage
11
10
 
12
-
13
11
  ## Develop
14
12
 
15
13
  This is a monorepo package.
16
14
 
17
15
  Follow the instructions for the top-level repo.
18
- 1. `git clone` this repo & `cd` into it as usual
19
- 2. Run `yarn` to install top-level dependencies.
20
-
21
16
 
17
+ 1. `git clone` this repo & `cd` into it as usual
18
+ 2. Run `pnpm install` to install top-level dependencies.
22
19
 
23
20
  ## Test
24
21
 
25
- - `yarn lint` run just eslint
26
- - `yarn test` run lint and tests
27
-
22
+ - `pnpm lint` runs oxlint
23
+ - `pnpm test` runs lint and tests
@@ -14,7 +14,7 @@ export declare class MetricsServer {
14
14
  private isShuttingDown;
15
15
  private createApp;
16
16
  private createStoppableServer;
17
- constructor({ serverConfig, handler, createApp, createStoppableServer }: {
17
+ constructor({ serverConfig, handler, createApp, createStoppableServer, }: {
18
18
  serverConfig: ServerConfig;
19
19
  handler: express.Handler;
20
20
  createApp?: CreateApp;
@@ -16,7 +16,7 @@ class MetricsServer {
16
16
  isShuttingDown;
17
17
  createApp;
18
18
  createStoppableServer;
19
- constructor({ serverConfig, handler, createApp, createStoppableServer }) {
19
+ constructor({ serverConfig, handler, createApp, createStoppableServer, }) {
20
20
  this.serverConfig = serverConfig;
21
21
  this.handler = handler;
22
22
  this.app = null;
@@ -91,7 +91,7 @@ export declare class PrometheusClient {
91
91
  * @param labelNames - The names of the labels for the metric
92
92
  * @returns The counter metric
93
93
  */
94
- registerCounter({ name, help, labelNames }: {
94
+ registerCounter({ name, help, labelNames, }: {
95
95
  name: string;
96
96
  help: string;
97
97
  labelNames?: string[];
@@ -103,7 +103,7 @@ export declare class PrometheusClient {
103
103
  * @param collect - The collect function to use for the gauge
104
104
  * @returns The gauge metric
105
105
  */
106
- registerGauge({ name, help, collect }: {
106
+ registerGauge({ name, help, collect, }: {
107
107
  name: string;
108
108
  help: string;
109
109
  collect?: () => void;
@@ -116,7 +116,7 @@ export declare class PrometheusClient {
116
116
  * @param collect - The collect function to use for the summary
117
117
  * @returns The summary metric
118
118
  */
119
- registerSummary({ name, help, percentiles, maxAgeSeconds, ageBuckets, pruneAgedBuckets, collect }: {
119
+ registerSummary({ name, help, percentiles, maxAgeSeconds, ageBuckets, pruneAgedBuckets, collect, }: {
120
120
  name: string;
121
121
  help: string;
122
122
  percentiles?: number[];
@@ -133,7 +133,7 @@ export declare class PrometheusClient {
133
133
  * @param collect - The collect function to use for the histogram
134
134
  * @returns The histogram metric
135
135
  */
136
- registerHistogram({ name, help, buckets }: {
136
+ registerHistogram({ name, help, buckets, }: {
137
137
  name: string;
138
138
  help: string;
139
139
  buckets: number[];
@@ -43,8 +43,8 @@ class PrometheusClient {
43
43
  timeout: 5000,
44
44
  agent: new http_1.default.Agent({
45
45
  keepAlive: true,
46
- maxSockets: 1
47
- })
46
+ maxSockets: 1,
47
+ }),
48
48
  });
49
49
  this.pushMetrics();
50
50
  this.pushInterval = setInterval(() => {
@@ -71,7 +71,7 @@ class PrometheusClient {
71
71
  catch (err) {
72
72
  let error;
73
73
  if (typeof err === 'object' && err !== null && 'code' in err) {
74
- error = 'Error pushing metrics to pushgateway: ' + err.code;
74
+ error = ('Error pushing metrics to pushgateway: ' + err.code);
75
75
  }
76
76
  else {
77
77
  error = 'Error pushing metrics to pushgateway: Unknown error';
@@ -179,11 +179,11 @@ class PrometheusClient {
179
179
  * @param labelNames - The names of the labels for the metric
180
180
  * @returns The counter metric
181
181
  */
182
- registerCounter({ name, help, labelNames = [] }) {
182
+ registerCounter({ name, help, labelNames = [], }) {
183
183
  return new this.client.Counter({
184
184
  name: `${this.prefix}${name}`,
185
185
  help,
186
- labelNames
186
+ labelNames,
187
187
  });
188
188
  }
189
189
  /**
@@ -193,11 +193,11 @@ class PrometheusClient {
193
193
  * @param collect - The collect function to use for the gauge
194
194
  * @returns The gauge metric
195
195
  */
196
- registerGauge({ name, help, collect }) {
196
+ registerGauge({ name, help, collect, }) {
197
197
  return new this.client.Gauge({
198
198
  name: `${this.prefix}${name}`,
199
199
  help,
200
- collect
200
+ collect,
201
201
  });
202
202
  }
203
203
  /**
@@ -208,7 +208,7 @@ class PrometheusClient {
208
208
  * @param collect - The collect function to use for the summary
209
209
  * @returns The summary metric
210
210
  */
211
- registerSummary({ name, help, percentiles, maxAgeSeconds, ageBuckets, pruneAgedBuckets, collect }) {
211
+ registerSummary({ name, help, percentiles, maxAgeSeconds, ageBuckets, pruneAgedBuckets, collect, }) {
212
212
  return new this.client.Summary({
213
213
  name: `${this.prefix}${name}`,
214
214
  help,
@@ -216,7 +216,7 @@ class PrometheusClient {
216
216
  maxAgeSeconds,
217
217
  ageBuckets,
218
218
  pruneAgedBuckets,
219
- collect
219
+ collect,
220
220
  });
221
221
  }
222
222
  /**
@@ -227,11 +227,11 @@ class PrometheusClient {
227
227
  * @param collect - The collect function to use for the histogram
228
228
  * @returns The histogram metric
229
229
  */
230
- registerHistogram({ name, help, buckets }) {
230
+ registerHistogram({ name, help, buckets, }) {
231
231
  return new this.client.Histogram({
232
232
  name: `${this.prefix}${name}`,
233
233
  help,
234
- buckets: buckets
234
+ buckets: buckets,
235
235
  });
236
236
  }
237
237
  // Utility functions for creating custom metrics
@@ -246,49 +246,49 @@ class PrometheusClient {
246
246
  help: 'The maximum number of connections allowed in the pool',
247
247
  collect() {
248
248
  this.set(knexInstance.client.pool.max);
249
- }
249
+ },
250
250
  });
251
251
  this.registerGauge({
252
252
  name: `db_connection_pool_min`,
253
253
  help: 'The minimum number of connections allowed in the pool',
254
254
  collect() {
255
255
  this.set(knexInstance.client.pool.min);
256
- }
256
+ },
257
257
  });
258
258
  this.registerGauge({
259
259
  name: `db_connection_pool_active`,
260
260
  help: 'The number of active connections to the database, which can be in use or idle',
261
261
  collect() {
262
262
  this.set(knexInstance.client.pool.numUsed() + knexInstance.client.pool.numFree());
263
- }
263
+ },
264
264
  });
265
265
  this.registerGauge({
266
266
  name: `db_connection_pool_used`,
267
267
  help: 'The number of connections currently in use by the database',
268
268
  collect() {
269
269
  this.set(knexInstance.client.pool.numUsed());
270
- }
270
+ },
271
271
  });
272
272
  this.registerGauge({
273
273
  name: `db_connection_pool_idle`,
274
274
  help: 'The number of active connections currently idle in pool',
275
275
  collect() {
276
276
  this.set(knexInstance.client.pool.numFree());
277
- }
277
+ },
278
278
  });
279
279
  this.registerGauge({
280
280
  name: `db_connection_pool_pending_acquires`,
281
281
  help: 'The number of connections currently waiting to be acquired from the pool',
282
282
  collect() {
283
283
  this.set(knexInstance.client.pool.numPendingAcquires());
284
- }
284
+ },
285
285
  });
286
286
  this.registerGauge({
287
287
  name: `db_connection_pool_pending_creates`,
288
288
  help: 'The number of connections currently waiting to be created',
289
289
  collect() {
290
290
  this.set(knexInstance.client.pool.numPendingCreates());
291
- }
291
+ },
292
292
  });
293
293
  const queryDurationSummary = this.registerSummary({
294
294
  name: `db_query_duration_seconds`,
@@ -296,7 +296,7 @@ class PrometheusClient {
296
296
  percentiles: [0.5, 0.9, 0.99],
297
297
  maxAgeSeconds: 60,
298
298
  ageBuckets: 6,
299
- pruneAgedBuckets: false
299
+ pruneAgedBuckets: false,
300
300
  });
301
301
  const acquireDurationSummary = this.registerSummary({
302
302
  name: `db_connection_acquire_duration_seconds`,
@@ -304,7 +304,7 @@ class PrometheusClient {
304
304
  percentiles: [0.5, 0.9, 0.99],
305
305
  maxAgeSeconds: 60,
306
306
  ageBuckets: 6,
307
- pruneAgedBuckets: false
307
+ pruneAgedBuckets: false,
308
308
  });
309
309
  const createDurationSummary = this.registerSummary({
310
310
  name: `db_connection_create_duration_seconds`,
@@ -312,7 +312,7 @@ class PrometheusClient {
312
312
  percentiles: [0.5, 0.9, 0.99],
313
313
  maxAgeSeconds: 60,
314
314
  ageBuckets: 6,
315
- pruneAgedBuckets: false
315
+ pruneAgedBuckets: false,
316
316
  });
317
317
  knexInstance.on('query', (query) => {
318
318
  // Add the query to the map
package/package.json CHANGED
@@ -1,48 +1,47 @@
1
1
  {
2
2
  "name": "@tryghost/prometheus-metrics",
3
- "version": "3.0.2",
3
+ "version": "3.1.0",
4
+ "author": "Ghost Foundation",
4
5
  "repository": {
5
6
  "type": "git",
6
7
  "url": "git+https://github.com/TryGhost/framework.git",
7
8
  "directory": "packages/prometheus-metrics"
8
9
  },
9
- "author": "Ghost Foundation",
10
+ "files": [
11
+ "build"
12
+ ],
13
+ "main": "build/index.js",
14
+ "types": "build/index.d.ts",
10
15
  "publishConfig": {
11
16
  "access": "public"
12
17
  },
13
- "main": "build/index.js",
14
- "types": "build/index.d.ts",
15
- "scripts": {
16
- "dev": "tsc --watch --preserveWatchOutput --sourceMap",
17
- "build": "yarn build:ts",
18
- "build:ts": "tsc",
19
- "prepare": "tsc",
20
- "test:unit": "NODE_ENV=testing vitest run --coverage",
21
- "test": "yarn test:types && yarn test:unit",
22
- "test:types": "tsc --noEmit",
23
- "lint:code": "eslint src/ --ext .ts --cache",
24
- "lint": "yarn lint:code && yarn lint:test",
25
- "lint:test": "eslint -c test/.eslintrc.js test/ --ext .ts --cache"
18
+ "dependencies": {
19
+ "express": "5.2.1",
20
+ "prom-client": "15.1.3",
21
+ "stoppable": "1.1.0",
22
+ "@tryghost/debug": "2.1.0",
23
+ "@tryghost/logging": "4.1.0"
26
24
  },
27
- "files": [
28
- "build"
29
- ],
30
25
  "devDependencies": {
31
26
  "@types/express": "5.0.6",
32
- "@types/sinon": "21.0.0",
27
+ "@types/node": "24.12.2",
28
+ "@types/sinon": "21.0.1",
33
29
  "@types/stoppable": "1.1.3",
34
30
  "@types/supertest": "7.2.0",
35
- "knex": "3.1.0",
36
- "nock": "14.0.11",
37
- "sinon": "21.0.2",
31
+ "knex": "3.2.9",
32
+ "nock": "14.0.12",
33
+ "sinon": "21.1.2",
38
34
  "supertest": "7.2.2",
39
35
  "ts-node": "10.9.2",
40
36
  "typescript": "5.9.3"
41
37
  },
42
- "dependencies": {
43
- "@tryghost/logging": "^4.0.2",
44
- "express": "5.2.1",
45
- "prom-client": "15.1.3",
46
- "stoppable": "1.1.0"
38
+ "scripts": {
39
+ "dev": "tsc --watch --preserveWatchOutput --sourceMap",
40
+ "build": "pnpm run build:ts",
41
+ "build:ts": "tsc",
42
+ "test:unit": "NODE_ENV=testing vitest run --coverage",
43
+ "test": "pnpm run test:types && pnpm run test:unit",
44
+ "test:types": "tsc --noEmit",
45
+ "lint": "oxlint -c ../../.oxlintrc.json ."
47
46
  }
48
- }
47
+ }