Using CheatSheets To Apply Best Practices

JQ CheatSheet

JQ CheatSheet

1.1 jq basic usage

Name Command
jq remove double-quotes Use the -r option to emit raw strings. jq -r ...
curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries'

curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries | .docs, .merges, .segments'

curl $es_ip:9200/$index_name/_stats?pretty | jq '.[0] | ._all: promaries}'

curl $es_ip:9200/$index_name/_stats?pretty | jq '[]'

curl $es_ip:9200/$index_name/_stats?pretty | jq '[], ._all.primaries.segments[]'

curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries[]' | jq '.docs'

1.2 jq with watch

watch -n 0.5 "kubectl get configmaps map1 -o json | jq '.data[\"file1.conf\"]'"

watch "curl $es_ip:9200/$index_name/_stats?pretty | jq '._all.primaries | .docs, .merges, .segments'"

1.3 k8s jq

# List pods and containers
kubectl get pods -o=',CONTAINERS:.spec.containers[*].name'

# List pods, containers and images
kubectl get pods -o=',CONTAINERS:.spec.containers[*].name,Images:.spec.containers[*].image'

1.4 More Resources

License: Code is licensed under MIT License.


Leave a Reply

Your email address will not be published. Required fields are marked *