# Prometheus mirror

## Overview

Prometheus mirror is a gateway between StackState and Prometheus that enables Prometheus telemetry in StackState.

## Prerequisites

The Prometheus Mirror has the following prerequisites:

* The mirror must be reachable from StackState
* Prometheus must be reachable from the mirror **without authentication**

## Helm

The Prometheus mirror is available via the StackState helm repository. Configure your helm with these 2 commands:

```
helm repo add stackstate https://helm.stackstate.io
helm repo update
```

Install the Prometheus mirror with the following command:

```
helm install prometheusmirror stackstate/prometheusmirror --set global.apiKey=API_KEY
```

Alternatively, you can use the Docker container directly:

```
docker pull stackstate/prometheusmirror:latest
```

## Mirror configuration

The Prometheus mirror is configured using the following parameters:

* `global.apiKey` - the API key used to authenticate communication between the mirror and StackState
* `workers` - number of workers processes (default: `20`)
* `port` - the port the mirror is listening on (default: `9900`)

## StackState configuration

In order to start using Prometheus mirror in StackState one has to create Mirror Datasource

### Configure Mirror Datasource

Create a new Mirror datasource:

* **DataSourceUrl** - points to the Prometheus mirror endpoint, for example `http://prometheusmirror.stackstate.svc.cluster.local:9900/`
* **API Key** - should be the same key as specified by `global.apiKey` mirror configuration
* **Connection Details JSON** - the mirror configuration json, for example:

  ```json
    {
      "host": "<prometheus host>",
      "port": <prometheus port>,
      "requestTimeout": 20000
    }
  ```

  Prometheus host/port refers to the actual Prometheus host/port (not the mirror).

## Query Configuration

### Prometheus Counter

Counter queries fetch counter metrics from Prometheus. The retrieved counter values are transformed to a rate.

The following are sample parameters for a counter query:

* \_\_counter\_\_ = go\_memstats\_lookups\_total
* job = payment-service
* name = payment
* instance = 127.0.0.1:80

### Prometheus Gauge

Gauge queries fetch gauge metrics from Prometheus.

The following are sample parameters for a gauge query:

* \_\_gauge\_\_ = go\_gc\_duration\_seconds
* job = payment-service
* name = payment
* instance = 127.0.0.1:80

### Prometheus Histogram and Summary

Prometheus histogram and summary queries are **not** supported from the query interface. They still can be configured using tilda-query.

### Tilde query \~

The query allows arbitrary Prometheus queries, for example:

```
~ = histogram_quantile(0.95, sum(rate(request_duration_seconds_bucket{instance='127.0.0.1:80', name='payment-service'}[1m])) by (name, le)) * 1000
```

## See also

* [Developer guide - mirroring telemetry](/5.1/develop/developer-guides/mirroring.md)
* [Developer tutorial - Set up a mirror to pull telemetry data from an external system](/5.1/develop/tutorials/mirror_tutorial.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://archivedocs.stackstate.com/5.1/configure/telemetry/data-sources/prometheus-mirror.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
