Skip to content

Adds skip_checks to providers #566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/system_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from enum import Enum
import subprocess
import psutil
import locale

from psycopg import OperationalError as psycopg_OperationalError

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

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

######## END CHECK FUNCTIONS ########

Expand All @@ -78,7 +81,8 @@ def check_docker_daemon():
(check_free_disk, Status.ERROR, '1GB free hdd space', 'We recommend to free up some disk space'),
(check_free_memory, Status.ERROR, 'free memory', 'No free memory! Please kill some programs'),
(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/]'),
(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/].'),
(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/].'),
(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.'),

]

Expand Down
7 changes: 5 additions & 2 deletions metric_providers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def __init__(
current_dir,
metric_provider_executable='metric-provider-binary',
sudo=False,
disable_buffer=True
disable_buffer=True,
skip_check=False,
):
self._metric_name = metric_name
self._metrics = metrics
Expand All @@ -33,6 +34,7 @@ def __init__(
self._has_started = False
self._disable_buffer = disable_buffer
self._rootless = None
self._skip_check = skip_check

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

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

self.check_system()
if not self._skip_check:
self.check_system()

# this is the default function that will be overridden in the children
def check_system(self):
Expand Down
3 changes: 2 additions & 1 deletion metric_providers/cpu/energy/RAPL/MSR/component/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from metric_providers.base import BaseMetricProvider

class CpuEnergyRaplMsrComponentProvider(BaseMetricProvider):
def __init__(self, resolution):
def __init__(self, resolution, skip_check=False):
super().__init__(
metric_name='cpu_energy_rapl_msr_component',
metrics={'time': int, 'value': int, 'package_id': str},
resolution=resolution,
unit='mJ',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check=skip_check,
)
3 changes: 2 additions & 1 deletion metric_providers/cpu/frequency/sysfs/core/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from metric_providers.base import MetricProviderConfigurationError, BaseMetricProvider

class CpuFrequencySysfsCoreProvider(BaseMetricProvider):
def __init__(self, resolution):
def __init__(self, resolution, skip_check=False):
super().__init__(
metric_name='cpu_frequency_sysfs_core',
metrics={'time': int, 'value': int, 'core_id': int},
resolution=0.001*resolution,
unit='Hz',
current_dir=os.path.dirname(os.path.abspath(__file__)),
metric_provider_executable='get-scaling-cur-freq.sh',
skip_check=skip_check,
)

def check_system(self):
Expand Down
3 changes: 2 additions & 1 deletion metric_providers/cpu/time/cgroup/container/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from metric_providers.base import BaseMetricProvider

class CpuTimeCgroupContainerProvider(BaseMetricProvider):
def __init__(self, resolution, rootless=False):
def __init__(self, resolution, rootless=False, skip_check=False):
super().__init__(
metric_name='cpu_time_cgroup_container',
metrics={'time': int, 'value': int, 'container_id': str},
resolution=resolution,
unit='us',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check=skip_check,
)
self._rootless = rootless
3 changes: 2 additions & 1 deletion metric_providers/cpu/time/cgroup/system/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from metric_providers.base import BaseMetricProvider

class CpuTimeCgroupSystemProvider(BaseMetricProvider):
def __init__(self, resolution):
def __init__(self, resolution, skip_check=False):
super().__init__(
metric_name='cpu_time_cgroup_system',
metrics={'time': int, 'value': int},
resolution=resolution,
unit='us',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check=skip_check,
)
3 changes: 2 additions & 1 deletion metric_providers/cpu/time/procfs/system/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from metric_providers.base import BaseMetricProvider

class CpuTimeProcfsSystemProvider(BaseMetricProvider):
def __init__(self, resolution):
def __init__(self, resolution, skip_check=False):
super().__init__(
metric_name='cpu_time_procfs_system',
metrics={'time': int, 'value': int},
resolution=resolution,
unit='us',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check = skip_check
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from metric_providers.base import BaseMetricProvider

class CpuUtilizationCgroupContainerProvider(BaseMetricProvider):
def __init__(self, resolution, rootless=False):
def __init__(self, resolution, rootless=False, skip_check=False):
super().__init__(
metric_name='cpu_utilization_cgroup_container',
metrics={'time': int, 'value': int, 'container_id': str},
resolution=resolution,
unit='Ratio',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check = skip_check,
)
self._rootless = rootless
3 changes: 2 additions & 1 deletion metric_providers/cpu/utilization/procfs/system/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from metric_providers.base import BaseMetricProvider

class CpuUtilizationProcfsSystemProvider(BaseMetricProvider):
def __init__(self, resolution):
def __init__(self, resolution, skip_check=False):
super().__init__(
metric_name='cpu_utilization_procfs_system',
metrics={'time': int, 'value': int},
resolution=resolution,
unit='Ratio',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check = skip_check,
)
3 changes: 2 additions & 1 deletion metric_providers/lm_sensors/abstract_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _create_options(self):
return ['-c'] + [f"'{i}'" for i in provider_config['chips']] \
+ ['-f'] + [f"'{i}'" for i in provider_config['features']]

def __init__(self, metric_name, resolution, unit):
def __init__(self, metric_name, resolution, unit, skip_check=False):
if __name__ == '__main__':
# If you run this on the command line you will need to set this in the config
# This is separate so it is always clear what config is used.
Expand All @@ -35,5 +35,6 @@ def __init__(self, metric_name, resolution, unit):
resolution=resolution,
unit=unit,
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check=skip_check,
)
self._extra_switches = self._create_options()
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@


class MemoryEnergyRaplMsrComponentProvider(BaseMetricProvider):
def __init__(self, resolution):
def __init__(self, resolution, skip_check=False):
super().__init__(
metric_name='memory_energy_rapl_msr_component',
metrics={'time': int, 'value': int, 'package_id': str},
resolution=resolution,
unit='mJ',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check=skip_check,
)
self._extra_switches = ['-d']
3 changes: 2 additions & 1 deletion metric_providers/memory/total/cgroup/container/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from metric_providers.base import BaseMetricProvider

class MemoryTotalCgroupContainerProvider(BaseMetricProvider):
def __init__(self, resolution, rootless=False):
def __init__(self, resolution, rootless=False, skip_check=False):
super().__init__(
metric_name='memory_total_cgroup_container',
metrics={'time': int, 'value': int, 'container_id': str},
resolution=resolution,
unit='Bytes',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check=skip_check,
)
self._rootless = rootless
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))

class NetworkConnectionsProxyContainerProvider(BaseMetricProvider):
def __init__(self, *, host_ip=None):

def __init__(self, *, host_ip=None, skip_check=False):
tinyproxy_path = subprocess.getoutput('which tinyproxy')

super().__init__(
Expand All @@ -24,7 +23,8 @@ def __init__(self, *, host_ip=None):
resolution=None,
unit=None,
current_dir=os.path.dirname(os.path.abspath(__file__)),
metric_provider_executable=f"{tinyproxy_path}"
skip_check=skip_check,
metric_provider_executable=f"{tinyproxy_path}",
)

self._conf_file = f"{CURRENT_DIR}/proxy_conf.conf"
Expand Down
3 changes: 2 additions & 1 deletion metric_providers/network/io/cgroup/container/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from metric_providers.base import BaseMetricProvider

class NetworkIoCgroupContainerProvider(BaseMetricProvider):
def __init__(self, resolution, rootless=False):
def __init__(self, resolution, rootless=False, skip_check=False):
super().__init__(
metric_name='network_io_cgroup_container',
metrics={'time': int, 'value': int, 'container_id': str},
resolution=resolution,
unit='Bytes',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check=skip_check,
)
self._rootless = rootless
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
from metric_providers.base import BaseMetricProvider

class NetworkIoDockerStatsContainerProvider(BaseMetricProvider):
def __init__(self, resolution):
def __init__(self, resolution, skip_check=False):
super().__init__(
metric_name='network_io_docker_stats_container',
metrics={'time': int, 'value': int, 'container_id': str},
resolution=resolution,
unit='Bytes',
current_dir=os.path.dirname(os.path.abspath(__file__)),
skip_check=skip_check,
)

def start_profiling(self, containers=None):
Expand Down
Loading