Skip to content

Instantly share code, notes, and snippets.

@c29r3
Last active October 5, 2020 22:42
Show Gist options
  • Save c29r3/ca43c4e08daebbfcdb46779c57ac62b9 to your computer and use it in GitHub Desktop.
Save c29r3/ca43c4e08daebbfcdb46779c57ac62b9 to your computer and use it in GitHub Desktop.
#!/bin/bash
export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
TEXTFILE_COLLECTOR_DIR=/var/lib/node_exporter/textfile_collector
FILENAME=solana_block_production.prom
metrics_prefix=solana_monit_tds
ALL=$(timeout 45 solana block-production 2>&1 | grep -v "Identity Pubkey" | grep -v "using data from" | grep -v ":" | grep . | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | sed -e 's/\s\+/,/g' | sed 's/%//g' )
epoch=$(solana epoch)
EPOCH=$(echo ${metrics_prefix}_epoch ${epoch})
LEADER_SLOTS=$(echo "$ALL" | awk -F, '{print $1,$2}' | sed -ne 's/^\([a-zA-Z0-9]\+\) \(.*\)$/'${metrics_prefix}'_leader_slots{pubkey="\1", epoch="'${epoch}'"} \2/p')
BLOCKS_PRODUCED=$(echo "$ALL" | awk -F, '{print $1,$3}' | sed -ne 's/^\([a-zA-Z0-9]\+\) \(.*\)$/'${metrics_prefix}'_blocks_produced{pubkey="\1", epoch="'${epoch}'"} \2/p')
BLOCKS_SKIPPED=$(echo "$ALL" | awk -F, '{print $1,$4}' | sed -ne 's/^\([a-zA-Z0-9]\+\) \(.*\)$/'${metrics_prefix}'_blocks_skipped{pubkey="\1", epoch="'${epoch}'"} \2/p')
BLOCKS_SKIPPED_PERC=$(echo "$ALL" | awk -F, '{print $1,$5}' | sed -ne 's/^\([a-zA-Z0-9]\+\) \(.*\)$/'${metrics_prefix}'_blocks_skipped_percent{pubkey="\1", epoch="'${epoch}'"} \2/p')
LEDGER_SIZE=$(du -bs $(find $HOME -type d -iname validator-ledger) 2>/dev/null | cut -f1)
CURRENT_CLIENT_VERSION=$(timeout 10 curl -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getVersion"}' http:///localhost:8899 | jq -r '.result."solana-core"' | cut -f1)
LAST_CLIENT_VERSION=$(timeout 10 curl -s -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "method":"getVersion"}' http://testnet.solana.com | jq -r '.result."solana-core"' | cut -f1)
HEALTH_STRING=$(timeout 5 curl --silent http:///localhost:8899/health)
HEALTH_STATUS=0
if [ "$HEALTH_STRING" = "ok" ]; then
HEALTH_STATUS=1
fi
cat << EOF > "$TEXTFILE_COLLECTOR_DIR/$FILENAME.$$"
# HELP ${metrics_prefix}_epoch Current epoch
# TYPE ${metrics_prefix}_epoch counter
$EPOCH
# HELP ${metrics_prefix}_leader_slots Leader slots during epoch
# TYPE ${metrics_prefix}_leader_slots gauge
$LEADER_SLOTS
# HELP ${metrics_prefix}_blocks_produced Blocks produced during epoch
# TYPE ${metrics_prefix}_blocks_produced gauge
$BLOCKS_PRODUCED
# HELP ${metrics_prefix}_blocks_skipped Blocks skipped during epoch
# TYPE ${metrics_prefix}_blocks_skipped gauge
$BLOCKS_SKIPPED
# HELP ${metrics_prefix}_blocks_skipped_percent Percent of skipped blocks during epoch
# TYPE ${metrics_prefix}_blocks_skipped_percent gauge
$BLOCKS_SKIPPED_PERC
# HELP ${metrics_prefix}_ledger_size_bytes Blocks skipped during epoch
# TYPE ${metrics_prefix}_ledger_size_bytes gauge
$LEDGER_SIZE
# HELP ${metrics_prefix}_health_status Blocks skipped during epoch
# TYPE ${metrics_prefix}_health_status gauge
$HEALTH_STATUS
# HELP ${metrics_prefix}_current_client_version Current solana client version
# TYPE ${metrics_prefix}_current_client_version gauge
$CURRENT_CLIENT_VERSION
# HELP ${metrics_prefix}_last_client_version Last solana client version
# TYPE ${metrics_prefix}_last_client_version gauge
$LAST_CLIENT_VERSION
EOF
mv "$TEXTFILE_COLLECTOR_DIR/$FILENAME.$$" "$TEXTFILE_COLLECTOR_DIR/$FILENAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment