# SpectraDetect Prometheus Metrics API — GET /metrics and honor_labels Setup

> Scrape Spectra Detect appliance health and performance metrics via GET /metrics with Prometheus, using honor_labels: true to preserve job labels and avoid collisions.

The Metrics API provides an interface for collecting Prometheus-compatible metrics from Spectra Detect appliances.

Users can scrape this endpoint to monitor the health and performance of the appliance.

## Prometheus `honor_labels` Configuration

When configuring your Prometheus server to scrape metrics from Spectra Detect appliances, we recommend enabling the `honor_labels` setting in your Prometheus scrape configuration.

By default, Prometheus renames conflicting labels scraped from targets to avoid collisions with its own internally generated labels (like `instance` and `job`). For example, a target's `job` label might be renamed to `exported_job`. However, Spectra Detect provides certain labels (e.g., `job`) within its exposed metrics that are essential for proper identification and data filtering.

Setting `honor_labels: true` in your Prometheus scrape configuration for Spectra Detect targets will instruct Prometheus to preserve the original label names exposed by the appliance.

Here's an example of a Prometheus scrape configuration snippet with `honor_labels` enabled:

```yaml
scrape_configs:
  - job_name: 'spectra-detect'
    honor_labels: true
    static_configs:
      - targets: ['<host>:<port>']
```

## Metrics API response status codes

- 200
  - The request has succeeded.
- 404
  - The server has not found anything matching the Request-URI.
- 500
  - The server encountered an unexpected condition which prevented it from fulfilling the request.
- 503
  - The server is currently unable to handle the request due to a temporary overloading or maintenance of the server.

## Get Prometheus metrics

```
GET /metrics
```

### Description

Returns the current system and application metrics in a Prometheus-compatible format. This endpoint can be scraped by a Prometheus server to collect data about the appliance.

### Request format

**Request examples**

```bash
curl -X GET https://<host>/metrics
```

```python

url = "https://<host>/metrics"

response = requests.request("GET", url)

print(response.text)
```

### Response format

A successful request returns the `200 OK` status code with the metrics in the Prometheus exposition format in the response body.

Each appliance returns metrics specific to the services it hosts. All appliances expose `node_*` metrics. Specifically, Hub appliances only provide `node_*` metrics. Manager appliances expose `node_*` and `rabbitmq_*` metrics. Worker appliances provide `node_*`, `rabbitmq_*`, and `rl_*` metrics.

### Aggregating metrics per appliance

While the metrics endpoint exposes raw metrics for each internal service (e.g., `job="postprocessor"`, `job="receiver"`), individual service metrics may show a value of 0. To view meaningful metrics for a particular appliance, aggregate the metrics across all services on that appliance using the `sum()` function in your Prometheus queries.

For example, to get the total processed bytes for a Worker appliance:

```promql
sum(rl_processed_bytes_total{instance="10.200.185.215"})
```

Replace `10.200.185.215` with the IP address of the target appliance.

**Response examples**

```
node_memory_Mapped_bytes{job="node"} 4.29580288e+08
node_network_receive_compressed_total{device="ens192",job="node"} 0
node_network_receive_compressed_total{device="lo",job="node"} 0
node_disk_writes_merged_total{device="dm-0",job="node"} 0
node_disk_writes_merged_total{device="dm-1",job="node"} 0
node_disk_writes_merged_total{device="sda",job="node"} 87857
node_disk_writes_merged_total{device="sr0",job="node"} 0
node_disk_writes_merged_total{device="sr1",job="node"} 0
rabbitmq_detailed_queue_messages_ready{vhost="rl-detect",queue="tiscale.hagent_retry",job="rabbitmq"} 0
rabbitmq_detailed_queue_messages_ready{vhost="rl-detect",queue="tiscale.hagent_error",job="rabbitmq"} 0
rabbitmq_detailed_queue_messages_ready{vhost="rl-detect",queue="tiscale.hagent_input",job="rabbitmq"} 0
rabbitmq_detailed_queue_messages_ready{vhost="rl-detect",queue="tiscale.hagent_url",job="rabbitmq"} 0
rabbitmq_detailed_queue_messages_ready{vhost="rl-detect",queue="tiscale.hagent_result",job="rabbitmq"} 0
rl_processed_bytes_total{job="postprocessor"} 0
rl_processed_files_total{job="postprocessor"} 0
rl_submitted_bytes_total{job="postprocessor"} 0
rl_submitted_files_total{job="postprocessor"} 0
rl_unpacked_bytes_total{job="postprocessor"} 0
rl_unpacked_files_total{job="postprocessor"} 0
rl_processed_bytes_total{job="receiver"} 0
rl_processed_files_total{job="receiver"} 0
rl_submitted_bytes_total{job="receiver"} 0
rl_submitted_files_total{job="receiver"} 0
rl_unpacked_bytes_total{job="receiver"} 0
rl_unpacked_files_total{job="receiver"} 0
```
