Cacti/Bcache
From fakedWiki
bcache Host
Add to your /etc/snmp/snmpd.conf
exec bcache /usr/bin/cacti-bcache.sh
Create /usr/bin/cacti-bcache.sh
#!/bin/bash PATH='/sys/fs/bcache' if [ ! -d ${PATH} ]; then echo "Error: bcache not loaded" exit 1 fi DIRTY_DATA=0 BYPASSED=0 get_dirty_data () { for dev in "${PATH}/${1}/bdev*/"; do local size=$(<${dev}/dirty_data) local bytes=$(/usr/bin/numfmt --from=iec ${size}) DIRTY_DATA=$(( ${DIRTY_DATA} + ${bytes} )) done } get_cache_ratio () { local cache_ratio="" for dev in "${PATH}/${1}/bdev*/"; do local hits=$(<${dev}/stats_${2}/cache_hits) local misses=$(<${dev}/stats_${2}/cache_misses) local dev_ratio=$(( 100 * ${hits} / (${hits} + ${misses}) )) if [ -z ${cache_ratio} ]; then cache_ratio=${dev_ratio} fi cache_ratio=$(( (${cache_ratio} + ${dev_ratio}) / 2 )) done eval CACHE_RATIO_${2}=${cache_ratio} } get_cache_request () { for dev in "${PATH}/${1}/bdev*/"; do local value=$(<${dev}/stats_five_minute/cache_${2}) eval CACHE_REQUEST_${2}=$(( $CACHE_REQUEST_${2} + ${value} )) done } get_bypassed () { for dev in "${PATH}/${1}/bdev*/"; do local size=$(<${dev}/stats_five_minute/bypassed) local bytes=$(/usr/bin/numfmt --from=iec ${size}) BYPASSED=$(( ${BYPASSED} + ${bytes} )) done } for cache in "${PATH}/*/"; do uuid=$(/usr/bin/basename ${cache}) get_dirty_data ${uuid} get_cache_ratio ${uuid} five_minute get_cache_ratio ${uuid} hour get_cache_ratio ${uuid} day get_cache_ratio ${uuid} total get_cache_request ${uuid} hits get_cache_request ${uuid} misses get_cache_request ${uuid} bypass_hits get_cache_request ${uuid} bypass_misses get_cache_request ${uuid} miss_collisions get_cache_request ${uuid} readaheads get_bypassed ${uuid} done echo "dirty_data:${DIRTY_DATA} \ ratio-5m:${CACHE_RATIO_five_minute} \ ratio-1h:${CACHE_RATIO_hour} \ ratio-1d:${CACHE_RATIO_day} \ ratio-total:${CACHE_RATIO_total} \ request_hits:${CACHE_REQUEST_hits} \ request_misses:${CACHE_REQUEST_misses} \ request_bypass_hits:${CACHE_REQUEST_bypass_hits} \ request_bypass_misses:${CACHE_REQUEST_bypass_misses} \ request_miss_collisions:${CACHE_REQUEST_miss_collisions} \ request_readaheads:${CACHE_REQUEST_readaheads} \ bypassed:${BYPASSED}" exit 0
Cacti Host
/usr/share/cacti/resource/scripts/get_bcache.sh
#!/bin/bash if [ ${#} -ne 3 ]; then echo "Usage: $0 <host> <community>" exit 0 fi snmptable -c${2} -v1 ${1} .1.3.6.1.4.1.2021.8 | sed -n "s/\s*[0-9]+*\s*bcache.*\s*0\s*\(.*\)\s*noError/\1/p"
Data Template
tbc