Skip to content

[Feat] Allow multiple globalmon instances per host #32

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions cloudmon/ansible/project/roles/globalmon/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ distro_lookup_path:

globalmon_os_user: "cloudmon"
globalmon_os_group: "cloudmon"
globalmon_systemd_service_name: "cloudmon-globalmon.service"
globalmon_suffix: "prod"
globalmon_systemd_service_name: "cloudmon-globalmon_{{ globalmon_suffix }}.service"
globalmon_systemd_unit_path: "{{ ('/etc/systemd/system/'+ globalmon_systemd_service_name) }}"
globalmon_image: "quay.io/stackmon/globalmon"
globalmon_config_dir: "/etc/cloudmon"
globalmon_config_file_name: "cloudmon-globalmon.yaml"
globalmon_config_file_name: "cloudmon-globalmon_{{ globalmon_suffix }}.yaml"
globalmon_config_path: "{{ globalmon_config_dir }}/{{ globalmon_config_file_name }}"
globalmon_log_dir: "/var/log/globalmon"
globalmon_log_dir: "/var/log/globalmon/{{ globalmon_suffix }}"
globalmon_secure_config_file_name: "cloudmon-globalmon-secure.yaml"
globalmon_secure_config_path: "{{ globalmon_config_dir }}/{{ globalmon_secure_config_file_name }}"
globalmon_env_file_name: "globalmon_env"
globalmon_env_path: "{{ globalmon_config_dir }}/{{ globalmon_env_file_name }}"
# globalmon_config:
# globalmon_secure_config:
globalmon_container_name: "cloudmon_globalmon"
globalmon_container_name: "cloudmon_globalmon_{{ globalmon_suffix }}"

container_command: "podman"
container_runtime: "/usr/bin/{{ container_command }}"
2 changes: 1 addition & 1 deletion cloudmon/ansible/project/start_globalmon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
tasks:
- name: Start globalmon
ansible.builtin.service:
name: "cloudmon-globalmon"
name: "{{ globalmon_service_name }}"
state: "started"
2 changes: 1 addition & 1 deletion cloudmon/ansible/project/stop_globalmon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
tasks:
- name: Stop globalmon
ansible.builtin.service:
name: "cloudmon-globalmon"
name: "{{ globalmon_service_name }}"
state: "stopped"
23 changes: 14 additions & 9 deletions cloudmon/plugin/globalmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@ def process_config(self):
def process_plugin_entry(self, plugin_ref, matrix_entry, plugin):
env_name = matrix_entry.env
zone = matrix_entry.monitoring_zone
key = f"{zone}_{env_name}" # Unique key per env + zone

globalmon_config = self.globalmon_configs.setdefault(
zone, GlobalmonConfig())
key, GlobalmonConfig())
globalmon_config.environment = env_name
globalmon_config.zone = zone
ansible_group_name = plugin.globalmons_inventory_group_name
globalmon_config.ansible_group_name = ansible_group_name
globalmon_config.image = plugin_ref.image

config = None

# Read config file
Expand All @@ -89,21 +92,17 @@ def process_plugin_entry(self, plugin_ref, matrix_entry, plugin):
raise RuntimeError("Globalmon config not found. Please either use --config-dir and relative path for globalmon config in cloudmon config OR use --insecure option with full path of globalmon config in cloudmon config") # noqa

globalmon_config.services = config["services"]

globalmon_config.watch_clouds[env_name] = dict(
# which services
services=globalmon_config.services,
# how cloud is named
cloud=plugin.cloud_name,
)

def provision(self, options):

for _, globalmon_config in self.globalmon_configs.items():
for key, globalmon_config in self.globalmon_configs.items():
self.log.info(
"Provisioning Globalmon in monitoring zone %s",
"Provisioning Globalmon in monitoring zone %s for env %s",
globalmon_config.zone,
)
globalmon_config.environment)

statsd_group_name = self.config.model.get_monitoring_zone_by_name(
globalmon_config.zone
Expand Down Expand Up @@ -157,6 +156,7 @@ def provision(self, options):
globalmon_secure_cfg = dict(clouds=clouds_creds)

extravars = dict(
globalmon_suffix=environment,
globalmon_group_name=globalmon_config.ansible_group_name,
globalmon_image=globalmon_config.image,
globalmon_config_dir="/home/ubuntu",
Expand All @@ -175,15 +175,18 @@ def provision(self, options):
verbosity=3,
)
if r.rc != 0:
raise RuntimeError("Error provisioning Globalmon")
raise RuntimeError(
f"Error provisioning Globalmon in {zone} for {environment}") # noqa

def stop(self, options):
for _, globalmon_config in self.globalmon_configs.items():
self.log.info(
"Stopping Globalmon in monitoring zone %s",
globalmon_config.zone,
)
environment = globalmon_config.environment
extravars = dict(
globalmon_service_name=f"cloudmon-globalmon_{environment}",
globalmon_group_name=globalmon_config.ansible_group_name,
)
r = ansible_runner.run(
Expand All @@ -204,7 +207,9 @@ def start(self, options):
"Starting Globalmon in monitoring zone %s",
globalmon_config.zone,
)
environment = globalmon_config.environment
extravars = dict(
globalmon_service_name=f"cloudmon-globalmon_{environment}",
globalmon_group_name=globalmon_config.ansible_group_name,
)
r = ansible_runner.run(
Expand Down