Example #1
0
def get_disk_anomaly_conditions(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
    threshold_free_ramdisk_megabytes = 1
    free_disk_megabytes = free_workdir_bytes / (1024 * 1024)
    free_disk_percentage = free_workdir_bytes / (total_workdir_bytes / 100)
    free_ramdisk_megabytes = free_ramdisk_bytes / (1024 * 1024)
    free_workdir_string = bytes_to_pretty_str(free_workdir_bytes)
    free_ramdisk_string = bytes_to_pretty_str(free_ramdisk_bytes)
    total_workdir_string = bytes_to_pretty_str(total_workdir_bytes)
    total_ramdisk_string = bytes_to_pretty_str(total_ramdisk_bytes)

    def info_msg_0():
        return "free_disk_megabytes <= %d or free_disk_percentage <= %d" % \
            (GLSettings.memory_copy.threshold_free_disk_megabytes_high,
             GLSettings.memory_copy.threshold_free_disk_percentage_high)

    def info_msg_1():
        return "free_ramdisk_megabytes <= %d" % threshold_free_ramdisk_megabytes

    def info_msg_2():
        return "free_disk_megabytes <= %d or free_disk_percentage <= %d" % \
            (GLSettings.memory_copy.threshold_free_disk_megabytes_medium,
             GLSettings.memory_copy.threshold_free_disk_percentage_medium)

    def info_msg_3():
        return "free_disk_megabytes <= %d or free_disk_percentage <= %d" % \
            (GLSettings.memory_copy.threshold_free_disk_megabytes_low,
             GLSettings.memory_copy.threshold_free_disk_percentage_low)

    # list of bad conditions ordered starting from the worst case scenario
    conditions = [
        {
            'condition': free_disk_megabytes <= GLSettings.memory_copy.threshold_free_disk_megabytes_high or \
                         free_disk_percentage <= GLSettings.memory_copy.threshold_free_disk_percentage_high,
            'info_msg': info_msg_0,
            'stress_level': 3,
            'accept_submissions': False
        },
        {
            'condition': free_ramdisk_megabytes <= threshold_free_ramdisk_megabytes,
            'info_msg': info_msg_1,
            'stress_level': 3,
            'accept_submissions': False
        },
        {
            'condition': free_disk_megabytes <= GLSettings.memory_copy.threshold_free_disk_megabytes_medium or \
                         free_disk_percentage <= GLSettings.memory_copy.threshold_free_disk_percentage_medium,
            'info_msg': info_msg_2,
            'stress_level': 2,
            'accept_submissions': True
        },
        {
            'condition': free_disk_megabytes <= GLSettings.memory_copy.threshold_free_disk_megabytes_low or \
                         free_disk_percentage <= GLSettings.memory_copy.threshold_free_disk_percentage_low,
            'info_msg': info_msg_3,
            'stress_level': 1,
            'accept_submissions': True
        }
    ]

    return conditions
Example #2
0
def get_disk_anomaly_conditions(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
    free_disk_megabytes = free_workdir_bytes / (1024 * 1024)
    free_disk_percentage = free_workdir_bytes / (total_workdir_bytes / 100)
    free_workdir_string = bytes_to_pretty_str(free_workdir_bytes)
    free_ramdisk_string = bytes_to_pretty_str(free_ramdisk_bytes)
    total_workdir_string = bytes_to_pretty_str(total_workdir_bytes)
    total_ramdisk_string = bytes_to_pretty_str(total_ramdisk_bytes)

    def info_msg_0(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "free_disk_megabytes <= 300 or free_disk_percentage <= 3"

    def info_msg_1(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "free_ramdisk_bytes <= 2048"

    def info_msg_2(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "free_disk_megabytes <= 500 or free_disk_percentage <= 5"

    def info_msg_3(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "free_disk_megabytes <= 1000 or free_disk_percentage <= 10"

    # list of bad conditions ordered starting from the worst case scenario
    conditions = [
        {
            'condition': free_disk_megabytes <= 300 or free_disk_percentage <= 3,
            'info_msg': info_msg_0,
            'stress_level': 3,
            'accept_submissions': False
        },
        {
            'condition': free_ramdisk_bytes <= 2048,
            'info_msg': info_msg_1,
            'stress_level': 3,
            'accept_submissions': False
        },
        {
            'condition': free_disk_megabytes <= 500 or free_disk_percentage <= 5,
            'info_msg': info_msg_2,
            'stress_level': 2,
            'accept_submissions': True
        },
        {
            'condition': free_disk_megabytes <= 1000 or free_disk_percentage <= 10,
            'info_msg': info_msg_3,
            'stress_level': 1,
            'accept_submissions': True
        }
    ]

    return conditions
Example #3
0
    def report_disk_usage(self, free_bytes):
        """
        Here in Alarm is written the threshold to say if we're in disk alarm
        or not. Therefore the function "report" the amount of free space and
        the evaluation + alarm shift is performed here.
        """

        # Mediam alarm threshold
        mat = Alarm._MEDIUM_DISK_ALARM * GLSetting.memory_copy.maximum_filesize
        hat = Alarm._HIGH_DISK_ALARM * GLSetting.memory_copy.maximum_filesize

        Alarm.latest_measured_freespace = free_bytes

        free_megabytes = free_bytes / (1000 * 1000)

        free_memory_str = bytes_to_pretty_str(free_bytes)

        if free_megabytes < hat:
            log.err("Warning: free space alarm (HIGH): only %s" %
                    free_memory_str)
            Alarm.stress_levels['disk_space'] = 2
        elif free_megabytes < mat:
            log.info("Warning: free space alarm (MEDIUM): %s" %
                     free_memory_str)
            Alarm.stress_levels['disk_space'] = 1
        else:
            Alarm.stress_levels['disk_space'] = 0
Example #4
0
 def test_bytes_to_pretty_str(self):
     self.assertEqual(utility.bytes_to_pretty_str("60000000001"), "60GB")
     self.assertEqual(utility.bytes_to_pretty_str("5000000001"), "5GB")
     self.assertEqual(utility.bytes_to_pretty_str("40000001"), "40MB")
     self.assertEqual(utility.bytes_to_pretty_str("3000001"), "3MB")
     self.assertEqual(utility.bytes_to_pretty_str("20001"), "20KB")
     self.assertEqual(utility.bytes_to_pretty_str("1001"), "1KB")
Example #5
0
 def test_bytes_to_pretty_str(self):
     self.assertEqual(utility.bytes_to_pretty_str("60000000001"), "60GB")
     self.assertEqual(utility.bytes_to_pretty_str("5000000001"), "5GB")
     self.assertEqual(utility.bytes_to_pretty_str("40000001"), "40MB")
     self.assertEqual(utility.bytes_to_pretty_str("3000001"), "3MB")
     self.assertEqual(utility.bytes_to_pretty_str("20001"), "20KB")
     self.assertEqual(utility.bytes_to_pretty_str("1001"), "1KB")
Example #6
0
 def TotalMemory(self):
     return "%s" % bytes_to_pretty_str(self.data["alert"]["latest_measured_totalspace"])
Example #7
0
 def TotalMemory(self):
     return '%s' % bytes_to_pretty_str(
         self.data['alert']['measured_totalspace'])
Example #8
0
 def FreeMemory(self):
     return '%s' % bytes_to_pretty_str(
         self.data['alert']['measured_freespace'])
Example #9
0
def get_disk_anomaly_conditions(free_workdir_bytes, total_workdir_bytes,
                                free_ramdisk_bytes, total_ramdisk_bytes):
    threshold_free_ramdisk_megabytes = 1
    free_disk_megabytes = free_workdir_bytes / (1024 * 1024)
    free_disk_percentage = free_workdir_bytes / (total_workdir_bytes / 100)
    free_ramdisk_megabytes = free_ramdisk_bytes / (1024 * 1024)
    free_workdir_string = bytes_to_pretty_str(free_workdir_bytes)
    free_ramdisk_string = bytes_to_pretty_str(free_ramdisk_bytes)
    total_workdir_string = bytes_to_pretty_str(total_workdir_bytes)
    total_ramdisk_string = bytes_to_pretty_str(total_ramdisk_bytes)

    def info_msg_0():
        return "free_disk_megabytes <= %d or free_disk_percentage <= %d" % \
            (GLSettings.memory_copy.threshold_free_disk_megabytes_high,
             GLSettings.memory_copy.threshold_free_disk_percentage_high)

    def info_msg_1():
        return "free_ramdisk_megabytes <= %d" % threshold_free_ramdisk_megabytes

    def info_msg_2():
        return "free_disk_megabytes <= %d or free_disk_percentage <= %d" % \
            (GLSettings.memory_copy.threshold_free_disk_megabytes_medium,
             GLSettings.memory_copy.threshold_free_disk_percentage_medium)

    def info_msg_3():
        return "free_disk_megabytes <= %d or free_disk_percentage <= %d" % \
            (GLSettings.memory_copy.threshold_free_disk_megabytes_low,
             GLSettings.memory_copy.threshold_free_disk_percentage_low)

    # list of bad conditions ordered starting from the worst case scenario
    conditions = [
        {
            'condition': free_disk_megabytes <= GLSettings.memory_copy.threshold_free_disk_megabytes_high or \
                         free_disk_percentage <= GLSettings.memory_copy.threshold_free_disk_percentage_high,
            'info_msg': info_msg_0,
            'stress_level': 3,
            'accept_submissions': False
        },
        {
            'condition': free_ramdisk_megabytes <= threshold_free_ramdisk_megabytes,
            'info_msg': info_msg_1,
            'stress_level': 3,
            'accept_submissions': False
        },
        {
            'condition': free_disk_megabytes <= GLSettings.memory_copy.threshold_free_disk_megabytes_medium or \
                         free_disk_percentage <= GLSettings.memory_copy.threshold_free_disk_percentage_medium,
            'info_msg': info_msg_2,
            'stress_level': 2,
            'accept_submissions': True
        },
        {
            'condition': free_disk_megabytes <= GLSettings.memory_copy.threshold_free_disk_megabytes_low or \
                         free_disk_percentage <= GLSettings.memory_copy.threshold_free_disk_percentage_low,
            'info_msg': info_msg_3,
            'stress_level': 1,
            'accept_submissions': True
        }
    ]

    return conditions
Example #10
0
 def _total_disk_space(notification_dict):
     return "%s" % bytes_to_pretty_str(Alarm.latest_measured_totalspace)
Example #11
0
 def TotalMemory(self):
     return "%s" % bytes_to_pretty_str(
         self.data['alert']['latest_measured_totalspace'])
Example #12
0
 def FreeMemory(self):
     return "%s" % bytes_to_pretty_str(self.data['alert']['latest_measured_freespace'])
Example #13
0
 def _total_disk_space():
     return "%s" % bytes_to_pretty_str(Alarm.latest_measured_totalspace)
Example #14
0
 def _free_disk_space():
     return "%s" % bytes_to_pretty_str(Alarm.latest_measured_freespace)
Example #15
0
def get_disk_anomaly_conditions(free_workdir_bytes, total_workdir_bytes,
                                free_ramdisk_bytes, total_ramdisk_bytes):
    free_disk_megabytes = free_workdir_bytes / (1024 * 1024)
    free_disk_percentage = free_workdir_bytes / (total_workdir_bytes / 100)
    free_workdir_string = bytes_to_pretty_str(free_workdir_bytes)
    free_ramdisk_string = bytes_to_pretty_str(free_ramdisk_bytes)
    total_workdir_string = bytes_to_pretty_str(total_workdir_bytes)
    total_ramdisk_string = bytes_to_pretty_str(total_ramdisk_bytes)

    def info_msg_0(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes,
                   total_ramdisk_bytes):
        return "free_disk_megabytes <= 300 or free_disk_percentage <= 3"

    def info_msg_1(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes,
                   total_ramdisk_bytes):
        return "free_ramdisk_bytes <= 2048"

    def info_msg_2(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes,
                   total_ramdisk_bytes):
        return "free_disk_megabytes <= 500 or free_disk_percentage <= 5"

    def info_msg_3(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes,
                   total_ramdisk_bytes):
        return "free_disk_megabytes <= 1000 or free_disk_percentage <= 10"

    # list of bad conditions ordered starting from the worst case scenario
    conditions = [{
        'condition':
        free_disk_megabytes <= 300 or free_disk_percentage <= 3,
        'info_msg':
        info_msg_0,
        'stress_level':
        3,
        'accept_submissions':
        False
    }, {
        'condition': free_ramdisk_bytes <= 2048,
        'info_msg': info_msg_1,
        'stress_level': 3,
        'accept_submissions': False
    }, {
        'condition':
        free_disk_megabytes <= 500 or free_disk_percentage <= 5,
        'info_msg':
        info_msg_2,
        'stress_level':
        2,
        'accept_submissions':
        True
    }, {
        'condition':
        free_disk_megabytes <= 1000 or free_disk_percentage <= 10,
        'info_msg':
        info_msg_3,
        'stress_level':
        1,
        'accept_submissions':
        True
    }]

    return conditions
Example #16
0
 def TotalMemory(self):
     return '%s' % bytes_to_pretty_str(self.data['alert']['measured_totalspace'])
Example #17
0
 def FreeMemory(self):
     return '%s' % bytes_to_pretty_str(self.data['alert']['measured_freespace'])
Example #18
0
def get_disk_anomaly_conditions(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
    free_disk_megabytes = free_workdir_bytes / (1024 * 1024)
    free_disk_percentage = free_workdir_bytes / (total_workdir_bytes / 100)
    free_workdir_string = bytes_to_pretty_str(free_workdir_bytes)
    free_ramdisk_string = bytes_to_pretty_str(free_ramdisk_bytes)
    total_workdir_string = bytes_to_pretty_str(total_workdir_bytes)

    def info_msg_0(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "Disk space < 1%%: %s on %s" % (total_workdir_string, free_workdir_string)

    def info_msg_1(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "Minimum space available of %d Mb reached: (%s on %s)" % \
                (GLSetting.defaults.minimum_megabytes_required,
                total_workdir_string,
                free_workdir_string)

    def info_msg_2(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "Ramdisk space not enough space (%s): required 2Kb" % free_ramdisk_string

    def info_msg_3(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "Disk space ~ 2%% (Critical when reach 1%%): %s on %s" % \
                (total_workdir_string, free_workdir_string)

    def info_msg_4(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "Minimum space available of %d Mb is near: (%s on %s)" % \
                (GLSetting.defaults.minimum_megabytes_required,
                 total_workdir_string,
                 free_workdir_string)

    def info_msg_5(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "Disk space permit maximum of %d uploads (%s on %s)" % \
                (Alarm._HIGH_DISK_ALARM, total_workdir_string, free_workdir_string)

    def info_msg_6(free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        return "Disk space permit maximum of %d uploads (%s on %s)" % \
                (Alarm._MEDIUM_DISK_ALARM, total_workdir_string, free_workdir_string)

    # list of bad conditions ordered starting from the worst case scenario
    conditions = [
        {
            # If percentage is <= 1%: disable the submission
            'condition': free_disk_percentage <= 1,
            'info_msg': info_msg_0,
            'stress_level': 3,
            'accept_submissions': False,
        },
        {
            # If disk has less than the hardcoded minimum amount (1Gb)
            'condition': free_disk_megabytes <= GLSetting.defaults.minimum_megabytes_required,
            'info_msg': info_msg_1,
            'stress_level': 3,
            'accept_submissions': False,
        },
        {
            # If ramdisk has less than 2kbytes
            'condition': free_ramdisk_bytes <= 2048,
            'info_msg': info_msg_2,
            'stress_level': 3,
            'accept_submissions': False,
        },
        {
            # If percentage is 2% start to alert the admin on the upcoming critical situation
            'condition': free_disk_percentage == 2,
            'info_msg': info_msg_3,
            'stress_level': 2,
            'accept_submissions': True,
        },
        {
            # Again to avoid bad surprise, we alert the admin at (minimum disk required * 2)
            'condition': free_disk_megabytes <= (GLSetting.defaults.minimum_megabytes_required * 2),
            'info_msg': info_msg_4,
            'stress_level': 2,
            'accept_submissions': True,
        },
        {
            # if 5 times maximum file can be accepted
            'condition': free_disk_megabytes <= (Alarm._HIGH_DISK_ALARM * GLSetting.memory_copy.maximum_filesize),
            'info_msg': info_msg_5,
            'stress_level': 2,
            'accept_submissions': True,
        },
        {
            # if 15 times maximum file size can be accepted
            'condition': free_disk_megabytes <= (Alarm._MEDIUM_DISK_ALARM * GLSetting.memory_copy.maximum_filesize),
            'info_msg': info_msg_6,
            'stress_level': 1,
            'accept_submissions': True,
        }
    ]

    return conditions
Example #19
0
 def _disk_dump():
     return "%s" % bytes_to_pretty_str(Alarm.latest_measured_freespace)
Example #20
0
 def TotalMemory(self):
     return "%s" % bytes_to_pretty_str(self.data['alert']['latest_measured_totalspace'])
Example #21
0
 def FreeMemory(self):
     return "%s" % bytes_to_pretty_str(
         self.data['alert']['latest_measured_freespace'])
Example #22
0
 def FreeMemory(self):
     return "%s" % bytes_to_pretty_str(self.data["alert"]["latest_measured_freespace"])
Example #23
0
 def _total_disk_space():
     return "%s" % bytes_to_pretty_str(Alarm.latest_measured_totalspace)
Example #24
0
 def _total_disk_space(notification_dict):
     return "%s" % bytes_to_pretty_str(Alarm.latest_measured_totalspace)