# Install and use metrics with Prometheus and Grafana ## Install metrics agents Install Prometheus, Prometheus Pushgateway and Grafana. Put them behind NGINX reverse proxy, get a TLS certificate, and run the service on startup with systemd. Do a replace all of prometheus-pushgateway.example.com and grafana.example.com with your own domains. ```sh chmod u+x ./install_metrics_agents.sh sudo ./install_metrics_agents.sh ``` ## Configure Grafana dashboard Go to https://grafana.example.com, log in with `admin:admin` and set your new secure password. In `Connections` > `Data sources`, Select `Prometheus`. In the host field, enter `http://localhost:9090`, and save. It should say that the connection was succesful. ## Push some metrics in Node.js Install required dependencies ```sh pnpm i prom-client ``` In the entrypoint of your Node.js project, simply import [metrics.mjs](#file-metrics-mjs). Pass the host where your Prometheus Pushgateway is deployed with `PROMETHEUS_GATEWAY_ENDPOINT=https://prometheus-pushgateway.example.com`. To increment the counter metric named `my_metric`, simply call: ```js MetricsUtils.my_metric.inc() ``` Check the [`prom-client`](https://github.com/siimon/prom-client/) repository for further documentation.