diff --git a/bin/mem_stats.py b/bin/mem_stats.py new file mode 100755 index 00000000..647a1ab7 --- /dev/null +++ b/bin/mem_stats.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python +# +# Copyright: 2014 Sipwise Development Team +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This package is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# On Debian systems, the complete text of the GNU General +# Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". +# +import sys, os, csv, argparse +import xmlrpclib + +KAM_URL='http://127.0.0.1:5062' +KAM_LINES=10 + +proxy = xmlrpclib.ServerProxy(KAM_URL) + +def get_headers(l): + res = {} + for i in l: + res[i] = i + return res + +def get_pvm(private_file): + res = [] + headers = ['pid', 'used', 'real_used', 'free'] + write_headers = False + try: + for i in range(KAM_LINES): + res.append(proxy.pkg.stats("index", i)[0]) + except xmlrpclib.Fault as err: + print "A fault occurred" + print "Fault code: %d" % err.faultCode + print "Fault string: %s" % err.faultString + sys.exit(-1) + except xmlrpclib.ProtocolError as err: + print "A protocol error occurred" + print "URL: %s" % err.url + print "HTTP/HTTPS headers: %s" % err.headers + print "Error code: %d" % err.errcode + print "Error message: %s" % err.errmsg + sys.exit(-2) + if not os.path.isfile(private_file): + write_headers = True + with open(private_file, 'a+') as csvfile: + spamwriter = csv.DictWriter(csvfile, + headers, extrasaction='ignore') + if write_headers: + spamwriter.writerow(get_headers(headers)) + for row in res: + spamwriter.writerow(row) + +def get_shm(share_file): + write_headers = False + try: + res = proxy.core.shmmem('b') + except xmlrpclib.Fault as err: + print "A fault occurred" + print "Fault code: %d" % err.faultCode + print "Fault string: %s" % err.faultString + sys.exit(-1) + except xmlrpclib.ProtocolError as err: + print "A protocol error occurred" + print "URL: %s" % err.url + print "HTTP/HTTPS headers: %s" % err.headers + print "Error code: %d" % err.errcode + print "Error message: %s" % err.errmsg + sys.exit(-2) + if not os.path.isfile(share_file): + write_headers = True + with open(share_file, 'a+') as csvfile: + spamwriter = csv.DictWriter(csvfile, + res.keys()) + if write_headers: + spamwriter.writerow(get_headers(res.keys())) + spamwriter.writerow(res) + +def main(): + parser = argparse.ArgumentParser(description='export to csv kamailio proxy stats.') + parser.add_argument('--private_file', '-P', nargs='?', default='pvm.csv', + help='path to the private csv file') + parser.add_argument('--share_file', '-S', nargs='?', default='shm.csv', + help='path to the share csv file') + parser.add_argument('--rpc_url', nargs='?', default=KAM_URL, + help='rpc URL of kamailio. Default:%s' % KAM_URL) + args = parser.parse_args() + + get_pvm(args.private_file) + get_shm(args.share_file) + +if __name__ == "__main__": + main() diff --git a/run_tests.sh b/run_tests.sh index 2cfdddae..1194cbc0 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -2,6 +2,7 @@ BASE_DIR=${BASE_DIR:-"/usr/share/kamailio-config-tests"} BIN_DIR="${BASE_DIR}/bin" LOG_DIR="${BASE_DIR}/log" +MLOG_DIR="${BASE_DIR}/mem" RESULT_DIR="${BASE_DIR}/result" PROFILE="CE" DOMAIN="spce.test" @@ -66,6 +67,11 @@ fi echo "$(date) - Clean log dir" rm -rf ${LOG_DIR} +mkdir -p ${MLOG_DIR} + +echo "$(date) - Initial mem stats" +${BIN_DIR}/mem_stats.py --private_file=${MLOG_DIR}/initial_pvm.cvs \ + --share_file=${MLOG_DIR}/initial_shm.cvs for t in $(find ${BASE_DIR}/scenarios/ -depth -maxdepth 1 -mindepth 1 -type d | grep -v templates | sort); do echo "$(date) - Run[${PROFILE}]: $(basename $t) =================================================" @@ -76,6 +82,10 @@ for t in $(find ${BASE_DIR}/scenarios/ -depth -maxdepth 1 -mindepth 1 -type d | echo "$(date) - =================================================================================" done +echo "$(date) - Initial mem stats" +${BIN_DIR}/mem_stats.py --private_file=${MLOG_DIR}/final_pvm.cvs \ + --share_file=${MLOG_DIR}/final_shm.cvs + if [ -z $SKIP ]; then echo "$(date) - Setting config debug off" ${BIN_DIR}/config_debug.pl off ${DOMAIN}