October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

Should Your Node.js SaaS Push Metrics or Let Prometheus Scrape Them?

For a continuously running Node.js SaaS service, expose a metrics endpoint and let Prometheus scrape it. Reserve Pushgateway for short-lived job results that must outlive the process.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a continuously running Node.js SaaS API, expose a /metrics endpoint and let Prometheus scrape it. Pull scraping gives you the normal per-target up health signal and lets a target’s metrics follow the target’s lifecycle. Use Pushgateway only for the narrower case of a short-lived service-level batch job whose result must remain available after the process exits.

Pull or push: which fits your workload?

The key distinction is not whether the Node.js client supports pushing—it does—but whether Prometheus can scrape the workload directly and whether the metrics describe a running instance or a completed job.

As an Amazon Associate I earn from qualifying purchases.

Question Pull scraping Pushgateway
What workload fits? A long-running API, worker, or service process. A short-lived job that may finish before Prometheus can scrape it.
What should the metric describe? Per-process or per-instance state and behavior. A service-level job outcome that is independent of one machine or process instance.
How is health observed? Prometheus scrape health and the generated up series help reveal a failed or unreachable target. Pushed metrics do not provide the ordinary per-target scrape health signal.
What happens when the process disappears? The target’s metrics follow its lifecycle. Pushed series remain until explicitly deleted, so cleanup must be managed.
What infrastructure is needed? Prometheus must be able to reach the target endpoint. The job cannot be scraped directly and a reachable gateway must be available.
What extra failure risk is introduced? No additional gateway is needed for the push path. A shared gateway may become a bottleneck or single point of failure.

How to expose custom metrics from a Node.js service

The Prometheus client-library directory lists Node.js as an unofficial third-party client, not an official Prometheus-maintained language client. Its linked Node.js client repository describes the package as @prometheus-io/client, previously published as prom-client. Package names and APIs can change, so check the repository’s current installation and migration guidance when adding or upgrading the dependency.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Install and configure the client. Follow the current package instructions in the client repository.
  2. Define the metrics you need. The client documents custom counters, gauges, histograms, and summaries, along with optional default Node.js runtime metrics.
  3. Serve the registry from an endpoint. In the repository’s example pattern, the handler returns await registry.metrics() in response to a scrape request.
  4. Configure Prometheus to scrape that endpoint. The service should be reachable from the Prometheus server over the network.

The client’s optional runtime metrics include observations such as event-loop lag, active handles, garbage-collection data, and Node.js version. Its README notes that some file-descriptor and memory metrics are Linux-only. For values that should be sampled at scrape time, the client also documents a collect() callback.

Which metrics should a small SaaS API start with?

Request volume, errors, and latency

For an online-serving API, start with request or query count, errors, and latency. In-progress requests may also be useful. Prometheus’s instrumentation guidance recommends aligning count, error, and latency measurements consistently; counting completed queries helps those observations line up.

Choose a metric type for the value

  • Counter: cumulative events that only increase during a process lifetime, such as total requests. A process restart can reset the value.
  • Gauge: a value that can rise or fall, such as the number of requests currently in progress or another point-in-time measurement.
  • Histogram or summary: distributions such as request duration. They are not interchangeable; choose based on the aggregation and percentile behavior your deployment needs.

Use rate() with counters when you need their per-second increase. Do not apply rate() to gauges.

Keep label values bounded

Every distinct combination of label values creates a time series, so labels can multiply the series a metric produces. Prometheus advises: “As a general guideline, try to keep the cardinality of your metrics below 10, and for metrics that exceed that, aim to limit them to a handful across your whole system.” It also recommends investigating alternatives for metrics with cardinality above 100 or that could grow that high. These are guidance thresholds, not performance guarantees.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Avoid unbounded labels such as user IDs and request IDs. Bounded values such as method or status class are more appropriate when they answer a real operational question. If a metric should have a known default before its first event, export that default where appropriate; labeled series generally cannot be exported until their label values are known. The client README also documents explicitly zeroing expected label combinations for histograms.

When Pushgateway is appropriate—and what to manage

Consider Pushgateway when a short-lived service-level batch job exits before Prometheus can scrape it, but its outcome still needs to be available. Useful job metrics can include last success, stage and overall runtime, last completion, and job-level totals. Keep the metric about the job outcome rather than tying it to a transient machine or process instance.

Pushgateway changes the lifecycle responsibilities: pushed series persist until deleted, so the job or an operational cleanup process must remove obsolete data. The shared gateway also becomes another dependency. The Node.js client documents Pushgateway methods such as push, add, and delete; that capability does not make pushing suitable for a long-running API.

If a batch job runs more often than every 15 minutes, Prometheus’s instrumentation guidance gives that frequency as an example of when to consider converting it into a daemon. For machine-related batch-job metrics, the guidance points to the Node Exporter textfile collector rather than Pushgateway.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What if Prometheus cannot reach the service?

Prometheus advises keeping its server on the same network as monitored instances when possible. If firewalls or NAT prevent direct scraping, its guidance suggests moving Prometheus behind the network barrier or considering PushProx. That connectivity problem alone does not make Pushgateway the default for an always-running service; choose a collection approach that preserves clear target health and lifecycle handling where possible.

Prometheus’s FAQ summarizes its general preference carefully: “Overall, we believe that pulling is slightly better than pushing, but it should not be considered a major point when considering a monitoring system.” For a small SaaS service, make the decision around workload lifetime, metric meaning, reachability, and cleanup—not merely the existence of a push method in a client library.

Where dashboards fit

Collection and visualization are separate choices. Prometheus’s FAQ recommends Grafana for production dashboards; it can be an optional visualization layer after Prometheus is collecting the metrics.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.