Exemplo n.º 1
0
    def _add_or_update(self, name, value, req_id, unit, metrics_method=None, dimensions=None):
        """
        Add a metric key value pair

        Parameters
        ----------
        name : str
            metric name
        value: int, float
            value of metric
        req_id: str
            request id
        unit: str
            unit of metric
        value: int, float , str
            value of metric
        metrics_method: str, optional
            indicates type of metric operation if it is defined
        """
        # IF req_id is none error Metric
        if dimensions is None:
            dimensions = list()
        elif not isinstance(dimensions, list):
            raise ValueError("Please provide a list of dimensions")
        if req_id is None:
            dimensions.append(Dimension("Level", "Error"))
        else:
            dimensions.append(Dimension("ModelName", self.model_name))
            dimensions.append(Dimension("Level", "Model"))

        # Cache the metric with an unique key for update
        dim_str = [name, unit, str(req_id)] + [str(d) for d in dimensions]
        dim_str = '-'.join(dim_str)
        if dim_str not in self.cache:
            metric = Metric(name, value, unit, dimensions, req_id, metrics_method)
            self.store.append(metric)
            self.cache[dim_str] = metric
        else:
            self.cache[dim_str].update(value)
def disk_available():
    data = psutil.disk_usage('/').free / (1024 * 1024 * 1024)  # in GB
    system_metrics.append(Metric('DiskAvailable', data, 'GB', dimension))
def disk_utilization():
    data = psutil.disk_usage('/').percent
    system_metrics.append(Metric('DiskUtilization', data, 'percent', dimension))
def disk_used():
    data = psutil.disk_usage('/').used / (1024 * 1024 * 1024)  # in GB
    system_metrics.append(Metric('DiskUsage', data, 'GB', dimension))
def memory_utilization():
    data = psutil.virtual_memory().percent
    system_metrics.append(Metric('MemoryUtilization', data, 'percent', dimension))
def memory_available():
    data = psutil.virtual_memory().available / (1024 * 1024)  # in MB
    system_metrics.append(Metric('MemoryAvailable', data, 'MB', dimension))
def memory_used():
    data = psutil.virtual_memory().used / (1024 * 1024)  # in MB
    system_metrics.append(Metric('MemoryUsed', data, 'MB', dimension))
def cpu_utilization():
    data = psutil.cpu_percent()
    system_metrics.append(Metric('CPUUtilization', data, 'percent', dimension))