More logging adjustments and improvements. (0.21.1)
This commit is contained in:
parent
ac99346ac9
commit
4f30af83db
9 changed files with 75 additions and 49 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -1,8 +1,6 @@
|
||||||
# Linspector
|
# Linspector
|
||||||
etc.local/
|
etc.test.*
|
||||||
log/*.log
|
log/*.log
|
||||||
log/*.log.*
|
|
||||||
tmp.py
|
|
||||||
|
|
||||||
# ---> Python
|
# ---> Python
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
|
|
|
||||||
2
Makefile
2
Makefile
|
|
@ -37,7 +37,7 @@ run:
|
||||||
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VERSION)/site-packages/ bin/linspector -s ./etc
|
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VERSION)/site-packages/ bin/linspector -s ./etc
|
||||||
|
|
||||||
rundev:
|
rundev:
|
||||||
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VERSION)/site-packages/ bin/linspector -s ./etc.local
|
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VERSION)/site-packages/ bin/linspector -s ./etc.test.local
|
||||||
|
|
||||||
daemon:
|
daemon:
|
||||||
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VRESION)/site-packages/ bin/linspector -d ./etc
|
PYTHONPATH=$(shell pwd):$(shell pwd)/venv/lib/python$(PYTHON_VRESION)/site-packages/ bin/linspector -d ./etc
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ from linspector.linspector import Linspector
|
||||||
from linspector.monitors import Monitors
|
from linspector.monitors import Monitors
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
|
|
||||||
__version__ = '0.21'
|
__version__ = '0.21.1'
|
||||||
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
__author__ = 'Johannes Findeisen <you@hanez.org>'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -61,23 +61,48 @@ def main():
|
||||||
services = {}
|
services = {}
|
||||||
tasks = {}
|
tasks = {}
|
||||||
|
|
||||||
|
logger.remove()
|
||||||
|
default_log_format = '[{time:YYYY-MM-DD HH:mm:ss.SSSSSS ZZ}] [{elapsed}] [{level}] [linspector] ' \
|
||||||
|
'[{name}:{function}:{line}]: {message}'
|
||||||
|
log_level = "INFO"
|
||||||
|
logger.add(sys.stderr, backtrace=True, colorize=True, diagnose=True, format=default_log_format, level=log_level)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
configuration = Configuration(args.configuration_path, logger)
|
configuration = Configuration(args.configuration_path, logger)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.error('configuration error: {0}'.format(err))
|
logger.error('configuration error: {0}'.format(err))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
logger.remove()
|
|
||||||
log_level = "ERROR"
|
|
||||||
if configuration.get_option('linspector', 'log_level'):
|
if configuration.get_option('linspector', 'log_level'):
|
||||||
log_level = configuration.get_option('linspector', 'log_level')
|
logger.remove()
|
||||||
|
log_format = default_log_format
|
||||||
|
if configuration.get_option('linspector', 'log_format'):
|
||||||
|
log_format = configuration.get_option('linspector', 'log_format')
|
||||||
|
|
||||||
|
if configuration.get_option('linspector', 'log_level'):
|
||||||
|
log_level = configuration.get_option('linspector', 'log_level')
|
||||||
|
|
||||||
|
logger.add(sys.stderr, backtrace=True, colorize=True, diagnose=True, format=log_format, level=log_level)
|
||||||
|
|
||||||
logger.add(sys.stderr, backtrace=True, colorize=True, diagnose=True, level=log_level)
|
|
||||||
# log.add(sys.stderr, backtrace=True, colorize=True, diagnose=True, format="{time} [{level}]: {message}", level="INFO")
|
|
||||||
# log.add(sys.stderr, format="{time} {level} {message}", filter="my_module", level="INFO")
|
|
||||||
if configuration.get_option('linspector', 'logfile'):
|
if configuration.get_option('linspector', 'logfile'):
|
||||||
|
logfile_count = '10'
|
||||||
|
if configuration.get_option('linspector', 'logfile_count'):
|
||||||
|
logfile_count = configuration.get_option('linspector', 'logfile_count')
|
||||||
|
|
||||||
|
logfile_format = default_log_format
|
||||||
|
if configuration.get_option('linspector', 'logfile_format'):
|
||||||
|
logfile_format = configuration.get_option('linspector', 'logfile_format')
|
||||||
|
|
||||||
|
logfile_level = log_level
|
||||||
|
if configuration.get_option('linspector', 'logfile_level'):
|
||||||
|
logfile_level = configuration.get_option('linspector', 'logfile_level')
|
||||||
|
|
||||||
|
logfile_size = '1MB'
|
||||||
|
if configuration.get_option('linspector', 'logfile_size'):
|
||||||
|
logfile_size = configuration.get_option('linspector', 'logfile_size')
|
||||||
|
|
||||||
logger.add(configuration.get_option('linspector', 'logfile'), backtrace=True, diagnose=True, enqueue=True,
|
logger.add(configuration.get_option('linspector', 'logfile'), backtrace=True, diagnose=True, enqueue=True,
|
||||||
level=configuration.get_option('linspector', 'logfile_level'))
|
format=logfile_format, level=logfile_level, retention=int(logfile_count), rotation=logfile_size)
|
||||||
|
|
||||||
environment = Environment(logger)
|
environment = Environment(logger)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,33 @@
|
||||||
[linspector]
|
[linspector]
|
||||||
default_interval = 300
|
default_interval = 300
|
||||||
|
minimum_interval = 10
|
||||||
delta_range = 10
|
delta_range = 10
|
||||||
error_receivers = admin@example.com
|
|
||||||
log_file_count = 20
|
start_scheduler = true
|
||||||
log_file_size = 1
|
scheduler_mode = thread
|
||||||
log_file_size_bytes = 100000
|
|
||||||
log_level = info
|
|
||||||
max_processes = 1
|
max_processes = 1
|
||||||
max_threads = 2048
|
max_threads = 2048
|
||||||
minimum_interval = 10
|
|
||||||
notifications = email
|
|
||||||
pid_file = /var/run/user/1000/linspector.pid
|
pid_file = /var/run/user/1000/linspector.pid
|
||||||
|
|
||||||
|
; log format. this overrides the default configured in the code
|
||||||
|
log_format = <green>[{time:YYYY-MM-DD HH:mm:ss.SSSSSS ZZ}]</green> <yellow>[{elapsed}]</yellow> <magenta>[{level}]</magenta> <blue>[linspector]</blue> <cyan>[{name}:{function}:{line}]</cyan><red>:</red> {message}
|
||||||
|
; log level for stderr logging (default: INFO)
|
||||||
|
log_level = INFO
|
||||||
|
; logfile to use
|
||||||
|
logfile = /home/hanez/code/linspector/linspector/log/linspector.log
|
||||||
|
; number of logfiles to keep (default: 10)
|
||||||
|
logfile_count = 5
|
||||||
|
; logfile format. this overrides the default configured in the code
|
||||||
|
;logfile_format = [{time:YYYY-MM-DD HH:mm:ss.SSSSSS ZZ}] [{elapsed}] [{level}] [linspector] [{name}:{function}:{line}]: {message}
|
||||||
|
; log level for file based logging
|
||||||
|
logfile_level = DEBUG
|
||||||
|
; size of logfiles (default: 1MB)
|
||||||
|
logfile_size = 10MB
|
||||||
|
|
||||||
|
notifications =
|
||||||
plugins =
|
plugins =
|
||||||
run_mode = cron
|
tasks =
|
||||||
scheduler_mode = thread
|
|
||||||
start_scheduler = true
|
|
||||||
tasks = mariadb
|
|
||||||
timezone = CET
|
|
||||||
|
|
||||||
[hostgroupparents]
|
; timezone can be set to a remote timezone to make monitors run at the remote time. this is optional. the local
|
||||||
|
; timezone is set by default. this can be overridden in each monitor.
|
||||||
[hostgroups]
|
;timezone = UTC
|
||||||
|
|
||||||
[membergroups]
|
|
||||||
|
|
||||||
[monitorgroups]
|
|
||||||
|
|
||||||
[notifications]
|
|
||||||
|
|
||||||
[plugins]
|
|
||||||
|
|
||||||
[services]
|
|
||||||
|
|
||||||
[tasks]
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,10 @@ title = Uplink Status
|
||||||
description = Cable Provider Uplink Status
|
description = Cable Provider Uplink Status
|
||||||
service = vendor.avm.is_connected
|
service = vendor.avm.is_connected
|
||||||
host = 192.168.1.1
|
host = 192.168.1.1
|
||||||
interval = 60
|
interval = 5
|
||||||
|
; the timezone can be set to the zone of the monitor target host to run at the remote time. this is optional. the
|
||||||
|
; default is the local system timezone.
|
||||||
|
;timezone = UTC
|
||||||
|
|
||||||
[args]
|
[args]
|
||||||
host = 192.168.1.1
|
|
||||||
password = PASSWORD
|
password = PASSWORD
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
[monitor]
|
[monitor]
|
||||||
title = Uplink Status
|
title = Uplink Status
|
||||||
description = DSL Provider Uplink Status
|
description = Cable Provider Uplink Status
|
||||||
service = vendor.avm.is_connected
|
service = vendor.avm.is_connected
|
||||||
host = 192.168.2.1
|
host = 192.168.2.1
|
||||||
interval = 5
|
interval = 13
|
||||||
|
|
||||||
[args]
|
[args]
|
||||||
password = PASSWORD
|
password = PASSWORD
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
# some python receipts for different stuff
|
||||||
|
|
||||||
# get system timezone name
|
# get system timezone name
|
||||||
# https://stackoverflow.com/questions/1111056/get-time-zone-information-of-the-system-in-python
|
# https://stackoverflow.com/questions/1111056/get-time-zone-information-of-the-system-in-python
|
||||||
import datetime
|
import datetime
|
||||||
|
|
@ -9,15 +9,15 @@ import os
|
||||||
|
|
||||||
|
|
||||||
# TODO: check for all required configuration options and set defaults if needed. do this only for
|
# TODO: check for all required configuration options and set defaults if needed. do this only for
|
||||||
# options in the "linspector" section of linspector.ini.
|
# options in the "linspector" section of linspector.conf.
|
||||||
class Configuration:
|
class Configuration:
|
||||||
def __init__(self, configuration_path, log):
|
def __init__(self, configuration_path, log):
|
||||||
self.__configuration = configparser.ConfigParser()
|
self.__configuration = configparser.ConfigParser()
|
||||||
self.__configuration_path = configuration_path
|
self.__configuration_path = configuration_path
|
||||||
self.__log = log
|
self.__log = log
|
||||||
|
|
||||||
# print('[linspector] reading configuration file: ' + configuration_path +
|
log.info('message=reading configuration configfile=' + configuration_path +
|
||||||
# '/linspector.conf')
|
'/linspector.conf')
|
||||||
if os.path.isfile(configuration_path + '/linspector.conf'):
|
if os.path.isfile(configuration_path + '/linspector.conf'):
|
||||||
try:
|
try:
|
||||||
self.__configuration.read(configuration_path + '/linspector.conf', 'utf-8')
|
self.__configuration.read(configuration_path + '/linspector.conf', 'utf-8')
|
||||||
|
|
|
||||||
|
|
@ -99,11 +99,12 @@ class Linspector:
|
||||||
|
|
||||||
if configuration.get_option('linspector', 'timezone'):
|
if configuration.get_option('linspector', 'timezone'):
|
||||||
timezone = configuration.get_option('linspector', 'timezone')
|
timezone = configuration.get_option('linspector', 'timezone')
|
||||||
if monitors.get(monitor).get_monitor_configuration_option('args', 'timezone'):
|
if monitors.get(monitor).get_monitor_configuration_option('monitor', 'timezone'):
|
||||||
timezone = monitors.get(monitor).get_monitor_configuration_option('args',
|
timezone = monitors.get(monitor).get_monitor_configuration_option('monitor',
|
||||||
'timezone')
|
'timezone')
|
||||||
else:
|
else:
|
||||||
timezone = 'UTC'
|
# set to local system timezone by as default
|
||||||
|
timezone = datetime.datetime.now(datetime.timezone.utc).astimezone().tzname()
|
||||||
|
|
||||||
# add cron and one time run jobs to Linspector. not only "interval" jobs should be
|
# add cron and one time run jobs to Linspector. not only "interval" jobs should be
|
||||||
# supported.
|
# supported.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue