Prometheus can make a Go job scraper’s behavior visible over time—but only if its metrics answer operational questions. The basic setup is a Go application that exposes a /metrics endpoint, plus a Prometheus server configured to scrape it. From there, the important work is choosing measures that show whether jobs complete, how often they fail, how long they take, and when success last occurred.
How Prometheus collects metrics from a Go application
The collection chain has three parts: application code updates metrics, an HTTP endpoint exposes their current values, and Prometheus periodically requests that endpoint according to its scrape configuration. The configured job name is added as a job label to the collected time series. This is pull monitoring: Prometheus must be able to discover and reach the target.
Prometheus’s Go application guide describes the required /metrics endpoint and walks through a Go client setup. Its example uses localhost:2112 and a 10-second scrape interval; those are tutorial values, not production defaults.
Expose a metrics endpoint in Go
Install the Prometheus Go client packages used by the official guide:
#1 Best Overall
go get github.com/prometheus/client_golang/prometheus
A minimal setup creates a registry, registers Go and process collectors, and serves that registry with promhttp:
package main
import (
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/collectors"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
registry := prometheus.NewRegistry()
registry.MustRegister(
collectors.NewGoCollector(),
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
)
http.Handle("/metrics", promhttp.HandlerFor(registry, promhttp.HandlerOpts{}))
log.Fatal(http.ListenAndServe(":2112", nil))
}
This example serves metrics on port 2112; choose an address and exposure policy appropriate to the deployment. A dedicated registry makes it clear which collectors the endpoint serves. For custom metrics, register them with that same registry or use the client’s default registry and corresponding handler, rather than unintentionally splitting metrics across registries. See the official Go guide and client_golang documentation for the client’s current API and complete example.
Choose metrics that answer scraper questions
Runtime and process collectors can show what the Go process is doing, but they do not establish whether the scraper is doing its job. Add application metrics only for quantities the implementation actually tracks. Prometheus’s Go client instrumentation documentation describes counters, gauges, and histograms; for a job scraper, they can map to operational questions like these:
Rank #2
| Question | Possible metric | Type and interpretation |
|---|---|---|
| Is work completing, and how much? | scraper_jobs_completed_total or scraper_records_processed_total |
Counter: cumulative completed jobs or processed records. |
| Are outcomes changing? | scraper_jobs_completed_total{outcome="success"} and a small, fixed set of outcome values |
Counter partitioned by a bounded outcome label. |
| How long do jobs or stages take? | scraper_job_duration_seconds |
Histogram: observations of job duration, suitable for analyzing distributions. |
| How much work is active or waiting now? | scraper_jobs_in_progress or scraper_queue_depth |
Gauge: a value that can rise and fall with current state. |
| When did a successful run last happen? | scraper_last_success_timestamp_seconds |
Unix timestamp of the event; calculate its age in PromQL instead of updating a “time since success” gauge. |
These are design examples, not metrics known to exist in any particular scraper. Use names and units that describe the measured quantity, and keep units explicit in names where relevant; Prometheus’s naming guidance covers conventions.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Keep labels bounded to control time-series growth
Each distinct combination of metric name and label values creates a separate time series. A label such as outcome with a handful of fixed values can be useful. Labels containing user IDs, email addresses, raw URLs, or other values that can vary without limit can create a large number of series, increasing Prometheus RAM, CPU, disk, and network costs.
Prometheus’s instrumentation guidance recommends keeping cardinality below 10 for most metrics as a rule of thumb. If a metric’s cardinality exceeds 100—or could grow that large—it advises investigating alternatives, such as reducing dimensions or moving the analysis to a general-purpose processing system. These are documentation guidelines, not capacity guarantees for every deployment.
Rank #3
Measure time since success from an event timestamp
When the question is “How long since the last successful run?”, export the Unix timestamp when that event occurred. Prometheus documents calculating elapsed time as time() - my_timestamp_metric. Applied to a scraper metric named scraper_last_success_timestamp_seconds, the expression is:
time() - scraper_last_success_timestamp_seconds
This avoids maintaining a gauge that must be continuously updated just to represent elapsed time. The timestamp should change when a success occurs, not on every scrape or timer tick.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallConfigure Prometheus to scrape the endpoint
Add the application endpoint to Prometheus’s scrape configuration. For example, if the Go process is reachable from Prometheus at scraper:2112:
Rank #4
scrape_configs:
- job_name: "go-job-scraper"
static_configs:
- targets: ["scraper:2112"]
The target name must resolve and be reachable from the Prometheus server in the actual deployment; localhost in a Prometheus configuration refers to the Prometheus host or container, not automatically to a separate application container. The official getting-started guide explains scrape jobs and targets. After configuring a target, check Prometheus’s target status and confirm that the endpoint returns metrics in the expected format.
Choose collection based on how the job runs
A scraper that runs continuously and can serve HTTP fits Prometheus’s pull model: keep its metrics endpoint available so Prometheus can scrape it. For batch jobs lasting more than a few minutes, Prometheus’s instrumentation guidance says pull-based monitoring can be useful. A short-lived process may finish before a scrape reaches it, so the execution model matters as much as the metric code.
The client_golang project documentation also describes exporting through an OpenTelemetry bridge using OTLP when a job cannot expose an endpoint and pull collection is unavailable. That is an additional integration path, not a reason to assume every one-off job needs a metrics push mechanism.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Check operational reachability and instrumentation cost
- Reachability: Prometheus needs network access to the target endpoint. Verify name resolution, routing, port access, and scrape status in the deployed environment.
- Exposure: Decide which networks can access
/metrics. The example endpoint does not establish a particular project’s security or network setup. - Hot paths: Prometheus says instrumentation overhead is generally outweighed by its operational benefits, but advises care in very hot inner loops and benchmarking when performance is critical. There is no measured overhead established for a particular scraper here.
- Signal quality: Prefer a small set of metrics tied to decisions—such as detecting stalled work or rising failures—over exporting every value simply because it is available.
What the metrics can—and cannot—tell you
A counter, histogram, gauge, and last-success timestamp can help an operator see work volume, outcomes, duration, current state, and recency. That evidence can support investigation and operational decisions. It does not, by itself, prove reliability: the metrics must reflect the real workflow, the endpoint must be scraped successfully, and the signals must be interpreted in the context of the application.
Quick Recap
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.

