From af7232abc8532fde133ca1726e0f70db30ad2c2b Mon Sep 17 00:00:00 2001 From: dettlaff Date: Wed, 17 Jul 2024 21:02:58 +0400 Subject: [PATCH] feat: add prometheus as a service --- .../services/prometheus/__init__.py | 90 +++++++++++++++++++ selfprivacy_api/services/prometheus/icon.py | 5 ++ .../services/prometheus/prometheus.svg | 10 +++ 3 files changed, 105 insertions(+) create mode 100644 selfprivacy_api/services/prometheus/__init__.py create mode 100644 selfprivacy_api/services/prometheus/icon.py create mode 100644 selfprivacy_api/services/prometheus/prometheus.svg diff --git a/selfprivacy_api/services/prometheus/__init__.py b/selfprivacy_api/services/prometheus/__init__.py new file mode 100644 index 0000000..a7516f5 --- /dev/null +++ b/selfprivacy_api/services/prometheus/__init__.py @@ -0,0 +1,90 @@ +"""Class representing Nextcloud service.""" + +import base64 +import subprocess +from typing import Optional, List + +from selfprivacy_api.services.owned_path import OwnedPath +from selfprivacy_api.utils.systemd import get_service_status +from selfprivacy_api.services.service import Service, ServiceStatus + +from selfprivacy_api.services.prometheus.icon import PROMETHEUS_ICON + + +class Prometheus(Service): + """Class representing Pleroma service.""" + + @staticmethod + def get_id() -> str: + return "prometheus" + + @staticmethod + def get_display_name() -> str: + return "Prometheus" + + @staticmethod + def get_description() -> str: + return "Prometheus is a free software application used for event monitoring and alerting." + + @staticmethod + def get_svg_icon() -> str: + return base64.b64encode(PROMETHEUS_ICON.encode("utf-8")).decode("utf-8") + + @staticmethod + def get_url() -> Optional[str]: + """Return service url.""" + return None + + @staticmethod + def get_subdomain() -> Optional[str]: + return None + + @staticmethod + def is_movable() -> bool: + return False + + @staticmethod + def is_required() -> bool: + return True + + @staticmethod + def get_backup_description() -> str: + return "For Prometheus backups are not available." + + @staticmethod + def get_status() -> ServiceStatus: + return get_service_status("prometheus.service") + + @staticmethod + def stop(): + subprocess.run(["systemctl", "stop", "prometheus.service"]) + + @staticmethod + def start(): + subprocess.run(["systemctl", "start", "prometheus.service"]) + + @staticmethod + def restart(): + subprocess.run(["systemctl", "restart", "prometheus.service"]) + + @staticmethod + def get_configuration(config_items): + return {} + + @staticmethod + def set_configuration(config_items): + return super().set_configuration(config_items) + + @staticmethod + def get_logs(): + return "" + + @staticmethod + def get_owned_folders() -> List[OwnedPath]: + return [ + OwnedPath( + path="/var/lib/prometheus", + owner="prometheus", + group="prometheus", + ), + ] diff --git a/selfprivacy_api/services/prometheus/icon.py b/selfprivacy_api/services/prometheus/icon.py new file mode 100644 index 0000000..8e46e15 --- /dev/null +++ b/selfprivacy_api/services/prometheus/icon.py @@ -0,0 +1,5 @@ +PROMETHEUS_ICON = """ + + + +""" diff --git a/selfprivacy_api/services/prometheus/prometheus.svg b/selfprivacy_api/services/prometheus/prometheus.svg new file mode 100644 index 0000000..f87c438 --- /dev/null +++ b/selfprivacy_api/services/prometheus/prometheus.svg @@ -0,0 +1,10 @@ + + + + + + + + + +