Calculate Elasticsearch hit ratio using command-line curl
utility.
Hit ratio for each node
Display request cache hit ratio for each node.
$ curl --silent http://elasticsearch.example.org:9200/_nodes/stats/indices/request_cache | \ jq --raw-output '.nodes[] | "Request cache hit ratio on node \(.name) is \(.indices.request_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%"'
Request cache hit ratio on node elasticsearch01 is 16.5% Request cache hit ratio on node elasticsearch04 is 16.53% Request cache hit ratio on node elasticsearch03 is 16.56% Request cache hit ratio on node elasticsearch05 is 16.57% Request cache hit ratio on node elasticsearch02 is 16.53%
Display query cache hit ratio for each node.
$ curl --silent http://elasticsearch.example.org:9200/_nodes/stats/indices/query_cache | \ jq --raw-output '.nodes[] | "Query cache hit ratio on node \(.name) is \(.indices.query_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%"'
Query cache hit ratio on node elasticsearch03 is 35.52% Query cache hit ratio on node elasticsearch01 is 35.12% Query cache hit ratio on node elasticsearch04 is 35.23% Query cache hit ratio on node elasticsearch02 is 35.19% Query cache hit ratio on node elasticsearch05 is 35.31%
Display request and query cache hit ratio for each node.
$ curl --silent http://elasticsearch.example.org:9200/_nodes/stats/ | \ jq --raw-output '.nodes[] | "Request cache hit ratio on node \(.name) is \(.indices.request_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%, query cache hit ratio is \(.indices.query_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%"'
Request cache hit ratio on node elasticsearch01 is 16.5%, query cache hit ratio is 35.12% Request cache hit ratio on node elasticsearch03 is 16.56%, query cache hit ratio is 35.52% Request cache hit ratio on node elasticsearch05 is 16.57%, query cache hit ratio is 35.31% Request cache hit ratio on node elasticsearch02 is 16.53%, query cache hit ratio is 35.19% Request cache hit ratio on node elasticsearch04 is 16.53%, query cache hit ratio is 35.23%
Display request and query cache hit ratio for a single node.
$ curl --silent http://elasticsearch.example.org:9200/_nodes/elasticsearch03/stats/ | \ jq --raw-output '.nodes[] | "Request cache hit ratio on node \(.name) is \(.indices.request_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%, query cache hit ratio is \(.indices.query_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%"'
Request cache hit ratio on node elasticsearch03 is 16.56%, query cache hit ratio is 35.52%
Hit and miss ratio for each index
Display request cache hit ratio for each index.
$ curl -s http://elasticsearch.example.org:9200/_stats/request_cache | \ jq --raw-output '.indices | keys[] as $k | "Request cache hit ratio for \($k) index is \(.[$k] | .total.request_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%"'
Request cache hit ratio for .elastichq index is 0% Request cache hit ratio for books-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 46.23% Request cache hit ratio for manuals-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 9.04% Request cache hit ratio for bookmarks-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 56.09% Request cache hit ratio for history-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 10.56% Request cache hit ratio for playbook-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 13.44%
Display query cache hit ratio for each index.
$ curl -s http://elasticsearch.example.org:9200/_stats/query_cache | \ jq --raw-output '.indices | keys[] as $k | "Query cache hit ratio for \($k) index is \(.[$k] | .total.query_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%"'
Query cache hit ratio for .elastichq index is 0% Query cache hit ratio for books-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 24.16% Query cache hit ratio for manuals-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 35.94% Query cache hit ratio for bookmarks-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 17.46% Query cache hit ratio for history-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 36.26% Query cache hit ratio for playbook-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 14.07%
Display request and query cache hit ratio for each index.
$ curl -s http://elasticsearch.example.org:9200/_stats/ | \ jq --raw-output '.indices | keys[] as $k | "Request cache hit ratio for \($k) index is \(.[$k] | .total.request_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%, query cache hit ratio is \(.[$k] | .total.query_cache | (.hit_count/(.hit_count + .miss_count + 0.00000001))*10000 | floor/100)%"'
Request cache hit ratio for .elastichq index is 0%, query cache hit ratio is 0% Request cache hit ratio for books-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 46.23%, query cache hit ratio is 24.16% Request cache hit ratio for manuals-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 9.04%, query cache hit ratio is 35.94% Request cache hit ratio for bookmarks-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 56.09%, query cache hit ratio is 17.46% Request cache hit ratio for history-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 10.56%, query cache hit ratio is 36.26% Request cache hit ratio for playbook-27a173b23dc96c94fsg23817aa1cdds9c6b40g22 index is 13.44%, query cache hit ratio is 14.07%
Additional notes
Notice, every time during a division operation, I add a small number in the denominator to prevent division by zero.
jq: error (at <stdin>:0): number (0) and number (0) cannot be divided because the divisor is zero
Remember about that.