Created
February 19, 2020 17:23
-
-
Save petdance/d3dc8d1b923b1d572063800187800051 to your computer and use it in GitHub Desktop.
Solr stats exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SOLRJOB=$1 | |
SOLRHOST=$2 | |
if [[ $SOLRJOB == "" || $SOLRHOST == "" ]] ; then | |
echo 'Usage: solr-exporter.sh SOLRJOB SOLRHOST' | |
echo ' Ex: solr-exporter.sh solrdev volley.flr.follett.com' | |
exit 1 | |
fi | |
DIR="/var/lib/node_exporter/textfiles" | |
FILE="$DIR/solr-$SOLRJOB.prom" | |
TMPFILE="$FILE.$$" | |
JSON="/tmp/solr-exporter-$$.json" | |
URL="http://$SOLRHOST:8080/solr/admin/cores?wt=json" | |
function dump_metric() { | |
declare -r field="$1" | |
declare -r metric="$2" | |
declare -r type="$3" | |
declare -r desc="$4" | |
declare -r core='twit' | |
declare -r jqpath=".status.${core}.index" | |
echo "# HELP $metric $desc" | |
echo "# TYPE $metric $type" | |
N=$(jq "$jqpath.$field" "$JSON" | sed -e's/"//g') | |
echo "$metric{core=\"$core\",solrjob=\"$SOLRJOB\"} $N" | |
return | |
} | |
curl --silent --output "$JSON" "$URL" | |
if [ $? != 0 ] ; then | |
echo "Failed to connect to $URL" | |
exit 1 | |
fi | |
{ | |
dump_metric \ | |
maxDoc \ | |
solr_core_documents_max \ | |
gauge \ | |
'Max number of documents in the core' | |
dump_metric \ | |
numDocs \ | |
solr_core_documents_total \ | |
gauge \ | |
'Total number of documents in the core' | |
dump_metric \ | |
deletedDocs \ | |
solr_core_documents_deleted \ | |
gauge \ | |
'Number of deleted documents' | |
dump_metric \ | |
segmentCount \ | |
solr_core_segments \ | |
gauge \ | |
'Number of segments in the core' | |
dump_metric \ | |
sizeInBytes \ | |
solr_core_bytes \ | |
gauge \ | |
'Number of bytes in the core' | |
} >> "$TMPFILE" | |
# Rename the temporary file atomically. | |
mv "$TMPFILE" "$FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment