Last active
May 17, 2021 15:05
-
-
Save dln/11a98735c9a2a2849dfa6b9bc57a03d8 to your computer and use it in GitHub Desktop.
Run a local prometheus with short scraping interval for development purposes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| datadir=$1 | |
| app_port=$2 | |
| metrics_path=${3:-/metrics} | |
| if [[ -z "$datadir" || -z "$app_port" ]]; then | |
| echo "Usage: $0 DATADIR APPLICATION_PORT [METRICS_PATH]" | |
| exit 1 | |
| fi | |
| mkdir -p $datadir/data | |
| cat >$datadir/prometheus.yml <<EOF | |
| global: | |
| evaluation_interval: 5s | |
| scrape_interval: 1s | |
| scrape_timeout: 1s | |
| scrape_configs: | |
| - job_name: my-application | |
| metrics_path: ${metrics_path} | |
| static_configs: | |
| - targets: | |
| - host.docker.internal:${app_port} | |
| EOF | |
| if [[ "$OSTYPE" == "linux-gnu"* ]]; then | |
| EXTRA_ARGS="--add-host=host.docker.internal:127.0.0.1" | |
| fi | |
| DOCKER=docker | |
| if command -v "podman"; then | |
| DOCKER=podman | |
| fi | |
| exec $DOCKER run \ | |
| -it \ | |
| --rm \ | |
| --publish 9090:9090 \ | |
| --volume $datadir:/etc/prometheus \ | |
| --volume $datadir/data:/prometheus \ | |
| --user root \ | |
| $EXTRA_ARGS \ | |
| prom/prometheus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment