55from distutils .version import LooseVersion
66import mamonsu .lib .platform as platform
77from mamonsu .lib .plugin import PluginDisableException
8+ import logging
89
910class MemoryLeakDiagnostic (Plugin ):
1011 DEFAULT_CONFIG = {'enabled' : 'False' ,
@@ -23,7 +24,7 @@ def __init__(self, config):
2324 super (Plugin , self ).__init__ (config )
2425 if not platform .LINUX :
2526 self .disable ()
26- raise PluginDisableException ('Plugin {name} work only on Linux. ' .format (name = self .__class__ .__name__ ))
27+ logging . error ('Plugin {name} work only on Linux. ' .format (name = self .__class__ .__name__ ))
2728
2829 if self .is_enabled ():
2930 self .page_size = os .sysconf ('SC_PAGE_SIZE' )
@@ -41,9 +42,11 @@ def __init__(self, config):
4142 ratio = 1024 * 1024 * 1024 * 1024
4243 else :
4344 self .disable ()
44- raise PluginDisableException ('Error in config, section [{section}], parameter private_anon_mem_threshold. '
45+ logging . error ('Error in config, section [{section}], parameter private_anon_mem_threshold. '
4546 'Possible values MB, GB, TB. For example 1GB.'
4647 .format (section = self .__class__ .__name__ .lower ()))
48+ ratio = 1024 * 1024 * 1024
49+
4750 self .diff = ratio * int (private_anon_mem_threshold )
4851
4952 self .os_release = os .uname ().release
@@ -52,15 +55,17 @@ def __init__(self, config):
5255 release_file = open (os_release_file , 'r' ).readlines ()
5356 except Exception as e :
5457 self .disable ()
55- raise PluginDisableException (f'Cannot read file { os_release_file } : { e } ' )
56-
57- for line in release_file :
58- if line .strip ('"\n ' ) != '' :
59- k , v = line .split ('=' , 1 )
60- if k == 'ID' :
61- self .os_name = v .strip ('"\n ' )
62- elif k == 'VERSION_ID' :
63- self .os_version = v .strip ('"\n ' )
58+ release_file = None
59+ logging .error (f'Cannot read file { os_release_file } : { e } ' )
60+
61+ if release_file :
62+ for line in release_file :
63+ if line .strip ('"\n ' ) != '' :
64+ k , v = line .split ('=' , 1 )
65+ if k == 'ID' :
66+ self .os_name = v .strip ('"\n ' )
67+ elif k == 'VERSION_ID' :
68+ self .os_version = v .strip ('"\n ' )
6469
6570 def run (self , zbx ):
6671 pids = []
0 commit comments