Add logging and command line arguments
This commit is contained in:
parent
5b8cde3c93
commit
a0a8598dd6
|
@ -1,4 +1,6 @@
|
|||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import threading
|
||||
|
||||
from openstack_qa_tools.collectors import mysql
|
||||
|
@ -19,13 +21,21 @@ def get_queues():
|
|||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--loglevel', default=logging.INFO)
|
||||
args = parser.parse_args()
|
||||
logging.basicConfig(format='%(asctime)-15s %(levelname)s %(threadName)s: %(message)s')
|
||||
log = logging.getLogger()
|
||||
log.setLevel(args.loglevel)
|
||||
getmysql = threading.Thread(name='mysql', target=get_mysql)
|
||||
getqueues = threading.Thread(name='queues', target=get_queues)
|
||||
getmysql.start()
|
||||
getqueues.start()
|
||||
log.debug('waiting for threads')
|
||||
|
||||
getmysql.join()
|
||||
getqueues.join()
|
||||
log.debug('threads all returned')
|
||||
|
||||
final = {
|
||||
'mysql': mysql_data,
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# This file was forked from dstat's mysql5_innodb plugin but retains none of
|
||||
# that original code other than a list of well known MySQL variable names.
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
import pymysql
|
||||
|
@ -55,6 +56,7 @@ def _get_config():
|
|||
|
||||
|
||||
def collect():
|
||||
log = logging.getLogger()
|
||||
args = _get_config()
|
||||
conn = pymysql.connect(**args)
|
||||
cursor = conn.cursor()
|
||||
|
@ -67,4 +69,5 @@ def collect():
|
|||
k, v = result
|
||||
if k in COLLECT_COUNTERS:
|
||||
counters[k] = int(v)
|
||||
log.debug(counters)
|
||||
return counters
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import base64
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
import socket
|
||||
|
@ -28,6 +29,7 @@ DSTAT_RABBITMQ_API_PASS = os.environ.get('DSTAT_RABBITMQ_PASS',
|
|||
|
||||
|
||||
def collect():
|
||||
log = logging.getLogger()
|
||||
conn = http_client.HTTPConnection(DSTAT_RABBITMQ_API)
|
||||
auth = '%s:%s' % (DSTAT_RABBITMQ_API_USER, DSTAT_RABBITMQ_API_PASS)
|
||||
auth = base64.encodestring(auth.encode('utf-8')).decode('ascii')
|
||||
|
@ -35,7 +37,9 @@ def collect():
|
|||
auth = {'Authorization': 'Basic %s' % auth}
|
||||
try:
|
||||
conn.request('GET', '/api/queues', headers=auth)
|
||||
log.debug('requested /api/queues')
|
||||
content = conn.getresponse().read()
|
||||
log.debug('received content')
|
||||
except (socket.error, http_client.HTTPException) as e:
|
||||
raise error.CollectionError(str(e))
|
||||
|
||||
|
|
Loading…
Reference in New Issue