This script collects and logs performance metrics from an Elasticsearch cluster.
- Supports Basic Auth, Bearer Token, or No Auth
- Select specific diagnostics to run
- Outputs in either pretty
.logor structured.json
./es_diagnostics.sh --env config/dev.env./es_diagnostics.sh --env config/prod.env --run health,nodes,statsES_USER+ES_PASS→ Basic AuthAUTH_TOKEN→ Bearer Token- None → No Auth
Set in .env:
MODE=pretty→ Human-readableMODE=json→ Structured machine-friendly format
macOS ships with Bash 3.2 which lacks features required for JSON mode. To fix:
brew install bashUpdate script shebang to:
#!/usr/local/bin/bashES_HOST=http://localhost:9200
ES_USER=elastic
ES_PASS=changeme
MODE=prettyES_HOST=https://your-prod-es.example.com
AUTH_TOKEN=your-token-here
MODE=jsonUse the --run flag to selectively execute checks. Below is a list of available modes:
| Tag | Description | Elasticsearch Endpoint |
|---|---|---|
health |
Cluster health status | /_cluster/health |
stats |
Cluster-wide statistics | /_cluster/stats |
nodes |
Node-level JVM, CPU, FS stats | /_nodes/stats/jvm,os,process,fs,indices |
pending |
Cluster pending tasks | /_cluster/pending_tasks |
indexstats |
Index stats (docs, store, etc.) | /_stats |
shards |
Shard allocation details | /_cat/shards?format=json |
indices |
Index summary information | /_cat/indices?format=json |
catnodes |
Node summary (cat API) | /_cat/nodes?format=json |
threadpool |
Thread pool metrics per node | /_nodes/stats/thread_pool |
./es_diagnostics.sh --env config/prod.env --run health,stats,threadpool./es_diagnostics.sh -h
Usage: ./es_diagnostics.sh [--env FILE] [--run TAG1,TAG2,...]
Options:
--env FILE Path to .env file with configuration variables.
--run TAGS Comma-separated list of diagnostic checks to run.
Available TAGS: health, stats, nodes, pending, indexstats, shards, indices, catnodes, threadpool
-h, --help Display this help message.
Examples:
./es_diagnostics.sh --env dev.env
./es_diagnostics.sh --env prod.env --run health,nodes