Commit a2daae2d by feilong

init

parent da005429
......@@ -19,49 +19,49 @@ Json_join(){
jstr=$jstr"{\"endpoint\": \"${endpoint}\", \"metric\": \"${metric}\", \"value\": $value,\"step\": ${step}, \"tags\": \"${tags}\",\"counterType\":\"${countertype}\",\"timestamp\": $(date +%s)},"
}
if [ "X$vendor" == "Xdell" ];then
test -f /usr/bin/hwinfo && value=2 || value=0
Json_join hw.status $value "$tags"
if [ $value -eq 2 ];then
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/sbin:/opt/dell/srvadmin/bin
SHELL=/bin/bash
./hwcheck_dell.py -p -s $step
exit 0
fi
test -f /usr/bin/hwinfo && value=2 || value=0
Json_join hw.status $value "$tags"
if [ $value -eq 2 ];then
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/dell/srvadmin/sbin:/opt/dell/srvadmin/bin
SHELL=/bin/bash
./hwcheck_dell.py -p -s $step
exit 0
fi
elif [ "X$vendor" == "Xhp" ];then
test -f /usr/sbin/hpacucli && value=2 || value=0
Json_join hw.status $value "$tags"
if [ $value -eq 2 ];then
hpacucli_log='/tmp/hpacucli_log'
temp_log='/tmp/temp_log'
hpacucli ctrl all show config > $hpacucli_log
vdisk=$(grep logicaldrive ${hpacucli_log}|grep -v OK|wc -l|awk '{print $1==0?2:0}')
pdisk=$(grep physicaldrive ${hpacucli_log}|grep -v OK|wc -l|awk '{print $1==0?2:0}')
memory=$(hpasmcli -s 'SHOW DIMM'|grep 'Status' |grep -v Ok|wc -l|awk '{print $1==0?2:0}')
fan=$(hpasmcli -s 'SHOW FANS'|grep '#'|grep -v Yes|wc -l|awk '{print $1==0?2:0}')
power=$(hpasmcli -s 'SHOW POWERSUPPLY'|grep Present|grep -v Yes|wc -l|awk '{print $1==0?2:0}')
cpu=$(hpasmcli -s 'SHOW SERVER' |grep Status|grep -v Ok|wc -l|awk '{print $1==0?2:0}')
raidcard=$(hpssacli ctrl all show status|grep Status|grep -v OK|wc -l|awk '{print $1==0?2:0}')
hpasmcli -s 'SHOW TEMP' >$temp_log
#power_temp=$(awk '/POWER_SUPPLY_BAY/{print $3}' $temp_log|awk -F"C" '{print $1}'|awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print max}')
#system_temp=$(awk '/SYSTEM_BD/{print $3}' $temp_log|awk -F"C" '{print $1}' |awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print max}')
ambient_temp=$(awk '/AMBIENT/{print $3}' $temp_log|awk -F"C" '{print $1}')
cpu_temp=$(awk '/PROCESSOR_ZONE/{print $3}' $temp_log|awk -F"C" '{print $1}' |awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print max}')
memory_temp=$(awk '/MEMORY_BD/{print $3}' $temp_log|awk -F"C" '{print $1}' |awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print max}')
Json_join hw.raidcard $raidcard $tags
Json_join hw.vdisk $vdisk $tags
Json_join hw.pdisk $pdisk $tags
Json_join hw.memory $memory $tags
Json_join hw.fan $fan $tags
Json_join hw.power $power $tags
Json_join hw.cpu $cpu $tags
Json_join hw.ambient_temp $ambient_temp $tags
Json_join hw.cpu_temp $cpu_temp $tags
Json_join hw.memory_temp $memory_temp $tags
#Json_join hw.power_temp $power_temp $tags
#Json_join hw.system_temp $system_temp $tags
fi
test -f /usr/sbin/hpacucli && value=2 || value=0
Json_join hw.status $value "$tags"
if [ $value -eq 2 ];then
hpacucli_log='/tmp/hpacucli_log'
temp_log='/tmp/temp_log'
hpacucli ctrl all show config > $hpacucli_log
vdisk=$(grep logicaldrive ${hpacucli_log}|grep -v OK|wc -l|awk '{print $1==0?2:0}')
pdisk=$(grep physicaldrive ${hpacucli_log}|grep -v OK|wc -l|awk '{print $1==0?2:0}')
memory=$(hpasmcli -s 'SHOW DIMM'|grep 'Status' |grep -v Ok|wc -l|awk '{print $1==0?2:0}')
fan=$(hpasmcli -s 'SHOW FANS'|grep '#'|grep -v Yes|wc -l|awk '{print $1==0?2:0}')
power=$(hpasmcli -s 'SHOW POWERSUPPLY'|grep Present|grep -v Yes|wc -l|awk '{print $1==0?2:0}')
cpu=$(hpasmcli -s 'SHOW SERVER' |grep Status|grep -v Ok|wc -l|awk '{print $1==0?2:0}')
raidcard=$(hpssacli ctrl all show status|grep Status|grep -v OK|wc -l|awk '{print $1==0?2:0}')
hpasmcli -s 'SHOW TEMP' >$temp_log
#power_temp=$(awk '/POWER_SUPPLY_BAY/{print $3}' $temp_log|awk -F"C" '{print $1}'|awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print max}')
#system_temp=$(awk '/SYSTEM_BD/{print $3}' $temp_log|awk -F"C" '{print $1}' |awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print max}')
ambient_temp=$(awk '/AMBIENT/{print $3}' $temp_log|awk -F"C" '{print $1}')
cpu_temp=$(awk '/PROCESSOR_ZONE/{print $3}' $temp_log|awk -F"C" '{print $1}' |awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print max}')
memory_temp=$(awk '/MEMORY_BD/{print $3}' $temp_log|awk -F"C" '{print $1}' |awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print max}')
Json_join hw.raidcard $raidcard $tags
Json_join hw.vdisk $vdisk $tags
Json_join hw.pdisk $pdisk $tags
Json_join hw.memory $memory $tags
Json_join hw.fan $fan $tags
Json_join hw.power $power $tags
Json_join hw.cpu $cpu $tags
Json_join hw.ambient_temp $ambient_temp $tags
Json_join hw.cpu_temp $cpu_temp $tags
Json_join hw.memory_temp $memory_temp $tags
#Json_join hw.power_temp $power_temp $tags
#Json_join hw.system_temp $system_temp $tags
fi
fi
jstr=$(echo $jstr|sed 's/^/[/;s/,$/]/;s/\[$/[]/')
......
......@@ -27,44 +27,43 @@ metric_slave_status=(slave_status:undefined Seconds_Behind_Master:undefined)
#metric_global_variables=(auto_increment_increment:undefined auto_increment_offset:undefined autocommit:undefined binlog_format:undefined general_log:undefined gtid_mode:undefined query_cache_size:undefined query_cache_type:undefined read_only:undefined report_host:undefined report_port:undefined server_id:undefined server_uuid:undefined skip_name_resolve:undefined slave_skip_errors:undefined slow_query_log:undefined sql_mode:undefined time_zone:undefined tx_isolation:undefined version:undefined)
Get_current_value(){
flag=$1
case $flag in
global_status)
sql="show global status"
eval $(mysql -u$user -p$pass -h$host -P$port -e "$sql" 2>/dev/null|awk '{printf("mysqld_%s=\"%s\"\n",$1,$2)}')
;;
slave_status)
sql="show slave status\G"
eval $(mysql -u$user -p$pass -h$host -P$port -e "$sql" 2>/dev/null |grep -v row |grep -v '_Gtid_Set'| grep -v ':\w' | awk -F'[: ]+' 'NR>1&&$0="mysqld_"$2"="$3')
#mysqld_slave_status
if [ ! -z $mysqld_Master_Host ];then
[ $mysqld_Slave_IO_Running == 'Yes' -a $mysqld_Slave_SQL_Running == 'Yes' ] && mysqld_slave_status=1 || mysqld_slave_status=0
fi
;;
# global_variables)
# sql="show global variables"
# eval $(mysql -u$user -p$pass -h$host -P$port -e "$sql" 2>/dev/null|awk '{printf("mysqld_%s=\"%s\"\n",$1,$2)}')
# ;;
esac
flag=$1
case $flag in
global_status)
sql="show global status"
eval $(mysql -u$user -p$pass -h$host -P$port -e "$sql" 2>/dev/null|awk '{printf("mysqld_%s=\"%s\"\n",$1,$2)}')
;;
slave_status)
sql="show slave status\G"
eval $(mysql -u$user -p$pass -h$host -P$port -e "$sql" 2>/dev/null |grep -v row |grep -v '_Gtid_Set'| grep -v ':\w' | awk -F'[: ]+' 'NR>1&&$0="mysqld_"$2"="$3')
#mysqld_slave_status
if [ ! -z $mysqld_Master_Host ];then
[ $mysqld_Slave_IO_Running == 'Yes' -a $mysqld_Slave_SQL_Running == 'Yes' ] && mysqld_slave_status=1 || mysqld_slave_status=0
fi
;;
# global_variables)
# sql="show global variables"
# eval $(mysql -u$user -p$pass -h$host -P$port -e "$sql" 2>/dev/null|awk '{printf("mysqld_%s=\"%s\"\n",$1,$2)}')
# ;;
esac
}
Push_n9e(){
for metric_array in ${metric_arrays[@]};do
{
for pre_metric in $(eval echo \${$metric_array[@]});do
{
[[ "$pre_metric" =~ ':compute' ]] \
&& countertype="COUNTER" \
|| countertype="GAUGE"
key="${service}_${pre_metric%%:*}"
value=$(eval echo \$$key)
metric="mysql.${pre_metric%%:*}"
[ "X"$value == "X" -o "X"$value == "XNULL" ] && continue
Json_join $metric $value "port=$port" $countertype
}
done
}
done
for metric_array in ${metric_arrays[@]};do
{
for pre_metric in $(eval echo \${$metric_array[@]});do
{
[[ "$pre_metric" =~ ':compute' ]] \
&& countertype="COUNTER" \
|| countertype="GAUGE"
key="${service}_${pre_metric%%:*}"
value=$(eval echo \$$key)
metric="mysql.${pre_metric%%:*}"
[ "X"$value == "X" -o "X"$value == "XNULL" ] && continue
Json_join $metric $value "port=$port" $countertype
}
done
}
done
}
Test_connection_status(){
tags="port=$port"
......@@ -87,13 +86,13 @@ Test_connection_status(){
}
Main(){
for port in $(grep $service ../service_port 2>/dev/null|awk '$0=$2');do
{
Test_connection_status || continue
Get_current_value global_status
Get_current_value slave_status
#Get_current_value global_variables
Push_n9e
}
{
Test_connection_status || continue
Get_current_value global_status
Get_current_value slave_status
#Get_current_value global_variables
Push_n9e
}
done
jstr=$(echo $jstr|sed 's/^/[/;s/,$/]/;s/\[$/[]/')
echo $jstr
......
......@@ -7,10 +7,7 @@ items:
"""
import os
import sys
import urllib2
import base64
import json
import re
import time
import yaml
import commands
......
......@@ -45,6 +45,7 @@ if __name__ == "__main__":
sys.stderr.write('cannot get local ip')
sys.exit(0)
core_total = int(os.popen("cat /proc/cpuinfo | grep processor | tail -1 | cut -d' ' -f2").read().strip()) + 1
# 核数太多采集单核指标意义不大
if core_total <= 8:
print(json.dumps(get_cpu_core_stat(core_total)))
else:
......
......@@ -609,36 +609,37 @@ def check(target=False):
# pass
if __name__ == "__main__":
code, endpoint = commands.getstatusoutput("ifconfig `route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|awk -F ':' '{print $NF}'|head -n 1")
if code != 0:
sys.stderr.write('cannot get local ip')
sys.exit(0)
metrics = ['cpu', 'memory', 'raidcard', 'pdisk', 'vdisk', 'raidcard_bat',
'bios', 'cmos_bat', 'fan', 'power', 'power_consumption', 'board_temp', 'ambient_temp', 'cpu_temp']
parser = OptionParser()
parser.add_option("-p", "--push", action="store_true", dest="push", help="push result to agent")
parser.add_option("-d", "--debug", action="store_true", dest="debug", help="output debug info")
parser.add_option("-m", "--metric", action="store", dest="metric", help="check special metric")
parser.add_option("-s", "--step", action="store", dest="step", help="check special metric")
(options, args) = parser.parse_args()
if not options.step:
step = 600
else:
step = int(options.step)
metric=None
if options.metric:
metric = options.metric
if metric not in metrics:
print(__doc__)
parser.print_help()
exit(1)
messages = check(target=metric)
if options.push:
addmsg('status', 2)
print(json.dumps(messages))
#push(messages)
else:
if options.debug:
print(json.dumps(messages, indent=2))
else:
print(json.dumps(verbs, indent=2))
code, endpoint = commands.getstatusoutput(
"ifconfig `route|grep '^default'|awk '{print $NF}'`|grep inet|awk '{print $2}'|awk -F ':' '{print $NF}'|head -n 1")
if code != 0:
sys.stderr.write('cannot get local ip')
sys.exit(0)
metrics = ['cpu', 'memory', 'raidcard', 'pdisk', 'vdisk', 'raidcard_bat',
'bios', 'cmos_bat', 'fan', 'power', 'power_consumption', 'board_temp', 'ambient_temp', 'cpu_temp']
parser = OptionParser()
parser.add_option("-p", "--push", action="store_true", dest="push", help="push result to agent")
parser.add_option("-d", "--debug", action="store_true", dest="debug", help="output debug info")
parser.add_option("-m", "--metric", action="store", dest="metric", help="check special metric")
parser.add_option("-s", "--step", action="store", dest="step", help="check special metric")
(options, args) = parser.parse_args()
if not options.step:
step = 600
else:
step = int(options.step)
metric = None
if options.metric:
metric = options.metric
if metric not in metrics:
print(__doc__)
parser.print_help()
exit(1)
messages = check(target=metric)
if options.push:
addmsg('status', 2)
print(json.dumps(messages))
# push(messages)
else:
if options.debug:
print(json.dumps(messages, indent=2))
else:
print(json.dumps(verbs, indent=2))
......@@ -2,7 +2,6 @@
#-*- coding:utf8 -*-
import sys
import os
import pymongo
from pymongo import MongoClient
......
......@@ -2,9 +2,6 @@
# coding: utf-8
import cx_Oracle
import inspect
import json
import re
class OracleTool(object):
......@@ -486,7 +483,7 @@ if __name__ == "__main__":
'dbname': 'orcl11g',
}
odb = OracleTool(dbconfig)
print odb.version()
print odb.tablespace_temp('TEMP')
print odb.show_tablespaces_temp()
print(odb.version())
print(odb.tablespace_temp('TEMP'))
print(odb.show_tablespaces_temp())
odb.db_close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment