Skip to content

Instantly share code, notes, and snippets.

@christian-korneck
Created July 30, 2023 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christian-korneck/f6d6cf5ba92636cdcea72b8867a7c36a to your computer and use it in GitHub Desktop.
Save christian-korneck/f6d6cf5ba92636cdcea72b8867a7c36a to your computer and use it in GitHub Desktop.
promtool query examples
# make a query at this point in time
$ promtool query instant http://localhost:9090 '{job=~".+"}'
up{instance="localhost:9090", job="prometheus"} => 1 @[1690724237.225]
go_memstats_alloc_bytes{instance="localhost:9090", job="prometheus"} => 29046776 @[1690724237.225]
...
# query a metric for the time range between two Unix timestamp
$ promtool query range --start 1690724700 --end 1690725307 --step 1m http://localhost:9090 \
'go_memstats_alloc_bytes{job="prometheus"}'
23215032 @[1690724700]
22376536 @[1690724760]
23908120 @[1690724820]
22682864 @[1690724880]
...
# make this more useful with the Unix `date` command
$ promtool query range --start `date -d 'now - 10 minutes' +%s` --end `date +%s` --step 15s \
http://localhost:9090 'go_mem stats_alloc_bytes{job="prometheus"}'
23215032 @[1690724700]
22376536 @[1690724760]
...
# get all known values for the label key "scrape_job"
$ promtool query labels http://localhost:9090 scrape_job
prometheus
holloway
...
# a series query with multiple matches
$ promtool query series http://localhost:9090 --match 'go_memstats_alloc_bytes{job="prometheus"}' \
--match 'up'
{__name__="go_memstats_alloc_bytes", instance="localhost:9090", job="prometheus"}
{__name__="up", instance="localhost:9090", job="prometheus"}
# we can also get json output, which makes `promtool` a nice glue tool :)
$ promtool query --format json instant http://localhost:9090 up | jq
[
{
"metric": {
"__name__": "up",
"instance": "localhost:9090",
"job": "prometheus"
},
"value": [
1690728125.803,
"1"
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment