Jake Goldsborough

node-postgres-exporter — A Lightweight, Configurable PostgreSQL Prometheus Exporter

Published June 20, 2025

4 min read

Tags: devops, nodejs

I’m releasing a small project I’ve been building:

node-postgres-exporter, is a lightweight Prometheus exporter for PostgreSQL, written in Node.js.

The goal: build a fully configurable exporter that supports multiple databases, dynamic custom metrics, and solid production fault tolerance — while keeping the design modular and simple to operate.

There are excellent existing exporters in the ecosystem — but many of them require full privilege access, tightly coupled SQL views, or lack flexible multi-database support.

This exporter aims to solve a more targeted problem:

Key Features

Metric Types Supported

Dynamic Query Configuration

One of the core design goals for node-postgres-exporter was flexibility without requiring code changes. To achieve this, all custom metric definitions are fully externalized via configuration files.

queries.json

Custom metrics are defined in a simple queries.json file, allowing operators to add new metrics by writing plain SQL queries without modifying or redeploying the exporter. Each query entry includes:

name – the Prometheus metric name

help – description for the metric

type – gauge or counter

labels – array of columns to extract as metric labels

query – the raw SQL statement to run against the target database

[
  {
    "name": "active_users",
    "help": "Number of active users",
    "type": "gauge",
    "labels": ["status"],
    "query": "SELECT status, COUNT(*)::int FROM users GROUP BY status"
  }
]

On each scrape, the exporter executes the configured queries, extracts label values from the row fields, and populates the Prometheus metric accordingly.

Fault Tolerance and Isolation

Another design goal was to handle database failures gracefully. If one database becomes unavailable (network issue, restart, maintenance), the exporter:

Internally, this is implemented using:

Example Use Case

This design fits environments where:

What it’s not trying to be

This exporter is intentionally simple, safe, and scoped — easy to audit and deploy.

Roadmap / Future Ideas

There’s plenty of room for future enhancement:

Source Code

Repo available here: https://github.com/ducks/node-postgres-exporter

A Side Benefit

Although this started as part of an audition project, I ended up building something I’d absolutely consider productionizing for real-world use cases — and more importantly, something I can showcase as a clean systems-level engineering project.