Cacti/Bcache: Difference between revisions

From fakedWiki
Jump to: navigation, search
No edit summary
No edit summary
 
Line 27: Line 27:
}
}


get_cache_ratio () {
get_hitrate () {
   local cache_ratio=""
   local hitrate=""
   for dev in "${PATH}/${1}/bdev*/"; do
   for dev in "${PATH}/${1}/bdev*/"; do
     local hits=$(<${dev}/stats_${2}/cache_hits)
     local dev_hr=$(<${dev}/stats_${2}/cache_hit_ratio)
    local misses=$(<${dev}/stats_${2}/cache_misses)
     if [ -z ${hitrate} ]; then
    local dev_ratio=$(( 100 * ${hits} / (${hits} + ${misses}) ))
       hitrate=${dev_hr}
     if [ -z ${cache_ratio} ]; then
       cache_ratio=${dev_ratio}
     fi
     fi
     cache_ratio=$(( (${cache_ratio} + ${dev_ratio}) / 2 ))  
     hitrate=$(( (${hitrate} + ${dev_hr}) / 2 ))  
   done
   done
   eval CACHE_RATIO_${2}=${cache_ratio}
   eval HITRATE_${2}=${hitrate}
}
}


get_cache_request () {
get_requests () {
   for dev in "${PATH}/${1}/bdev*/"; do
   for dev in "${PATH}/${1}/bdev*/"; do
     local value=$(<${dev}/stats_five_minute/cache_${2})
     local value=$(<${dev}/stats_five_minute/cache_${2})
     eval CACHE_REQUEST_${2}=$(( $CACHE_REQUEST_${2} + ${value} ))
     eval REQUEST_${2}=$(( $REQUEST_${2} + ${value} ))
   done
   done
}
}
Line 58: Line 56:
for cache in "${PATH}/*/"; do
for cache in "${PATH}/*/"; do
   uuid=$(/usr/bin/basename ${cache})
   uuid=$(/usr/bin/basename ${cache})
  get_bypassed ${uuid}
   get_dirty_data ${uuid}
   get_dirty_data ${uuid}
   get_cache_ratio ${uuid} five_minute
   get_hitrate ${uuid} total
   get_cache_ratio ${uuid} hour
   get_hitrate ${uuid} day
   get_cache_ratio ${uuid} day
   get_hitrate ${uuid} hour
   get_cache_ratio ${uuid} total
   get_hitrate ${uuid} five_minute
   get_cache_request ${uuid} hits
   get_requests ${uuid} bypass_hits
   get_cache_request ${uuid} misses
   get_requests ${uuid} bypass_misses
   get_cache_request ${uuid} bypass_hits
   get_requests ${uuid} hits
   get_cache_request ${uuid} bypass_misses
   get_requests ${uuid} misses
   get_cache_request ${uuid} miss_collisions
   get_requests ${uuid} miss_collisions
   get_cache_request ${uuid} readaheads
   get_requests ${uuid} readaheads
  get_bypassed ${uuid}
done
done


echo "dirty_data:${DIRTY_DATA} \
echo "bb:${BYPASSED}\
  ratio-5m:${CACHE_RATIO_five_minute} \
dd:${DIRTY_DATA}\
  ratio-1h:${CACHE_RATIO_hour} \
hr:${HITRATE_total}\
  ratio-1d:${CACHE_RATIO_day} \
hr_1d:${HITRATE_day}\
  ratio-total:${CACHE_RATIO_total} \
hr_1h:${HITRATE_hour}\
  request_hits:${CACHE_REQUEST_hits} \
hr_5m:${HITRATE_five_minute}\
  request_misses:${CACHE_REQUEST_misses} \
req_bh:${REQUEST_bypass_hits}\
  request_bypass_hits:${CACHE_REQUEST_bypass_hits} \
req_bm:${REQUEST_bypass_misses}\
  request_bypass_misses:${CACHE_REQUEST_bypass_misses} \
req_h:${REQUEST_hits}\
  request_miss_collisions:${CACHE_REQUEST_miss_collisions} \
req_m:${REQUEST_misses}\
  request_readaheads:${CACHE_REQUEST_readaheads} \
req_mc:${REQUEST_miss_collisions}\
  bypassed:${BYPASSED}"
req_ra:${REQUEST_readaheads}"


exit 0
exit 0
Line 89: Line 87:


== Cacti Host ==
== Cacti Host ==
'''/usr/share/cacti/resource/scripts/get_bcache.sh'''
'''/var/www/cacti/scripts/get_bcache.sh'''
<pre>
<pre>
#!/bin/bash
#!/bin/bash
Line 98: Line 96:
fi
fi


snmptable -CH -Cf '#' -c${2} -v1 ${1} .1.3.6.1.4.1.2021.8 | cut -d '#' -f5
snmptable -CH -Cf '#' -c${2} -v1 ${1} .1.3.6.1.4.1.2021.8 | sed -n "s/.*#bcache#.*#0#\(.*\)#noError#/\1/p"
 
</pre>
</pre>



Latest revision as of 22:33, 5 September 2016

bcache Host

Add to your /etc/snmp/snmpd.conf

exec bcache /etc/snmp/bcache.sh

Create /etc/snmp/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_hitrate () {
  local hitrate=""
  for dev in "${PATH}/${1}/bdev*/"; do
    local dev_hr=$(<${dev}/stats_${2}/cache_hit_ratio)
    if [ -z ${hitrate} ]; then
      hitrate=${dev_hr}
    fi
    hitrate=$(( (${hitrate} + ${dev_hr}) / 2 )) 
  done
  eval HITRATE_${2}=${hitrate}
}

get_requests () {
  for dev in "${PATH}/${1}/bdev*/"; do
    local value=$(<${dev}/stats_five_minute/cache_${2})
    eval REQUEST_${2}=$(( $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_bypassed ${uuid}
  get_dirty_data ${uuid}
  get_hitrate ${uuid} total
  get_hitrate ${uuid} day
  get_hitrate ${uuid} hour
  get_hitrate ${uuid} five_minute
  get_requests ${uuid} bypass_hits
  get_requests ${uuid} bypass_misses
  get_requests ${uuid} hits
  get_requests ${uuid} misses
  get_requests ${uuid} miss_collisions
  get_requests ${uuid} readaheads
done

echo "bb:${BYPASSED}\
 dd:${DIRTY_DATA}\
 hr:${HITRATE_total}\
 hr_1d:${HITRATE_day}\
 hr_1h:${HITRATE_hour}\
 hr_5m:${HITRATE_five_minute}\
 req_bh:${REQUEST_bypass_hits}\
 req_bm:${REQUEST_bypass_misses}\
 req_h:${REQUEST_hits}\
 req_m:${REQUEST_misses}\
 req_mc:${REQUEST_miss_collisions}\
 req_ra:${REQUEST_readaheads}"

exit 0

Cacti Host

/var/www/cacti/scripts/get_bcache.sh

#!/bin/bash

if [ ${#} -ne 2 ]; then
  echo "Usage: $0 <host> <community>"
  exit 0
fi

snmptable -CH -Cf '#' -c${2} -v1 ${1} .1.3.6.1.4.1.2021.8 | sed -n "s/.*#bcache#.*#0#\(.*\)#noError#/\1/p"

Data Template

tbc