Skip to content

Commit

Permalink
Refactor show stats and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ycedres committed Oct 10, 2024
1 parent 9ac0bcc commit 3fece3d
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 329 deletions.
10 changes: 10 additions & 0 deletions health-check/src/uyuni_health_check/config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[podman]
network_name = "health-check-network"

[loki]
loki_container_name = uyuni_health_check_loki
loki_port = 3100

[logcli]
logcli_container_name = uyuni_health_check_logcli
logcli_image_name = logcli
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
supportconfig_path: /home/ygutierrez/Documents/L3/1227859/scc_lxms-cp-suma01_240828_1131
supportconfig_path: /home/ygutierrez/Documents/L3/1230944/scc_s3p3238_240916_1049
port: 9000
scrape_frequency: 60
16 changes: 8 additions & 8 deletions health-check/src/uyuni_health_check/config/promtail/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ scrape_configs:
- localhost
labels:
job: cobbler
__path__: /home/ygutierrez/Documents/L3/1227859/scc_lxms-cp-suma01_240828_1131/spacewalk-debug/cobbler-logs/cobbler.log
__path__: /home/ygutierrez/Documents/L3/1230944/scc_s3p3238_240916_1049/spacewalk-debug/cobbler-logs/cobbler.log
pipeline_stages:
- multiline:
firstline: '^\[.*\] [\dT:-]+ - [A-Z]+ | '
Expand All @@ -34,7 +34,7 @@ scrape_configs:
- localhost
labels:
job: postgresql
__path__: /home/ygutierrez/Documents/L3/1227859/scc_lxms-cp-suma01_240828_1131/spacewalk-debug/database//postgresql*.log*
__path__: /home/ygutierrez/Documents/L3/1230944/scc_s3p3238_240916_1049/spacewalk-debug/database//postgresql*.log*
pipeline_stages:
- multiline:
firstline: '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}.\d{3} \S+ '
Expand All @@ -53,7 +53,7 @@ scrape_configs:
- localhost
labels:
job: salt
__path__: /home/ygutierrez/Documents/L3/1227859/scc_lxms-cp-suma01_240828_1131/spacewalk-debug/salt-logs/salt/{api,master}
__path__: /home/ygutierrez/Documents/L3/1230944/scc_s3p3238_240916_1049/spacewalk-debug/salt-logs/salt/{api,master}
pipeline_stages:
- multiline:
firstline: '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(,)\d{3} '
Expand Down Expand Up @@ -89,33 +89,33 @@ scrape_configs:
labels:
job: rhn
component: tomcat
__path__: /home/ygutierrez/Documents/L3/1227859/scc_lxms-cp-suma01_240828_1131/spacewalk-debug/rhn-logs/rhn/rhn_{salt,web}_*log
__path__: /home/ygutierrez/Documents/L3/1230944/scc_s3p3238_240916_1049/spacewalk-debug/rhn-logs/rhn/rhn_{salt,web}_*log
- targets:
- localhost
labels:
job: rhn
component: taskomatic
__path__: /home/ygutierrez/Documents/L3/1227859/scc_lxms-cp-suma01_240828_1131/spacewalk-debug/rhn-logs/rhn/rhn_taskomatic_*log
__path__: /home/ygutierrez/Documents/L3/1230944/scc_s3p3238_240916_1049/spacewalk-debug/rhn-logs/rhn/rhn_taskomatic_*log
- job_name: apache
static_configs:
- targets:
- localhost
labels:
job: apache
component: error_log
__path__: /home/ygutierrez/Documents/L3/1227859/scc_lxms-cp-suma01_240828_1131/spacewalk-debug/httpd-logs/apache2/error_log*
__path__: /home/ygutierrez/Documents/L3/1230944/scc_s3p3238_240916_1049/spacewalk-debug/httpd-logs/apache2/error_log*
- targets:
- localhost
labels:
job: apache
component: access_log
__path__: /home/ygutierrez/Documents/L3/1227859/scc_lxms-cp-suma01_240828_1131/spacewalk-debug/httpd-logs/apache2/access_log*
__path__: /home/ygutierrez/Documents/L3/1230944/scc_s3p3238_240916_1049/spacewalk-debug/httpd-logs/apache2/access_log*
- targets:
- localhost
labels:
job: apache
component: ssl_request_log
__path__: /home/ygutierrez/Documents/L3/1227859/scc_lxms-cp-suma01_240828_1131/spacewalk-debug/httpd-logs/apache2/ssl_request_log*
__path__: /home/ygutierrez/Documents/L3/1230944/scc_s3p3238_240916_1049/spacewalk-debug/httpd-logs/apache2/ssl_request_log*
pipeline_stages:
- match:
selector: '{job="apache",component="error_log"} |~ "^\\[[A-Z][a-z]{2} "'
Expand Down
8 changes: 7 additions & 1 deletion health-check/src/uyuni_health_check/config_loader.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import os
import configparser
import yaml
from jinja2 import Environment, FileSystemLoader


class ConfigLoader:
def __init__(self):
self.base_dir = os.path.dirname(os.path.abspath(__file__))
self.templates_dir = os.path.join(self.base_dir, "templates")
self.config_dir = os.path.join(self.base_dir, "config")
self.containers_dir = os.path.join(self.base_dir, "containers")
self.jinja_env = Environment(loader=FileSystemLoader(self.templates_dir))
self.load_config()


def load_config(self, file_path='config.ini'):
self.global_config = configparser.ConfigParser()
self.global_config.read(os.path.join(self.base_dir, "config.ini"))

def load_yaml(self, filename):
file_path = os.path.join(self.config_dir, filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ def __init__(self, supportconfig_path=None):
self.refresh()

def refresh(self):
self.salt_jobs = self.read_salt_jobs()
self.salt_keys = self.read_salt_keys()
self.salt_configuration = self.read_salt_configuration()
if self.exists_salt_jobs_file():
self.salt_jobs = self.read_salt_jobs()
if self.exists_salt_keys_file():
self.salt_keys = self.read_salt_keys()
if self.exists_salt_configuration_file():
self.salt_configuration = self.read_salt_configuration()

def _parse_command(self, command_block):
lines = command_block.strip().split("\n")
Expand Down Expand Up @@ -61,6 +64,10 @@ def parse_supportconfig_plugin_file(self, filein):
ret[cmd] = val
return ret

def exists_salt_configuration_file(self):
if not os.path.isfile(os.path.join(self.supportconfig_path, "plugin-saltconfiguration.txt")):
return

def read_salt_configuration(self):
content = None
with open(
Expand All @@ -77,6 +84,10 @@ def read_salt_configuration(self):
for attr in attrs_to_expose:
ret[attr] = re.findall(f"^{attr}: ([0-9]+)$", content, re.MULTILINE)[-1]
return ret

def exists_salt_keys_file(self):
if not os.path.isfile(os.path.join(self.supportconfig_path, "plugin-saltminionskeys.txt")):
return

def read_salt_keys(self):
content = None
Expand All @@ -96,6 +107,10 @@ def read_salt_keys(self):
ret["unaccepted"] = parsed[2].strip().split("\n") if parsed[2].strip() else []
ret["rejected"] = parsed[3].strip().split("\n") if parsed[3].strip() else []
return ret

def exists_salt_jobs_file(self):
if not os.path.isfile(os.path.join(self.supportconfig_path, "plugin-saltjobs.txt")):
return

def read_salt_jobs(self):
content = None
Expand All @@ -109,40 +124,44 @@ def collect(self):
gauge = GaugeMetricFamily(
"salt_master_config", "Salt Master Configuration", labels=["name"]
)
gauge.add_metric(
["worker_threads"],
self.salt_configuration["worker_threads"],
)
gauge.add_metric(
["sock_pool_size"],
self.salt_configuration["sock_pool_size"],
)
gauge.add_metric(["timeout"], self.salt_configuration["timeout"])
gauge.add_metric(
["gather_job_timeout"],
self.salt_configuration["gather_job_timeout"],
)
yield gauge

gauge2 = GaugeMetricFamily(
"salt_keys",
"Information about Salt keys",
labels=["name"],
)
gauge2.add_metric(["accepted"], len(self.salt_keys["accepted"]))
gauge2.add_metric(["denied"], len(self.salt_keys["denied"]))
gauge2.add_metric(["unaccepted"], len(self.salt_keys["unaccepted"]))
gauge2.add_metric(["rejected"], len(self.salt_keys["rejected"]))
yield gauge2

gauge3 = GaugeMetricFamily(
"salt_jobs",
"Information about Salt Jobs",
labels=["jid", "fun"],
)
for jid, fun in self.salt_jobs:
gauge3.add_metric([jid, fun], 1)
yield gauge3
if hasattr(self,'salt_configuration'):
gauge.add_metric(
["worker_threads"],
self.salt_configuration["worker_threads"],
)

gauge.add_metric(
["sock_pool_size"],
self.salt_configuration["sock_pool_size"],
)
gauge.add_metric(["timeout"], self.salt_configuration["timeout"])
gauge.add_metric(
["gather_job_timeout"],
self.salt_configuration["gather_job_timeout"],
)
yield gauge

if hasattr(self,'salt_keys'):
gauge2 = GaugeMetricFamily(
"salt_keys",
"Information about Salt keys",
labels=["name"],
)
gauge2.add_metric(["accepted"], len(self.salt_keys["accepted"]))
gauge2.add_metric(["denied"], len(self.salt_keys["denied"]))
gauge2.add_metric(["unaccepted"], len(self.salt_keys["unaccepted"]))
gauge2.add_metric(["rejected"], len(self.salt_keys["rejected"]))
yield gauge2

if hasattr(self,'salt_jobs'):
gauge3 = GaugeMetricFamily(
"salt_jobs",
"Information about Salt Jobs",
labels=["jid", "fun"],
)
for jid, fun in self.salt_jobs:
gauge3.add_metric([jid, fun], 1)
yield gauge3


def main():
Expand Down
17 changes: 7 additions & 10 deletions health-check/src/uyuni_health_check/containers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def podman(cmd, quiet=True, use_print=False):
"""
try:
if not quiet:
console.log(f"[italic]Running command {['podman'] + cmd}[/italic]")
console.log(f"[italic]Running command {'podman ' + ' '.join(cmd)}[/italic]")
return run_command(["podman"] + cmd, console, quiet=quiet, use_print=use_print)
except OSError:
raise HealthException("podman is required")
Expand Down Expand Up @@ -48,19 +48,16 @@ def image_exists(image):
"""
Check if the image is present in podman images result
"""
return (
podman(["images", "--quiet", "-f", f"reference={image}"], quiet=True)
.stdout.read()
.strip()
!= ""
)
stdout, stderr, _ = podman(["images", "--quiet", "-f", f"reference={image}"], quiet=True)
return stdout.strip() != ""


def network_exists(network):
"""
Check if the podman network is up and running
"""
return podman(["network", "exists", f"{network}"], quiet=True).returncode == 0
stdout, stderr, returncode = podman(["network", "exists", f"{network}"], quiet=True)
return returncode == 0


def clean_containers(verbose=False):
Expand Down Expand Up @@ -131,5 +128,5 @@ def container_is_running(name):
"""
Check if a container with a given name is running in podman
"""
process = podman(["ps", "--quiet", "-f", f"name={name}"])
return process.stdout.read() != ""
stdout, stderr, _ = podman(["ps", "--quiet", "-f", f"name={name}"])
return stdout != ""
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ def prepare_exporter(config=None, verbose=False, supportconfig_path=None):
f"{supportconfig_path}:{supportconfig_path}",
"-v",
f"{exporter_config}:/opt/config.yml",
"-p",
"9000:9000",
]

podman_args.extend(
Expand All @@ -63,7 +61,7 @@ def prepare_exporter(config=None, verbose=False, supportconfig_path=None):
f"{exporter_name}",
]
)

console.log(f"Running this command: podman " + ' '.join(podman_args))
# Run the container
podman(
podman_args,
Expand Down
Loading

0 comments on commit 3fece3d

Please sign in to comment.