Plot Prometheus time series and predict_linear-style extrapolation (linear regression). The CLI can fetch from a live Prometheus instance or plot from saved query_range JSON.
Prerequisites: Go 1.17+ (install).
go mod downloadThe entry point is cmd/main.go. Run with go run ./cmd (or build with go build -o promml ./cmd).
You need a Prometheus server with data (e.g. scraping metrics). Then:
# Plot a query (default: last 60 minutes, output graph.png)
go run ./cmd -prom http://localhost:9090 -query 'up' -out up.png
# Custom time range and step
go run ./cmd -prom http://localhost:9090 -query 'node_filesystem_free_bytes{device="/dev/vda1"}' \
-step 5m -minutes 120 -out disk.png
# Add 12h/24h predict_linear extrapolation
go run ./cmd -prom http://localhost:9090 -query 'node_filesystem_free_bytes{device="/dev/vda1"}' \
-step 5m -minutes 120 -predict -out disk.png
# Explicit start/end (RFC3339)
go run ./cmd -prom http://localhost:9090 -query 'up' \
-start '2025-01-01T00:00:00Z' -end '2025-01-01T12:00:00Z' -step 15s -out range.pngFlags (Prometheus mode):
| Flag | Description |
|---|---|
-prom |
Prometheus base URL (required for live fetch). |
-query |
PromQL query (required with -prom). |
-out |
Output PNG path (default: graph.png). |
-step |
Step duration, e.g. 15s, 5m (default: 15s). |
-minutes |
Last N minutes when -start/-end omitted (default: 60). |
-start |
Start time (RFC3339). |
-end |
End time (RFC3339). |
-predict |
Add 12h and 24h prediction lines to the plot. |
Quick way to get a Prometheus to point the CLI at:
# Create a minimal config (optional: add scrape configs for your targets)
mkdir -p prometheus
echo 'global: { scrape_interval: 15s }
scrape_configs:
- job_name: prometheus
static_configs: [{ targets: [localhost:9090] }]' > prometheus/prometheus.yml
# Run Prometheus (data in ./prometheus/data)
docker run --rm -d -p 9090:9090 \
-v "$(pwd)/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml" \
-v "$(pwd)/prometheus/data:/prometheus" \
--name prometheus prom/prometheus:latestThen use -prom http://localhost:9090 (or http://host.docker.internal:9090 from another container). To stop: docker stop prometheus.
The repo includes Prometheus query_range-style JSON files (e.g. scenario1_slow_leak.json). You can plot them without a running Prometheus:
# Plot raw series (output: scenario1_slow_leak.png)
go run ./cmd -json scenario1_slow_leak.json
# Custom output path
go run ./cmd -json scenario1_slow_leak.json -out my_plot.png
# Plot with 12h and 24h predict_linear extrapolation
go run ./cmd -json scenario1_slow_leak.json -predict
# All scenario examples with prediction lines
go run ./cmd -json scenario1_slow_leak.json -predict
go run ./cmd -json scenario2_burst_recovery.json -predict
go run ./cmd -json scenario3_runaway_fill.json -predict
go run ./cmd -json scenario4_sawtooth_cleanup.json -predict
go run ./cmd -json scenario5_false_safety.json -predictFlags (JSON mode):
| Flag | Description |
|---|---|
-json |
Path to a Prometheus query_range JSON file (required if -prom not set). |
-out |
Output PNG path (default: <json basename>.png). |
-predict |
Run linear regression and add 12h/24h prediction lines. |
JSON files must match the Prometheus /api/v1/query_range response shape: data.result[].values as [[timestamp_seconds, "value"], ...].
go run ./cmdPrints usage, flags, and examples when no -prom or -json is given.
Prerequisites for running the Go notebooks:
- Go (1.17 or later). Install from go.dev.
- Jupyter. Install via pip:
pip install jupyterorpip install jupyterlabfor JupyterLab.
Ensure $GOPATH/bin (or $GOBIN if set) is in your PATH so Go-installed binaries are found.
pip install jupyterOr for JupyterLab:
pip install jupyterlabInstall the GoNB kernel plus goimports and gopls (for auto-complete and import handling):
go install github.com/janpfeifer/gonb@latest && \
go install golang.org/x/tools/cmd/goimports@latest && \
go install golang.org/x/tools/gopls@latestgonb --installIf gonb is not in your PATH, run it from $GOPATH/bin or $HOME/go/bin:
$HOME/go/bin/gonb --installFrom the project root:
go mod downloadStart Jupyter from the project directory:
jupyter notebook --no-browserOr with JupyterLab:
jupyter lab --no-browserCopy the URL printed in the terminal (e.g. http://localhost:8888/tree?token=...) into your browser.
- Open an existing notebook or create a new one.
- For new notebooks, choose "Go (gonb)" as the kernel (Kernel → Change kernel → Go (gonb)).
- Use
import "github.com/opeonikute/promml"to import this package in cells.