PHP 7.4.33
Preview: threshold.py Size: 1.48 KB
//lib/fm-agent/library/threshold.py

import logging
import operator
import sys
import time


class Threshold(object):
    def __init__(self, **kwargs):
        self.log = logging.getLogger(self.__class__.__name__)
        self.id = kwargs.get("id")
        # I renamed 'delay' to 'duration' to indicate that we're not delaying
        # reporting an exceeded threshold, but instead we're checking if it is
        # being exceded for a duration of time.
        self.duration = kwargs.get("delay", 0)
        # I renamed 'value' to 'limit' to distinguish it from the check value.
        self.limit = kwargs.get("value", 0)
        self.operator = kwargs.get("operator", None)
        self.reported = False

    # The logging library interferes with cPickle, so we must remove the logger
    # instance then reset it when we serialize/unserialize.
    def __getstate__(self):
        state = dict(self.__dict__)
        del state["log"]
        return state

    def __setstate__(self, state):
        self.__dict__.update(state)
        self.log = logging.getLogger(self.__class__.__name__)

    def limit_exceeded(self, value):
        if self.operator is None:
            self.log.debug("Threshold %s is a null threshold", self.id)
            return None

        operation = getattr(operator, self.operator)
        self.log.debug(
            "Testing if value (%.2f) is %s threshold %s's limit (%.2f)",
            value,
            self.operator,
            self.id,
            self.limit,
        )

        return operation(value, self.limit)

Directory Contents

Dirs: 1 × Files: 23

Name Size Perms Modified Actions
- drwxr-xr-x 2025-06-19 05:08:01
Edit Download
107.89 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
110 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download
9.19 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
14.82 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.17 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
807 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download
3.54 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.12 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.99 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
16.17 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
2.97 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.96 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
4.25 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
3.62 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.34 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
5.32 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
11.69 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
872 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download
874 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.99 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
3.23 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
1.48 KB lrw-r--r-- 2025-06-18 20:44:50
Edit Download
0 B lrw-r--r-- 2025-06-18 20:44:50
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).