Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ryotarai/prometheus-query
CLI client to query Prometheus
https://github.com/ryotarai/prometheus-query
Last synced: 2 months ago
JSON representation
CLI client to query Prometheus
- Host: GitHub
- URL: https://github.com/ryotarai/prometheus-query
- Owner: ryotarai
- Created: 2017-08-02T08:44:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-09T10:16:48.000Z (about 6 years ago)
- Last Synced: 2024-10-06T03:50:23.741Z (3 months ago)
- Language: Go
- Size: 5.86 KB
- Stars: 40
- Watchers: 2
- Forks: 17
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# prometheus-query
CLI client to query Prometheus
## Installation
```
$ go get -u github.com/ryotarai/prometheus-query
```## Usage
```
Usage of prometheus-query:
-end string
End time (default "now")
-format string
Format (available formats are json, tsv and csv) (default "json")
-query string
Query
-server string
Prometheus server URL like 'https://prometheus.example.com' (can be set by PROMETHEUS_SERVER environment variable) (default "")
-start string
Start time (default "1 hour ago")
-step string
Step (default "15s")
``````
$ PROMETHEUS_SERVER="http://your-prometheus.example.com"
$ QUERY="100 * (1 - avg by(instance_type, availability_zone)(irate(node_cpu{mode='idle'}[5m])))"
```Output format defaults to JSON:
```
$ prometheus-query -query "$QUERY" | jq .
[
{
"time": 1501662831,
"values": [
{
"metric": {
"availability_zone": "ap-northeast-1b",
"instance_type": "c3.2xlarge"
},
"value": 33.65555555557196
},
{
"metric": {
"availability_zone": "ap-northeast-1b",
"instance_type": "c3.4xlarge"
},
"value": 32.32500000000012
},
...
```CSV and TSV formatters are available:
```
$ prometheus-query -query "$QUERY" -format csv
time,availability_zone:ap-northeast-1b|instance_type:c3.2xlarge,availability_zone:ap-northeast-1b|instance_type:c3.4xlarge
1501662920,36.910185,26.927778
1501662935,34.331481,27.270139
...
```Query range can be specified by `-start` and `-end` options and they are parsed by https://github.com/ymotongpoo/datemaki .
Start time defaults to 1 hour ago and end time defaults to now:```
$ prometheus-query -query "$QUERY" -start-time '2 day ago' -end-time '1 day ago'
```