Skip to content

Instantly share code, notes, and snippets.

@AGx10k
Last active February 18, 2021 21:26
Show Gist options
  • Save AGx10k/5a640bd9cc0b07a4c239918385b39ab9 to your computer and use it in GitHub Desktop.
Save AGx10k/5a640bd9cc0b07a4c239918385b39ab9 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
TEXTFILE_COLLECTOR_DIR=/var/lib/prometheus/node-exporter
FILENAME=solana_active_stake.prom
metrics_prefix=solana_monit_mainnet
ALL=$(timeout 45 solana validators --output json | jq -r '.currentValidators[] |[.identityPubkey, .activatedStake/1000000000] | @csv' )
ACTIVATED_STAKE=$(echo "$ALL" | awk -F"," -v prometheus_metric="${metrics_prefix}_activated_stake" ' { print prometheus_metric"{pubkey="$1"} "$2 } ' )
cat << EOF > "$TEXTFILE_COLLECTOR_DIR/$FILENAME.$$"
# HELP ${metrics_prefix}_activated_stake
# TYPE ${metrics_prefix}_activated_stake gauge
$ACTIVATED_STAKE
EOF
mv "$TEXTFILE_COLLECTOR_DIR/$FILENAME.$$" "$TEXTFILE_COLLECTOR_DIR/$FILENAME"
#!/bin/bash
export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
TEXTFILE_COLLECTOR_DIR=/var/lib/prometheus/node-exporter
FILENAME=solana_block_production.prom
metrics_prefix=solana_monit_mainnet
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')
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
EOF
mv "$TEXTFILE_COLLECTOR_DIR/$FILENAME.$$" "$TEXTFILE_COLLECTOR_DIR/$FILENAME"
#!/bin/bash
export PATH="/root/.local/share/solana/install/active_release/bin:$PATH"
TEXTFILE_COLLECTOR_DIR=/var/lib/prometheus/node-exporter
FILENAME=solana_delinquent_validators.prom
metrics_prefix=solana_monit_mainnet
ALL=$(timeout 45 solana validators --output json | jq .delinquentValidators[].identityPubkey -r )
DELINQUENT=$(echo "$ALL" | sed -ne 's/^\(.*\)$/solana_monit_mainnet_delinquent{pubkey="\1"} 1/p' )
cat << EOF > "$TEXTFILE_COLLECTOR_DIR/$FILENAME.$$"
# HELP ${metrics_prefix}_delinquent
# TYPE ${metrics_prefix}_delinquent gauge
$DELINQUENT
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