18 from typing
import Tuple, Dict, List
23 from ...entities
import MetricType, TaskRun, Metric
24 from ...entities.task_run.metrics
import metric_factory
27 def _getMetrics() -> List[Metric]:
29 metric_factory.createMetric(
"cpu_usage",
"time (s)", MetricType.interval,
"usage (%)", MetricType.percent,
None, [0, 100]),
30 metric_factory.createMetric(
"ram_usage",
"time (s)", MetricType.interval,
"usage (%)", MetricType.percent,
None, [0, 100]),
31 metric_factory.createMetric(
"swap_usage",
"time (s)", MetricType.interval,
"usage (%)", MetricType.percent,
None, [0, 100]),
32 metric_factory.createMetric(
"download_speed",
"time (s)", MetricType.interval,
"bytes", MetricType.bytes),
33 metric_factory.createMetric(
"upload_speed",
"time (s)", MetricType.interval,
"bytes", MetricType.bytes),
34 metric_factory.createMetric(
"disk_read",
"time (s)", MetricType.interval,
"bytes", MetricType.bytes),
35 metric_factory.createMetric(
"disk_write",
"time (s)", MetricType.interval,
"bytes", MetricType.bytes)
40 from py3nvml
import py3nvml
46 metric_factory.createMetric(
"gpu_usage",
"time (s)", MetricType.interval,
"usage (%)", MetricType.percent,
None, [0, 100]),
47 metric_factory.createMetric(
"gpu_temperature",
"time (s)", MetricType.interval,
"usage (%)", MetricType.percent),
48 metric_factory.createMetric(
"gpu_memory_usage",
"time (s)", MetricType.interval,
"usage (%)", MetricType.percent,
None, [0, 100])
51 logging.getLogger(
"coretexpylib").debug(
">> [Coretex] Initialized GPU metrics")
53 logging.getLogger(
"coretexpylib").debug(
">> [Coretex] Failed to initialize GPU metrics")
58 def create(taskRun: TaskRun) ->
None:
59 taskRun.createMetrics(_getMetrics())
62 def upload(taskRun: TaskRun) ->
None:
64 metricValues: Dict[str, Tuple[float, float]] = {}
66 for metric
in taskRun.metrics:
67 metricValue = metric.extract()
69 if metricValue
is not None:
70 metricValues[metric.name] = x, metricValue
72 taskRun.submitMetrics(metricValues)