Skip to content

Commit 26b1506

Browse files
ribalbaArneTR
andauthored
Adds skip_checks to providers (#566)
* Adds skip_checks to providers * Fixes the case where we want to allow pm to run * PR Feedback * trying to fix test * for arne * Fixing tests and corner cases * Some clarfications and more explicit calls * pylint fixes and better error handling * Services might be empty and is dict * System checks turned on * Unclear why tests fail - new try --------- Co-authored-by: Arne Tarara <[email protected]>
1 parent 6d071fe commit 26b1506

File tree

26 files changed

+201
-87
lines changed

26 files changed

+201
-87
lines changed

lib/system_checks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from enum import Enum
1313
import subprocess
1414
import psutil
15+
import locale
1516

1617
from psycopg import OperationalError as psycopg_OperationalError
1718

@@ -68,6 +69,8 @@ def check_docker_daemon():
6869
check=False, encoding='UTF-8')
6970
return result.returncode == 0
7071

72+
def check_utf_encoding():
73+
return locale.getpreferredencoding().lower() == sys.getdefaultencoding().lower() == 'utf-8'
7174

7275
######## END CHECK FUNCTIONS ########
7376

@@ -78,7 +81,8 @@ def check_docker_daemon():
7881
(check_free_disk, Status.ERROR, '1GB free hdd space', 'We recommend to free up some disk space'),
7982
(check_free_memory, Status.ERROR, 'free memory', 'No free memory! Please kill some programs'),
8083
(check_docker_daemon, Status.ERROR, 'docker daemon', 'The docker daemon could not be reached. Are you running in rootless mode or have added yourself to the docker group? See installation: [See https://docs.green-coding.berlin/docs/installation/]'),
81-
(check_containers_running, Status.WARN, 'Running containers', 'You have other containers running on the system. This is usually what you want in local development, but for undisturbed measurements consider going for a measurement cluster [See https://docs.green-coding.berlin/docs/installation/installation-cluster/].'),
84+
(check_containers_running, Status.WARN, 'running containers', 'You have other containers running on the system. This is usually what you want in local development, but for undisturbed measurements consider going for a measurement cluster [See https://docs.green-coding.berlin/docs/installation/installation-cluster/].'),
85+
(check_utf_encoding, Status.ERROR, 'utf file encoding', 'Your system encoding is not set to utf-8. This is needed as we need to parse console output.'),
8286

8387
]
8488

metric_providers/base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ def __init__(
2121
current_dir,
2222
metric_provider_executable='metric-provider-binary',
2323
sudo=False,
24-
disable_buffer=True
24+
disable_buffer=True,
25+
skip_check=False,
2526
):
2627
self._metric_name = metric_name
2728
self._metrics = metrics
@@ -33,6 +34,7 @@ def __init__(
3334
self._has_started = False
3435
self._disable_buffer = disable_buffer
3536
self._rootless = None
37+
self._skip_check = skip_check
3638

3739
self._tmp_folder = '/tmp/green-metrics-tool'
3840
self._ps = None
@@ -42,7 +44,8 @@ def __init__(
4244

4345
self._filename = f"{self._tmp_folder}/{self._metric_name}.log"
4446

45-
self.check_system()
47+
if not self._skip_check:
48+
self.check_system()
4649

4750
# this is the default function that will be overridden in the children
4851
def check_system(self):

metric_providers/cpu/energy/RAPL/MSR/component/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
from metric_providers.base import BaseMetricProvider
44

55
class CpuEnergyRaplMsrComponentProvider(BaseMetricProvider):
6-
def __init__(self, resolution):
6+
def __init__(self, resolution, skip_check=False):
77
super().__init__(
88
metric_name='cpu_energy_rapl_msr_component',
99
metrics={'time': int, 'value': int, 'package_id': str},
1010
resolution=resolution,
1111
unit='mJ',
1212
current_dir=os.path.dirname(os.path.abspath(__file__)),
13+
skip_check=skip_check,
1314
)

metric_providers/cpu/frequency/sysfs/core/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from metric_providers.base import MetricProviderConfigurationError, BaseMetricProvider
44

55
class CpuFrequencySysfsCoreProvider(BaseMetricProvider):
6-
def __init__(self, resolution):
6+
def __init__(self, resolution, skip_check=False):
77
super().__init__(
88
metric_name='cpu_frequency_sysfs_core',
99
metrics={'time': int, 'value': int, 'core_id': int},
1010
resolution=0.001*resolution,
1111
unit='Hz',
1212
current_dir=os.path.dirname(os.path.abspath(__file__)),
1313
metric_provider_executable='get-scaling-cur-freq.sh',
14+
skip_check=skip_check,
1415
)
1516

1617
def check_system(self):

metric_providers/cpu/time/cgroup/container/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
from metric_providers.base import BaseMetricProvider
44

55
class CpuTimeCgroupContainerProvider(BaseMetricProvider):
6-
def __init__(self, resolution, rootless=False):
6+
def __init__(self, resolution, rootless=False, skip_check=False):
77
super().__init__(
88
metric_name='cpu_time_cgroup_container',
99
metrics={'time': int, 'value': int, 'container_id': str},
1010
resolution=resolution,
1111
unit='us',
1212
current_dir=os.path.dirname(os.path.abspath(__file__)),
13+
skip_check=skip_check,
1314
)
1415
self._rootless = rootless

metric_providers/cpu/time/cgroup/system/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
from metric_providers.base import BaseMetricProvider
44

55
class CpuTimeCgroupSystemProvider(BaseMetricProvider):
6-
def __init__(self, resolution):
6+
def __init__(self, resolution, skip_check=False):
77
super().__init__(
88
metric_name='cpu_time_cgroup_system',
99
metrics={'time': int, 'value': int},
1010
resolution=resolution,
1111
unit='us',
1212
current_dir=os.path.dirname(os.path.abspath(__file__)),
13+
skip_check=skip_check,
1314
)

metric_providers/cpu/time/procfs/system/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
from metric_providers.base import BaseMetricProvider
44

55
class CpuTimeProcfsSystemProvider(BaseMetricProvider):
6-
def __init__(self, resolution):
6+
def __init__(self, resolution, skip_check=False):
77
super().__init__(
88
metric_name='cpu_time_procfs_system',
99
metrics={'time': int, 'value': int},
1010
resolution=resolution,
1111
unit='us',
1212
current_dir=os.path.dirname(os.path.abspath(__file__)),
13+
skip_check = skip_check
1314
)

metric_providers/cpu/utilization/cgroup/container/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
from metric_providers.base import BaseMetricProvider
44

55
class CpuUtilizationCgroupContainerProvider(BaseMetricProvider):
6-
def __init__(self, resolution, rootless=False):
6+
def __init__(self, resolution, rootless=False, skip_check=False):
77
super().__init__(
88
metric_name='cpu_utilization_cgroup_container',
99
metrics={'time': int, 'value': int, 'container_id': str},
1010
resolution=resolution,
1111
unit='Ratio',
1212
current_dir=os.path.dirname(os.path.abspath(__file__)),
13+
skip_check = skip_check,
1314
)
1415
self._rootless = rootless

metric_providers/cpu/utilization/procfs/system/provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
from metric_providers.base import BaseMetricProvider
44

55
class CpuUtilizationProcfsSystemProvider(BaseMetricProvider):
6-
def __init__(self, resolution):
6+
def __init__(self, resolution, skip_check=False):
77
super().__init__(
88
metric_name='cpu_utilization_procfs_system',
99
metrics={'time': int, 'value': int},
1010
resolution=resolution,
1111
unit='Ratio',
1212
current_dir=os.path.dirname(os.path.abspath(__file__)),
13+
skip_check = skip_check,
1314
)

metric_providers/lm_sensors/abstract_provider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _create_options(self):
2222
return ['-c'] + [f"'{i}'" for i in provider_config['chips']] \
2323
+ ['-f'] + [f"'{i}'" for i in provider_config['features']]
2424

25-
def __init__(self, metric_name, resolution, unit):
25+
def __init__(self, metric_name, resolution, unit, skip_check=False):
2626
if __name__ == '__main__':
2727
# If you run this on the command line you will need to set this in the config
2828
# This is separate so it is always clear what config is used.
@@ -35,5 +35,6 @@ def __init__(self, metric_name, resolution, unit):
3535
resolution=resolution,
3636
unit=unit,
3737
current_dir=os.path.dirname(os.path.abspath(__file__)),
38+
skip_check=skip_check,
3839
)
3940
self._extra_switches = self._create_options()

0 commit comments

Comments
 (0)