Ciscoスイッチ向けmackerel agentスクリプト
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 | |
if [ -z "$1" ]; | |
then | |
echo "Usage $(basename $0) <host>" | |
exit 1 | |
fi | |
TARGET="$1" | |
MACKEREL_APIKEY="API Key" | |
MACKEREL_HOSTID_FILE="/var/lib/mackerel/$TARGET/id" | |
SNMP_COMMUNITY="SNMP Community" | |
SNMP_OPT="-v2c -c $SNMP_COMMUNITY" | |
MKR="/usr/local/bin/mkr" | |
fetchsnmp() { | |
snmpwalk -Ov $SNMP_OPT $TARGET $1 | awk '{print $2}' | |
} | |
inithost() { | |
[ ! -d "$(dirname "$MACKEREL_HOSTID_FILE")" ] && mkdir -p "$(dirname "$MACKEREL_HOSTID_FILE")" | |
HOSTNAME="$(fetchsnmp .1.3.6.1.2.1.1.5.0)" | |
$MKR create $HOSTNAME | awk '{print $NF}' > $MACKEREL_HOSTID_FILE | |
} | |
throwmetric() { | |
METRIC="$1" | |
OID="$2" | |
VALUE="$(fetchsnmp $OID)" | |
echo "$METRIC $VALUE $(date +%s)" | $MKR throw --host $MACKEREL_HOSTID > /dev/null | |
} | |
[ ! -f "$MACKEREL_HOSTID_FILE" ] && inithost | |
MACKEREL_HOSTID="$(cat $MACKEREL_HOSTID_FILE)" | |
# CPU | |
throwmetric custom.cisco.cpu.5m .1.3.6.1.4.1.9.9.109.1.1.1.1.3.1 | |
throwmetric custom.cisco.cpu.1m .1.3.6.1.4.1.9.9.109.1.1.1.1.3.1 | |
throwmetric custom.cisco.cpu.5s .1.3.6.1.4.1.9.9.109.1.1.1.1.5.1 | |
# Memory Used | |
throwmetric custom.cisco.memory.used .1.3.6.1.4.1.9.9.48.1.1.1.5.1 | |
throwmetric custom.cisco.memory.free .1.3.6.1.4.1.9.9.48.1.1.1.6.1 | |
# Interface | |
snmpwalk -On $SNMP_OPT $TARGET .1.3.6.1.2.1.2.2.1.1 | | |
awk '{print $1}' | | |
awk -F. '{print $NF}' | | |
while read INDEX | |
do | |
throwmetric "custom.cisco.interface.in.ifindex$INDEX" .1.3.6.1.2.1.2.2.1.10.$INDEX | |
throwmetric "custom.cisco.interface.out.ifindex$INDEX" .1.3.6.1.2.1.2.2.1.16.$INDEX | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment