Commit a2daae2d by feilong

init

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