The components required for the complete Prometheus system are available in the solution bundle but are not active by default.
If required, these components must be enabled.

## Enable Prometheus Metrics

To enable Prometheus metrics, SSH into the receiver and execute the `configure_prometheus.sh enable` command, specifying the following parameters:

- `--username <string>`: defines the username for the endpoint of the Grafana instance.
- `--password <string>`: defines the password for the endpoint of the Grafana instance.
- `--remoteurl <string>`: defines the URL for the endpoint of the Grafana instance.
- `--env <string>`: defines the name of the node/machine. If not specified, the hostname is used.
- `--zone <string>`: defines the location zone for the node/machine.

This step will need to be repeated after upgrading the receiver software.

## Disable Prometheus Metrics

Disabling the Prometheus system make all the components inactive but still present and allows you to enable it again at a later stage.
To disable Prometheus metrics, execute the `configure_prometheus.sh disable` command.

The following commands are also available:

- `configure_prometheus.sh show-secret`: displays the stored username and password for the Grafana endpoint.
- `configure_prometheus.sh update-secret`: update the stored username and password for the Grafana endpoint.
- `--username <string>`: defines the username for the endpoint of the Grafana instance.
- `--password <string>`: defines the password for the endpoint of the Grafana instance.
- `configure_prometheus.sh show-remoteurl`: displays the stored URL for the endpoint of the Grafana instance.

If any of the `remoteurl`, `env` or `zone` parameters need to be updated after Prometheus has been enabled, Prometheus must be disabled first. Then enable Prometheus again, passing in the updated parameter values.
Please refer to the respective documentation for Prometheus and Grafana for information on usage.

## Examples

Replace `<GRAFANA_USER>`, `<GRAFANA_PASSWORD>`, and `<GRAFANA_HOST>` with the values for your Grafana endpoint. The username and password are stored in a Kubernetes secret.

```bash
configure_prometheus.sh enable --username <GRAFANA_USER> --password <GRAFANA_PASSWORD> --remoteurl https://<GRAFANA_HOST>/api/prom/push
```

To disable Prometheus and delete the secret:

```bash
configure_prometheus.sh disable
```

To update the secret without disabling Prometheus:

```bash
configure_prometheus.sh update-secret --username <GRAFANA_USER> --password <GRAFANA_PASSWORD>
```

## Port Conflicts on Startup

There is a small delay in between exposer port assignment and the assigned port being used. On rare occasions, it is possible that a third party grabs that port during that time.
When this happens, metrics are not published as the port cannot be changed. To recover the Prometheus metrics, a service restart (start / stop) is needed, to force a new port to be found.
