changing threads func args to keyargs

This commit is contained in:
Alexey Nizhegolenko 2022-07-21 14:23:44 +03:00
parent 156453cf76
commit 7acc4727df

View file

@ -123,10 +123,6 @@ def main():
INFLUXUSER = CONFIG.get('INFLUXDB1', 'username') INFLUXUSER = CONFIG.get('INFLUXDB1', 'username')
MEASUREMENT = CONFIG.get('INFLUXDB1', 'measurement') MEASUREMENT = CONFIG.get('INFLUXDB1', 'measurement')
INFLUXUSERPASS = CONFIG.get('INFLUXDB1', 'password') INFLUXUSERPASS = CONFIG.get('INFLUXDB1', 'password')
KWARGS1 = {'GEOIPDB': GEOIPDB, 'LOGPATH': LOGPATH, 'INFLUXHOST': INFLUXHOST,
'INFLUXPORT': INFLUXPORT, 'INFLUXDBDB': INFLUXDBDB,
'INFLUXUSER': INFLUXUSER, 'MEASUREMENT': MEASUREMENT,
'INFLUXUSERPASS': INFLUXUSERPASS, 'INFLUXDB_VERSION': INFLUXDB_VERSION} # NOQA
elif INFLUXDB_VERSION == "2": elif INFLUXDB_VERSION == "2":
# Getting params from config for version 2 # Getting params from config for version 2
LOGPATH = CONFIG.get('NGINX_LOGS', 'logpath').split() LOGPATH = CONFIG.get('NGINX_LOGS', 'logpath').split()
@ -135,9 +131,6 @@ def main():
INFLUXDBBUCKET = CONFIG.get('INFLUXDB2', 'bucket') INFLUXDBBUCKET = CONFIG.get('INFLUXDB2', 'bucket')
MEASUREMENT = CONFIG.get('INFLUXDB2', 'measurement') MEASUREMENT = CONFIG.get('INFLUXDB2', 'measurement')
INFLUXDBORG = CONFIG.get('INFLUXDB2', 'organization') INFLUXDBORG = CONFIG.get('INFLUXDB2', 'organization')
KWARGS2 = {'LOGPATH': LOGPATH, 'URL': URL, 'INFLUXDBTOKEN': INFLUXDBTOKEN,
'INFLUXDBBUCKET': INFLUXDBBUCKET, 'MEASUREMENT': MEASUREMENT,
'INFLUXDBORG': INFLUXDBORG} # NOQA
# Parsing log file and sending metrics to Influxdb # Parsing log file and sending metrics to Influxdb
while True: while True:
@ -153,9 +146,16 @@ def main():
logging.info('Nginx log file %s not found', log) logging.info('Nginx log file %s not found', log)
print('Nginx log file %s not found' % log) print('Nginx log file %s not found' % log)
return return
if INFLUXDB_VERSION == "1": if INFLUXDB_VERSION == "1":
# Run the main loop and grep data in separate threads # Run the main loop and grep data in separate threads
KWARGS1 = {'GEOIPDB': GEOIPDB, 'LOGPATH': LOGPATH, 'INFLUXHOST': INFLUXHOST,
'INODE': INODE, 'WEBSITE': website, 'INFLUXPORT': INFLUXPORT, 'INFLUXDBDB': INFLUXDBDB,
'INFLUXUSER': INFLUXUSER, 'MEASUREMENT': MEASUREMENT,
'INFLUXUSERPASS': INFLUXUSERPASS, 'INFLUXDB_VERSION': INFLUXDB_VERSION} # NOQA
KWARGS2 = {'LOGPATH': LOGPATH, 'URL': URL, 'INFLUXDBTOKEN': INFLUXDBTOKEN,
'INFLUXDBBUCKET': INFLUXDBBUCKET, 'MEASUREMENT': MEASUREMENT,
'INODE': INODE, 'WEBSITE': website, 'INFLUXDBORG': INFLUXDBORG} # NOQA
t = website t = website
if os.path.exists(log): if os.path.exists(log):
t = threading.Thread(target=logparse, kwargs=KWARGS1, daemon=True, name=website) # NOQA t = threading.Thread(target=logparse, kwargs=KWARGS1, daemon=True, name=website) # NOQA