{"id":15062624,"url":"https://github.com/christiangalsterer/node-postgres-prometheus-exporter","last_synced_at":"2025-04-10T10:10:23.522Z","repository":{"id":217643374,"uuid":"744418370","full_name":"christiangalsterer/node-postgres-prometheus-exporter","owner":"christiangalsterer","description":"A prometheus exporter for node-postgres","archived":false,"fork":false,"pushed_at":"2025-04-09T14:12:06.000Z","size":2199,"stargazers_count":5,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-09T15:26:13.524Z","etag":null,"topics":["grafana","grafana-dashboards","metrics","monitoring","node-js","node-postgres","nodejs","pg","postgres","postgresql","prometheus","prometheus-exporter","sre"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/christiangalsterer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-01-17T09:04:10.000Z","updated_at":"2025-04-08T01:47:23.000Z","dependencies_parsed_at":"2024-03-19T02:42:35.508Z","dependency_job_id":"67e38f29-7554-4ad7-8cce-e40f96b72819","html_url":"https://github.com/christiangalsterer/node-postgres-prometheus-exporter","commit_stats":{"total_commits":45,"total_committers":2,"mean_commits":22.5,"dds":0.4,"last_synced_commit":"0dd143aa705b0dfa8317a38786f3f81f18ffc8f0"},"previous_names":["christiangalsterer/node-postgres-prometheus-exporter"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christiangalsterer%2Fnode-postgres-prometheus-exporter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christiangalsterer%2Fnode-postgres-prometheus-exporter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christiangalsterer%2Fnode-postgres-prometheus-exporter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christiangalsterer%2Fnode-postgres-prometheus-exporter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christiangalsterer","download_url":"https://codeload.github.com/christiangalsterer/node-postgres-prometheus-exporter/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248059477,"owners_count":21040953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["grafana","grafana-dashboards","metrics","monitoring","node-js","node-postgres","nodejs","pg","postgres","postgresql","prometheus","prometheus-exporter","sre"],"created_at":"2024-09-24T23:43:53.508Z","updated_at":"2025-04-10T10:10:23.500Z","avatar_url":"https://github.com/christiangalsterer.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub Actions CI Status](https://github.com/christiangalsterer/node-postgres-prometheus-exporter/actions/workflows/build.yaml/badge.svg)](https://github.com/christiangalsterer/node-postgres-prometheus-exporter/actions/workflows/build.yaml)\n[![codecov](https://codecov.io/gh/christiangalsterer/node-postgres-prometheus-exporter/graph/badge.svg?token=2KFRFMXSGS)](https://codecov.io/gh/christiangalsterer/node-postgres-prometheus-exporter)\n[![Coverage Status](https://coveralls.io/repos/github/christiangalsterer/node-postgres-prometheus-exporter/badge.svg?branch=main)](https://coveralls.io/github/christiangalsterer/node-postgres-prometheus-exporter?branch=main)\n[![Known Vulnerabilities](https://snyk.io/test/github/christiangalsterer/node-postgres-prometheus-exporter/badge.svg)](https://github.com/christiangalsterer/node-postgres-prometheus-exporter/security/advisories)\n[![npm downloads](https://img.shields.io/npm/dt/@christiangalsterer/node-postgres-prometheus-exporter.svg)](https://www.npmjs.com/package/@christiangalsterer/node-postgres-prometheus-exporter)\n[![npm version](https://img.shields.io/npm/v/@christiangalsterer/node-postgres-prometheus-exporter.svg)](https://www.npmjs.com/package/@christiangalsterer/node-postgres-prometheus-exporter?activeTab=versions)\n[![npm license](https://img.shields.io/npm/l/@christiangalsterer/node-postgres-prometheus-exporter.svg)](https://www.npmjs.com/package/@christiangalsterer/node-postgres-prometheus-exporter)\n[![semver](https://img.shields.io/badge/semver-2.0.0-green)](https://semver.org)\n[![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org)\n[![renovate](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://developer.mend.io/github/christiangalsterer/node-postgres-prometheus-exporter)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n![github stars](https://img.shields.io/github/stars/christiangalsterer/node-postgres-prometheus-exporter.svg)\n\n# Prometheus Exporter for node-postgres\n\nA prometheus exporter exposing metrics for [node-postgres](https://node-postgres.com/).\n\n## Available Metrics\n\nThe exporter provides the following metrics.\n\n### pg.Client Metrics\n\n|Metric Name|Description|Labels|Since|\n|---|---|---|---|\n|pg_client_errors_total|The total number of connection errors with a database|\u003cul\u003e\u003cli\u003e_host_: The host of the database.\u003c/li\u003e\u003cli\u003e_database_: The database name\u003c/li\u003e\u003cul\u003e|1.0.0|\n|pg_client_disconnects_total|The total number of disconnected connections|\u003cul\u003e\u003cli\u003e_host_: The host of the database.\u003c/li\u003e\u003cli\u003e_database_: The database name\u003c/li\u003e\u003cul\u003e|1.0.0|\n\n### pg.Pool Metrics\n\n|Metric Name|Description|Labels|Since|\n|---|---|---|---|\n|pg_pool_connections_created_total|The total number of created connections|\u003cul\u003e\u003cli\u003e_host_: The host of the database.\u003c/li\u003e\u003cli\u003e_database_: The database name\u003c/li\u003e\u003cul\u003e|1.0.0|\n|pg_pool_size|The current size of the connection pool, including active and idle members|\u003cul\u003e\u003cli\u003e_host_: The host of the database.\u003c/li\u003e\u003cli\u003e_database_: The database name\u003c/li\u003e\u003cul\u003e|1.0.0|\n|pg_pool_active_connections|The total number of active connections|\u003cul\u003e\u003cli\u003e_host_: The host of the database.\u003c/li\u003e\u003cli\u003e_database_: The database name\u003c/li\u003e\u003cul\u003e|1.0.0|\n|pg_pool_errors_total|The total number of connection errors with a database|\u003cul\u003e\u003cli\u003e_host_: The host of the database.\u003c/li\u003e\u003cli\u003e_database_: The database name\u003c/li\u003e\u003cul\u003e|1.0.0|\n|pg_pool_connections_removed_total|The total number of removed connections|\u003cul\u003e\u003cli\u003e_host_: The host of the database.\u003c/li\u003e\u003cli\u003e_database_: The database name\u003c/li\u003e\u003cul\u003e|1.0.0|\n\n## Example Output\n\nHere an example output in the prometheus format of the provided metrics.\n\n```sh\n# HELP pg_client_errors_total The total number of connection errors with a database.\n# TYPE pg_client_errors_total counter\npg_client_errors_total{host=\"localhost:5432\",database=\"node_postgres_test1\"} 1\n\n# HELP pg_client_disconnects_total The total number of disconnected connections.\n# TYPE pg_client_disconnects_total counter\npg_client_disconnects_total{host=\"localhost:5432\",database=\"node_postgres_test1\"} 1\n\n# HELP pg_pool_connections_created_total The total number of created connections.\n# TYPE pg_pool_connections_created_total counter\npg_pool_connections_created_total{host=\"localhost:5432\",database=\"node_postgres_test1\"} 19\n\n# HELP pg_pool_size The current size of the connection pool, including active and idle members.\n# TYPE pg_pool_size gauge\npg_pool_size{host=\"localhost:5432\",database=\"node_postgres_test1\"} 10\n\n# HELP pg_pool_max The maximum size of the connection pool.\n# TYPE pg_pool_max gauge\npg_pool_max{host=\"localhost:5432\",database=\"node_postgres_test1\"} 10\n\n# HELP pg_pool_active_connections The total number of active connections.\n# TYPE pg_pool_active_connections gauge\npg_pool_active_connections{host=\"localhost:5432\",database=\"node_postgres_test1\"} 10\n\n# HELP pg_pool_waiting_connections The total number of waiting connections.\n# TYPE pg_pool_waiting_connections gauge\npg_pool_waiting_connections{host=\"localhost:5432\",database=\"node_postgres_test1\"} 1\n\n# HELP pg_pool_idle_connections The total number of idle connections.\n# TYPE pg_pool_idle_connections gauge\npg_pool_idle_connections{host=\"localhost:5432\",database=\"node_postgres_test1\"} 0\n\n# HELP pg_pool_errors_total The total number of connection errors with a database.\n# TYPE pg_pool_errors_total counter\npg_pool_errors_total{host=\"localhost:5432\",database=\"node_postgres_test1\"} 1\n\n# HELP pg_pool_connections_removed_total The total number of removed connections.\n# TYPE pg_pool_connections_removed_total counter\npg_pool_connections_removed_total{host=\"localhost:5432\",database=\"node_postgres_test1\"} 9\n```\n\n# Usage\n\n## Add Dependency\n\nAdd the following dependency to your project to download the package from [npm](https://www.npmjs.com/package/@christiangalsterer/node-postgres-prometheus-exporter).\n\n```sh\nnpm i @christiangalsterer/node-postgres-prometheus-exporter\n```\n\n## TypeScript\n\nThe following example illustrates how to use the exporter to enable monitoring for the node-postgres.\n\n```ts\nimport { Client, Pool } from 'pg'\nimport { Registry, collectDefaultMetrics } from 'prom-client'\nimport { monitorPgClient, monitorPgPool } from '@christiangalsterer/node-postgres-prometheus-exporter'\n\n...\n\n// set up a pg.Client\nconst client = new Client()\n\n// set up a pg.Pool\nconst pool = new Pool()\n\n// set up the prometheus client\nconst register = new Registry();\ncollectDefaultMetrics({ register })\n\n// monitor the pg.Client\nmonitorPgClient(client, register)\n\n// monitor the pg.Pool\nmonitorPgPool(pool, register)\n\n...\n\n// connect to PostgreSQL *after* calling monitorPgClient() / monitorPgPool()\nawait client.connect()\nawait pool.connect()\n```\n\n## JavaScript\n\nThe following example illustrates how to use the exporter to enable monitoring for node-postgres.\n\n```js\nconst pg = require('pg')\nconst promClient = require( 'prom-client');\nconst postgresExporter = require('@christiangalsterer/node-postgres-prometheus-exporter')\n\n// set up a pg.Client\nconst client = new pg.Client()\n\n// set up a pg.Pool\nconst pool = new pg.Pool()\n\n// set up the prometheus client\nconst collectDefaultMetrics = promClient.collectDefaultMetrics;\nconst Registry = promClient.Registry;\nconst register = new Registry();\ncollectDefaultMetrics({ register });\n\n// monitor the pg.Client\npostgresExporter.monitorPgClient(client, register)\n\n// monitor the pg.Pool\npostgresExporter.monitorPgPool(pool, register)\n\n// connect to Postgres *after* calling monitorPgClient() / monitorPgPool()\nawait client.connect()\nawait pool.connect()\n```\n\n# Configuration\n\nThe exporter can be configured via properties specified on the optional parameter of type\n_PgClientExporterOptions_  and _PgPoolExporterOptions_ respectively.\n\n## PgClientExporterOptions\n\n|property|Description|Example|Since |\n|---|---|---|---|\n| defaultLabels | Default labels added to each metrics. | {'foo':'bar', 'alice': 3} | 1.0.0 |\n\n## PgPoolExporterOptions\n\n|property|Description|Example|Since |\n|---|---|---|---|\n| defaultLabels | Default labels added to each metrics. | {'foo':'bar', 'alice': 3} | 1.0.0|\n\n# Grafana Dashboard\n\nAn example dashboard for Grafana is available [here](/docs/grafana/dashboard.json) displaying the provided metrics by the exporter.\n\nHere an example for node-postgres client metrics:\n![Grafana:node-postgres Client Metrics](/docs/images/grafana_node_postgres_client_1.png \"Grafana: node-postgres Client Metrics\")\n\nHere an example for node-postgres pool metrics:\n![Grafana:node-postgres Pool Metrics](/docs/images/grafana_node_postgres_pool_1.png \"Grafana: node-postgres Pool Metrics\")\n\n# Changelog\n\nThe changes to project can be found in the [changelog](/CHANGELOG.md).\n\n# Compatibility\n\nThe following table list the compatibility of exporter versions with different node-postgres and prom-client versions.\n\n|Exporter Version|node-postgres Version|prom-client version|\n|---|---|---|\n|^1.0.0|^8.11.0|^15.0.0|\n\n# Contributions\n\nContributions are highly welcome. If you want to contribute to this project please follow the steps described in the [contribution guidelines](/CONTRIBUTING.md).\n\n# Projects Using The Exporter\n\nIf you want to support this project, please add a link to your project and/or company when you use this exporter.\n\n# Related Projects\n\nIf you are looking for a way to monitor your MongoDB Driver for Node.js you may have a look at \u003chttps://github.com/christiangalsterer/mongodb-driver-prometheus-exporter\u003e.\n\nIf you are looking for a way to monitor KafkaJs for Node.js you may have a look at \u003chttps://github.com/christiangalsterer/kafkajs-prometheus-exporter\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristiangalsterer%2Fnode-postgres-prometheus-exporter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristiangalsterer%2Fnode-postgres-prometheus-exporter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristiangalsterer%2Fnode-postgres-prometheus-exporter/lists"}