Push timeseries to Prometheus via remote_write

Using remote_write facility (see https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write) to send metrics to remote Prometheus from NodeJS app.
Pretty much anything from https://prometheus.io/docs/operating/integrations/#remote-endpoints-and-storage should be supported, but tested only with grafana.com:
(List copied from https://github.com/prometheus/docs/blob/main/content/docs/operating/integrations.md)
Usage:
import { pushTimeseries, pushMetrics } from "prometheus-remote-write";
await pushMetrics(
{
queue_depth_total: 100,
},
{
url: process.env.GRAFANA_PUSH_URL || "http://localhost:9201",
labels: { service: "queue-worker" },
}
);
const config = {
url: "http://localhost:9201",
auth: {
username: "...",
password: "...",
},
proto: undefined,
console: undefined,
verbose: false,
timing: false,
fetch: undefined,
labels: undefined
};
await pushTimeseries(
{
labels: {
__name__: "queue_depth_total",
instance: "dev.example.com",
service: "SQS",
},
samples: [
{
value: 150,
timestamp: Date.now(),
},
],
},
config
);
Links