Skip to content

lawrenceching/metricdump

Repository files navigation

metricdump

A tool to save Prometheus metrics into SVC/PNG.
For experimental purpose, metricdump supports to render SVG by JSDom, render PNG by node-canvas, and SVG, PNG and HTML by Chromium.

Given that the underlying chart library is Apache Echart, a library for browser, using Chromium and rendering backend will output the best quality PNG.
You can see the images in https://github.com/lawrenceching/metricdump/tree/main/example generated by different backends.

Example - Node CPU Usage

Renderer Backend Output
SVG JSDom .svg
Canvas node-canvas .svg
SVG Chromium .svg & .html
Canvas Chromium .png & .html

Get Started

From Command Line

Node.js 16

  • Please note that Node.js 17 is not currently supported
git clone https://github.com/lawrenceching/metricdump.git
npm install

# Or if you're in China
npm install --registry=https://registry.npmmirror.com
Options:
  -V, --version                output the version number
  --since <since>              Record metric since last XXX s/m/h/d (seconds/minutes/hours/days), default in seconds
  --start <time>               Record metric started from the given time, in format yyyy-MM-ddThh:mm:ss
  --end <time>                 Record metric end at the given time, in format yyyy-MM-ddThh:mm:ss
  --width <px>                 The width of the generated SVG or PNG file (default: "1024")
  --height <px>                The height of the generated SVG or PNG file (default: "600")
  --backend <title>            Backend of renderer. Supports node-canvas or chromium
  --title <title>              The title of graph
  --output <title>             The output SVG/PNG file path (default: "./output")
  --renderer <title>           The renderer, svg or canvas (default: "canvas")
  --step <step>                The step for query Prometheus metric
  --promql <query>             The PromQL to query
  --unit <unit>                The unit for the metric.
  --showLegend <boolean>       Display legend
  --headless <headless>        Launch Chromium in headless mode or not
  --metrics <yaml1,yaml2,...>  List of paths to the metric file which defined a series of metrics need to be recorded
  --prometheus <url>           The url to Prometheus (default: "http://localhost:9090")
  -h, --help                   display help for command
Save one metric as SVG
node src/main.js \
  --promql 'sum(rate(prometheus_notifications_latency_seconds_sum[5m]))/sum(rate(prometheus_notifications_latency_seconds_count[5m]))' \
  --unit second \
  --prometheus https://prometheus.demo.do.prometheus.io \
  --since 1h \
  --renderer svg \
  --output ./example
Save series of metrics as SVG
node src/main.js \
  --metrics ./example/metrics-http.yaml \
  --prometheus https://prometheus.demo.do.prometheus.io \
  --since 7d \
  --renderer svg \
  --output ./example

From Docker

# Run metricdump container to save metrics, files will be stored at /tmp/metrics inside the container
docker run \
  --name metricdump \
  --mount type=bind,source="$(pwd)"/example/metrics-http.yaml,target=/etc/prometheus-snaphost/metrics-http.yaml,readonly \
  -e DEBUG="main" \
  -e PROMETHEUS=https://prometheus.demo.do.prometheus.io \
  -e START="2022-01-01T00:00:00" \
  -e END="2022-01-02T10:30:00" \
  metricdump

# Get container id
ID=$(docker container ls -all  | grep metricdump | cut -d ' ' -f 1)

# Copy files out from container
docker cp $ID:/tmp/metrics ./

# Remove container
docker container rm $ID

Releases

No releases published

Packages

No packages published

Languages