Page MenuHomeDevCentral

D2600.diff
No OneTemporary

D2600.diff

diff --git a/_modules/convert.py b/_modules/convert.py
--- a/_modules/convert.py
+++ b/_modules/convert.py
@@ -11,6 +11,12 @@
import json
+import salt.serializers.yaml
+
+
+# -------------------------------------------------------------
+# JSON
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def to_json_from_pillar_key(key):
@@ -34,3 +40,43 @@
salt-call --local convert.to_json "Hello world"
"""
return json.dumps(data, indent=4, sort_keys=True)
+
+
+# -------------------------------------------------------------
+# YAML
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def _to_dictionary(data, root=None):
+ if root is not None:
+ return {root: _to_dictionary(data)}
+
+ if type(data) is list:
+ dictionary = {}
+ for item in data:
+ dictionary.update(_to_dictionary(item))
+ return dictionary
+
+ if type(data) is tuple and len(data) == 2:
+ return dict({data})
+
+ return dict(data)
+
+
+def to_yaml_dictionary(data, root=None):
+ """
+ A function to convert data to YAML dictionary.
+
+ CLI Example::
+
+ salt * convert.to_yaml_dictionary '[{"a": "bar"}, {"b": "foo"}]'
+
+ That example will return:
+ ```
+ a: bar
+ b: foo
+ ```
+ """
+ return salt.serializers.yaml.serialize(
+ _to_dictionary(data, root), default_flow_style=False
+ )
diff --git a/_modules/paas_docker.py b/_modules/paas_docker.py
--- a/_modules/paas_docker.py
+++ b/_modules/paas_docker.py
@@ -48,3 +48,37 @@
subnets.append("172.17.0.0/16")
return subnets
+
+
+# -------------------------------------------------------------
+# Monitoring
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def _get_health_check_url(check_type, container, url):
+ if check_type[-6:] == "_proxy":
+ return f"https://{container['host']}{url}"
+
+ return f"http://localhost:{container['app_port']}{url}"
+
+
+def get_health_checks():
+ """
+ A function to get a dictionary with health checks
+ for known containers to use with our monitoring.
+
+ CLI Example:
+
+ salt * paas_docker.get_health_checks
+ """
+ containers = __pillar__["docker_containers"][__grains__["id"]]
+ monitoring = __pillar__["docker_containers_monitoring"]
+
+ return {
+ check_type: {
+ instance: _get_health_check_url(check_type, container, url)
+ for service, url in monitoring[check_type].items()
+ for instance, container in containers[service].items()
+ }
+ for check_type in monitoring.keys()
+ }
diff --git a/pillar/paas/docker.sls b/pillar/paas/docker.sls
--- a/pillar/paas/docker.sls
+++ b/pillar/paas/docker.sls
@@ -474,6 +474,41 @@
sentry_cron:
realm: nasqueron
+# -------------------------------------------------------------
+# Monitoring
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+docker_containers_monitoring:
+
+ # Go to URL, check it's an HTTP 200 response
+ check_http_200:
+ acme_dns: /health
+ cachet: /api/v1/ping
+ hound: /healthz
+
+ # Test a regular URL for services without health check
+ api-datasources: /datasources
+ etherpad: /stats
+ hauk: /
+ jenkins: /login
+ registry: /
+
+ # Go to URL, check it's an HTTP 200 response code + "ALIVE" as content
+ check_http_200_alive:
+ auth-grove: /status
+ docker-registry-api: /status
+ notifications: /status
+ tommy: /status
+
+ # Same than check_http_200, but we need to query the proxy
+ check_http_200_proxy:
+ openfire: /login.jsp
+ pixelfed: /api/nodeinfo/2.0.json
+
+ # Same than check_http_200_alive, but we need to query the proxy
+ check_http_200_alive_proxy:
+ phabricator: /status
+
# -------------------------------------------------------------
# Ports listened by known applications
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/roles/paas-docker/init.sls b/roles/paas-docker/init.sls
--- a/roles/paas-docker/init.sls
+++ b/roles/paas-docker/init.sls
@@ -20,6 +20,7 @@
- .wwwroot-502
- .wwwroot-content
- .nginx
+ - .monitoring
- .letsencrypt
- .wrappers
{% if salt['node.has']('flags:install_docker_devel_tools') %}
diff --git a/roles/paas-docker/monitoring/files/checks.yml.jinja b/roles/paas-docker/monitoring/files/checks.yml.jinja
new file mode 100644
--- /dev/null
+++ b/roles/paas-docker/monitoring/files/checks.yml.jinja
@@ -0,0 +1,19 @@
+# -------------------------------------------------------------
+# Configuration for Docker PaaS monitoring
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# Source file: roles/paas-docker/monitoring/files/checks.yml.jinja
+# -------------------------------------------------------------
+#
+# <auto-generated>
+# This file is managed by our rOPS SaltStack repository.
+#
+# Changes to this file may cause incorrect behavior
+# and will be lost if the state is redeployed.
+# </auto-generated>
+
+# -------------------------------------------------------------
+# Checks configuration
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{{ salt["convert.to_yaml_dictionary"](checks, root="checks") }}
diff --git a/roles/paas-docker/monitoring/init.sls b/roles/paas-docker/monitoring/init.sls
new file mode 100644
--- /dev/null
+++ b/roles/paas-docker/monitoring/init.sls
@@ -0,0 +1,29 @@
+# -------------------------------------------------------------
+# Salt — Provision Docker engine
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Nasqueron
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+{% from "map.jinja" import dirs with context %}
+
+# -------------------------------------------------------------
+# Platform checks
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+platform-checks:
+ pip.installed
+
+# -------------------------------------------------------------
+# Health check configuration
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+{{ dirs.etc }}/monitoring/checks.yml:
+ file.managed:
+ - source: salt://roles/paas-docker/monitoring/files/checks.yml.jinja
+ - makedirs: True
+ - mode: 0644
+ - template: jinja
+ - context:
+ checks:
+ - {{ salt['paas_docker.get_health_checks']() }}

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 27, 14:13 (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2267042
Default Alt Text
D2600.diff (6 KB)

Event Timeline