def create_metrics(platform: Platform) -> List[Metric]: """Creates a list of Metric objects from data in Platform object""" platform_metrics = list() platform_metrics.append( Metric.create_metric_with_metadata(name=MetricName.MEM_USAGE, value=platform.total_memory_used)) for cpu_id, cpu_usage in platform.cpus_usage.items(): platform_metrics.append( Metric.create_metric_with_metadata( name=MetricName.CPU_USAGE_PER_CPU, value=cpu_usage, labels={"cpu": str(cpu_id)})) return platform_metrics
def create_metrics(task_measurements: Measurements) -> List[Metric]: """Prepare a list of metrics for a mesos tasks based on provided measurements applying common_labels. :param task_measurements: use values of measurements to create metrics """ metrics = [] for metric_name, metric_value in task_measurements.items(): metric = Metric.create_metric_with_metadata(name=metric_name, value=metric_value) metrics.append(metric) return metrics
def test_collect_platform_information(*mocks): assert collect_platform_information() == (Platform(1, 1, 2, { 0: 100, 1: 200 }, 1337, 1536071557.123456), [ Metric.create_metric_with_metadata(name=MetricName.MEM_USAGE, value=1337), Metric.create_metric_with_metadata(name=MetricName.CPU_USAGE_PER_CPU, value=100, labels={"cpu": "0"}), Metric.create_metric_with_metadata(name=MetricName.CPU_USAGE_PER_CPU, value=200, labels={"cpu": "1"}), ], { "sockets": "1", "cores": "1", "cpus": "2", "host": "test_host", "owca_version": "0.1" })