|
| 1 | +# LocalStack Prometheus Metrics |
| 2 | +[](https://app.localstack.cloud/extensions/remote?url=git+https://github.com/localstack/localstack-extensions/#egg=localstack-extension-prometheus-metrics&subdirectory=prometheus) |
| 3 | + |
| 4 | +Instruments, collects, and exposes LocalStack metrics via a [Prometheus](https://prometheus.io/) endpoint. |
| 5 | + |
| 6 | +## Installing |
| 7 | + |
| 8 | +```bash |
| 9 | +localstack extensions install localstack-extension-prometheus-metrics |
| 10 | +``` |
| 11 | + |
| 12 | +**Note**: This plugin only supports LocalStack `>=v4.2` |
| 13 | + |
| 14 | +## Usage |
| 15 | + |
| 16 | +Scrape metrics via the endpoint: |
| 17 | +```bash |
| 18 | +curl localhost.localstack.cloud:4566/_extension/metrics |
| 19 | +``` |
| 20 | + |
| 21 | +## Quickstart (Docker-Compose) |
| 22 | + |
| 23 | +See the documentation on [Automating extension installation](https://docs.localstack.cloud/user-guide/extensions/managing-extensions/#automating-extensions-installation) for more details. |
| 24 | + |
| 25 | +First, enable the extension by adding it to your LocalStack environment: |
| 26 | + |
| 27 | +```yaml |
| 28 | +services: |
| 29 | + localstack: |
| 30 | + environment: |
| 31 | + - EXTENSION_AUTO_INSTALL=localstack-extension-prometheus-metrics |
| 32 | +``` |
| 33 | +
|
| 34 | +Next, you'll need to spin up a Prometheus instance to run alongside your LocalStack container. A [configuration file](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#configuration-file) is required. |
| 35 | +
|
| 36 | +### Option 1: Using a Volume Mount (Recommended) |
| 37 | +
|
| 38 | +Create `prometheus_config.yml`: |
| 39 | +```yaml |
| 40 | +global: |
| 41 | + scrape_interval: 15s # Set the scrape interval to every 15 seconds |
| 42 | + scrape_timeout: 5s # Set the scrape request timeout to 5 seconds |
| 43 | +# Scrape configuration for LocalStack metrics |
| 44 | +scrape_configs: |
| 45 | + - job_name: 'localstack' |
| 46 | + static_configs: |
| 47 | + # Note: The target needs to match the LocalStack container name for the Prometheus container to resolve the endpoint. |
| 48 | + - targets: ['localstack:4566'] # Target the LocalStack Gateway. |
| 49 | + metrics_path: '/_extension/metrics' # Metrics are exposed via `/_extension/metrics` endpoint |
| 50 | +``` |
| 51 | + |
| 52 | +And mount it on startup in your `docker-compose.yml`: |
| 53 | +```yaml |
| 54 | +services: |
| 55 | + # ... LocalStack container should be defined |
| 56 | + prometheus: |
| 57 | + image: prom/prometheus |
| 58 | + ports: |
| 59 | + - "9090:9090" |
| 60 | + volumes: |
| 61 | + - "./prometheus_config.yml:/etc/prometheus/prometheus.yml" |
| 62 | +``` |
| 63 | +
|
| 64 | +### Option 2: Inline Configuration |
| 65 | +
|
| 66 | +Using the Docker Compose top-level [configs](https://docs.docker.com/reference/compose-file/configs/): |
| 67 | +```yaml |
| 68 | +services: |
| 69 | + prometheus: |
| 70 | + image: prom/prometheus |
| 71 | + ports: |
| 72 | + - "9090:9090" |
| 73 | + configs: |
| 74 | + - source: prometheus_config |
| 75 | + target: /etc/prometheus/prometheus.yml |
| 76 | + |
| 77 | +configs: |
| 78 | + prometheus_config: |
| 79 | + content: | |
| 80 | + global: |
| 81 | + scrape_interval: 15s |
| 82 | + scrape_timeout: 5s |
| 83 | + scrape_configs: |
| 84 | + - job_name: 'localstack' |
| 85 | + static_configs: |
| 86 | + - targets: ['localstack:4566'] |
| 87 | + metrics_path: '/_extension/metrics' |
| 88 | +``` |
| 89 | +
|
| 90 | +### Full Example |
| 91 | +
|
| 92 | +```yaml |
| 93 | +services: |
| 94 | + localstack: |
| 95 | + container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}" |
| 96 | + image: localstack/localstack-pro # required for Pro |
| 97 | + ports: |
| 98 | + - "4566:4566" # LocalStack Gateway |
| 99 | + - "4510-4559:4510-4559" # external services port range |
| 100 | + - "443:443" # LocalStack HTTPS Gateway (Pro) |
| 101 | + environment: |
| 102 | + - LOCALSTACK_AUTH_TOKEN=${LOCALSTACK_AUTH_TOKEN:?} # required for Pro |
| 103 | + - DEBUG=${DEBUG:-0} |
| 104 | + - PERSISTENCE=${PERSISTENCE:-0} |
| 105 | + - EXTENSION_AUTO_INSTALL=localstack-extension-prometheus-metrics |
| 106 | + volumes: |
| 107 | + - "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack" |
| 108 | + - "/var/run/docker.sock:/var/run/docker.sock" |
| 109 | + |
| 110 | + prometheus: |
| 111 | + image: prom/prometheus |
| 112 | + ports: |
| 113 | + - "9090:9090" |
| 114 | + volumes: |
| 115 | + - "./prometheus_config.yml:/etc/prometheus/prometheus.yml" # Assumes prometheus_config.yml exists in your CWD |
| 116 | +``` |
| 117 | +
|
| 118 | +## Available Metrics |
| 119 | +
|
| 120 | +The Prometheus extension exposes various LocalStack metrics through the `/_extension/metrics` endpoint, including: |
| 121 | +- Request counts by service |
| 122 | +- Request latencies |
| 123 | +- Resource utilization |
| 124 | +- Error rates |
| 125 | + |
| 126 | +For a complete list of available metrics, visit the endpoint directly at `localhost.localstack.cloud:4566/_extension/metrics` when LocalStack is running. |
| 127 | + |
| 128 | +## Licensing |
| 129 | + |
| 130 | +* [client_python](https://github.com/prometheus/client_python) is licensed under the Apache License version 2. |
0 commit comments