Revision 310

Date:
2010/02/04 16:33:29
Author:
alan
Revision Log:
Disk usage checks added to MySQL / FreeBSD modules
Files:

Legend:

 
Added
 
Removed
 
Modified
  • binarystor/trunk/src/python/dbalerter/daemon/dbalerter/checkfreebsd.py

     
    6 6 @license: BSD License
    7 7 """
    8 8
    9 import ctypes, subprocess
    9 import ctypes, os, subprocess
    10 10
    11 11 __author__ = "Alan Snelson"
    12 12 __copyright__ = "Copyright (c) 2010 Wave2 Limited"
     
    32 32 memory_usage['total'] = (v_page_count * page_size) / (1024*1024)
    33 33 memory_usage['used'] = memory_usage['total'] - ((v_free_count * page_size) / (1024*1024))
    34 34 return memory_usage
    35
    35 36
    36 37 def get_swap_usage():
    37 38 """Return swap usage dictionary in megabytes"""
     
    44 45 swap_usage['total'] += int(line.split()[3])
    45 46 return swap_usage
    46 47
    47 def get_mount_usage():
    48
    49 def get_mount_point(path):
    50 """Strip mount point from path"""
    51
    52 path = os.path.abspath(path)
    53 while path != os.path.sep:
    54 if os.path.ismount(path):
    55 return path
    56 path = os.path.abspath(os.path.join(path, os.pardir))
    57 return path
    58
    59
    60 def get_disk_usage():
    48 61 """Return disk usage in dictionary"""
    49 62
    63 disk_usage = {}
    64 diskinfo = subprocess.Popen(['df','-i'], shell=False, stdout=subprocess.PIPE)
    65 diskinfo.stdout.readline()
    66 for line in diskinfo.stdout:
    67 disk_usage[line.split()[8]] = { 'filesystem' : line.split()[0], 'size' : int(line.split()[1]), \
    68 'used' : int(line.split()[2]), 'avail' : int(line.split()[3]), 'capacity' : line.split()[4], 'iused' : int(line.split()[5]), 'ifree' : int(line.split()[6]), 'icapacity' : line.split()[7] }
    69 return disk_usage
    70
    71
    72 def get_mount_usage(paths):
    73 """Check mount point disk usage"""
    74
    50 75 mount_usage = {}
    51 mountinfo = subprocess.Popen(['df','-i'], shell=False, stdout=subprocess.PIPE)
    52 mountinfo.stdout.readline()
    53 for line in mountinfo.stdout:
    54 mount_usage[line.split()[8]] = { 'filesystem' : line.split()[0], 'size' : int(line.split()[1]), \
    55 'used' : int(line.split()[2]), 'avail' : int(line.split()[3]), 'capacity' : line.split()[4], 'iused' : int(line.split()[5]), 'ifree' : int(line.split()[6]), 'icapacity' : line.split()[7] }
    76 for mount, stats in get_disk_usage().items():
    77 for path in paths:
    78 if (mount == get_mount_point(path)):
    79 mount_usage[path] = stats
    56 80 return mount_usage
    57 81
    82
    58 83 def get_cpu_usage(pid):
    59 84 """Return process cpu usage"""
    60 85
  • binarystor/trunk/src/python/dbalerter/daemon/dbalerter/checkmysql.py

     
    23 23 auto_increment_state = {}
    24 24 process_list_state = {}
    25 25 security_state = {'ANONACCOUNT' : 0, 'EMPTYPASS' : 0}
    26 warning_state = {'CONNECTIONS' : 0, 'CPU_USAGE' : 0, 'OPEN_FILES' : 0, 'SLAVEIO' : 0, 'SLAVESQL' : 0, 'SLAVEPOS' : 0}
    26 warning_state = {'CONNECTIONS' : 0, 'BASEDIR_USAGE' : 0, 'CPU_USAGE' : 0, 'DATADIR_USAGE' : 0, \
    27 'OPEN_FILES' : 0, 'PLUGIN_DIR_USAGE' : 0, 'SLAVEIO' : 0, 'SLAVESQL' : 0, 'SLAVEPOS' : 0, 'TMPDIR_USAGE' : 0}
    27 28 global_status = {'SLOW_QUERIES' : 0, 'MAX_USED_CONNECTIONS' : 0, 'UPTIME' : 0}
    28 29 statistics = {'ERROR' : 0, 'WARNING' : 0, 'INFO' : 0, 'SLOWQ' : 0, 'MAXCONN' : 0, 'MAX_OPEN_FILES' : 0}
    29 30 variables = {'BASEDIR' : '', 'DATADIR' : '', 'HOSTNAME' : '', 'LOG_ERROR' : '', 'PID' : 0, 'PID_FILE' : '', \
     
    120 121 global db, statistics
    121 122 try:
    122 123 #OS Checks
    123 check_cpu_usage()
    124 if (checkos.supported):
    125 check_cpu_usage()
    126 check_disk_usage()
    124 127 #MySQL Checks
    125 128 update_variables()
    126 129 check_status()
     
    210 213 """Check MySQL CPU usage"""
    211 214
    212 215 global variables
    213 if (checkos.supported):
    214 cpu_usage = float(checkos.get_cpu_usage(variables['PID']))
    215 threshold = float(config.get('dbAlerter','mysql_cpu_usage_threshold'))
    216 if (cpu_usage > threshold):
    217 notify.stateful_notify(True, warning_state, 'CPU_USAGE', 'Warning', 'CPU threshold crossed', 'CPU Usage for MySQL process (' + str(variables['PID']) + ') is currently ' + str(cpu_usage) + '% (Threshold currently set to ' + str(threshold) + '%)')
    218 else:
    219 notify.stateful_notify(False, warning_state, 'CPU_USAGE', 'Warning', 'CPU threshold returned below threshold', 'CPU Usage for MySQL process (' + str(variables['PID']) + ') is currently ' + str(cpu_usage) + '% (Threshold currently set to ' + str(threshold) + '%)')
    220
    221 216
    217 cpu_usage = float(checkos.get_cpu_usage(variables['PID']))
    218 threshold = float(config.get('dbAlerter','mysql_cpu_usage_threshold'))
    219 if (cpu_usage > threshold):
    220 notify.stateful_notify(True, warning_state, 'CPU_USAGE', 'Warning', 'CPU utilisation threshold crossed', 'CPU utilisation for MySQL process (' + str(variables['PID']) + ') is currently ' + str(cpu_usage) + '% (Threshold currently set to ' + str(threshold) + '%)')
    221 else:
    222 notify.stateful_notify(False, warning_state, 'CPU_USAGE', 'Info', 'CPU utilisation returned below threshold', 'CPU utilisation for MySQL process (' + str(variables['PID']) + ') is currently ' + str(cpu_usage) + '% (Threshold currently set to ' + str(threshold) + '%)')
    222 223
    224
    225 def check_disk_usage():
    226 """Check MySQL disk usage"""
    227
    228 global variables
    229
    230 mount_usage = checkos.get_mount_usage([variables['BASEDIR'], variables['DATADIR'], variables['PLUGIN_DIR'], variables['TMPDIR']])
    231 #Basedir usage
    232 capacity = int(mount_usage[variables['BASEDIR']]['capacity'].replace('%',''))
    233 threshold = int(config.get('dbAlerter', 'mysql_basedir_threshold'))
    234 if (capacity > threshold):
    235 notify.stateful_notify(True, warning_state, 'BASEDIR_USAGE', 'Warning', 'Basedir usage threshold crossed', 'Basedir usage is currently ' + str(capacity) + '% (Threshold currently set to ' + str(threshold) + '%)')
    236 else:
    237 notify.stateful_notify(False, warning_state, 'BASEDIR_USAGE', 'Info', 'Basedir usage returned below threshold', 'Basedir usage is currently ' + str(capacity) +'% (Threshold currently set to ' + str(threshold) + '%)')
    238
    239 #Datadir usage
    240 capacity = int(mount_usage[variables['DATADIR']]['capacity'].replace('%',''))
    241 threshold = int(config.get('dbAlerter', 'mysql_datadir_threshold'))
    242 if (capacity > threshold):
    243 notify.stateful_notify(True, warning_state, 'DATADIR_USAGE', 'Warning', 'Datadir usage threshold crossed', 'Datadir usage is currently ' + str(capacity) + '% (Threshold currently set to ' + str(threshold) + '%)')
    244 else:
    245 notify.stateful_notify(False, warning_state, 'DATADIR_USAGE', 'Info', 'Datadir usage returned below threshold', 'Datadir usage is currently ' + str(capacity) +'% (Threshold currently set to ' + str(threshold) + '%)')
    246
    247 #Plugin_dir usage
    248 capacity = int(mount_usage[variables['PLUGIN_DIR']]['capacity'].replace('%',''))
    249 threshold = int(config.get('dbAlerter', 'mysql_plugindir_threshold'))
    250 if (capacity > threshold):
    251 notify.stateful_notify(True, warning_state, 'PLUGIN_DIR_USAGE', 'Warning', 'Plugindir usage threshold crossed', 'Plugindir usage is currently ' + str(capacity) + '% (Threshold currently set to ' + str(threshold) + '%)')
    252 else:
    253 notify.stateful_notify(False, warning_state, 'PLUGIN_DIR_USAGE', 'Info', 'Plugindir usage returned below threshold', 'Plugindir usage is currently ' + str(capacity) +'% (Threshold currently set to ' + str(threshold) + '%)')
    254
    255 #Tmpdir usage
    256 capacity = int(mount_usage[variables['TMPDIR']]['capacity'].replace('%',''))
    257 threshold = int(config.get('dbAlerter', 'mysql_tmpdir_threshold'))
    258 if (capacity > threshold):
    259 notify.stateful_notify(True, warning_state, 'TMPDIR_USAGE', 'Warning', 'Tmpdir usage threshold crossed', 'Tmpdir usage is currently ' + str(capacity) + '% (Threshold currently set to ' + str(threshold) + '%)')
    260 else:
    261 notify.stateful_notify(False, warning_state, 'TMPDIR_USAGE', 'Info', 'Tmpdir usage returned below threshold', 'Tmpdir usage is currently ' + str(capacity) +'% (Threshold currently set to ' + str(threshold) + '%)')
    262
    263
    223 264 def check_empty_passwords():
    224 265 """Check for empty passwords"""
    225 266
  • binarystor/trunk/src/python/dbalerter/daemon/dbalerter/checkos.py

     
    7 7 """
    8 8
    9 9 import os
    10 import config, notify
    10 11
    11 12 __author__ = "Alan Snelson"
    12 13 __copyright__ = "Copyright (c) 2010 Wave2 Limited"
     
    15 16 __version__ = "0.1.0"
    16 17
    17 18 supported = False
    19 mount_state = {}
    20
    18 21 sysname = os.uname()[0]
    19 22 if (sysname =='FreeBSD'):
    20 23 from checkfreebsd import *
    21 24 supported = True
    25
    26 def check():
    27 """Perform OS related checks"""
    28
    29 global supported
    30
    31 if (supported):
    32 pass
    33
  • binarystor/trunk/src/python/dbalerter/daemon/dbalerter/config.py

     
    30 30 if (not cfg.has_section('dbAlerter')):
    31 31 raise ConfigParser.NoSectionError('dbAlerter')
    32 32
    33 #Initialise configuration defaults
    33 #Initialise dbAlerter configuration defaults
    34 34 if (not cfg.has_option('dbAlerter', 'check_interval')):
    35 35 cfg.set('dbAlerter', 'check_interval', '42')
    36 36
    37 37 if (not cfg.has_option('dbAlerter', 'smtp_server')):
    38 38 cfg.set('dbAlerter', 'smtp_server', 'localhost')
    39 39
    40 #Initialise MySQL configuration defaults
    40 41 if (not cfg.has_option('dbAlerter', 'mysql_hostname')):
    41 42 cfg.set('dbAlerter', 'mysql_hostname', 'localhost')
    42 43
     
    58 59 if (not cfg.has_option('dbAlerter', 'mysql_open_files_threshold')):
    59 60 cfg.set('dbAlerter', 'mysql_open_files_threshold', '75')
    60 61
    62 if (not cfg.has_option('dbAlerter', 'mysql_plugindir_threshold')):
    63 cfg.set('dbAlerter', 'mysql_plugindir_threshold', '75')
    64
    61 65 if (not cfg.has_option('dbAlerter', 'mysql_tmpdir_threshold')):
    62 66 cfg.set('dbAlerter', 'mysql_tmpdir_threshold', '75')
    63 67