Module: check_mk
Branch: master
Commit: 4925bcf10b182e5f41c585072b3456514bcc1c4b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4925bcf10b182e…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Oct 23 14:29:15 2017 +0200
5402 Number of apache processes can now be configured via Global Settings
It is now possible to configure the apache configuration option {MaxClients} via
WATO (Global Settings > Site Management > Apache process tuning).
This option is often changed to tune the site apache to either consume less memory
(reduce the number of maximum processes) or being able to handle more users in the
GUI simultaneously.
The option can be configured globally for all sites or in the site specific globals,
depending on your needs.
The defaul value of this option is read from the existing configuration files
(etc/apache/apache.conf and etc/apache/conf.d/*.conf) and defaults to {64}.
Change-Id: I1cd97e6a3391d2cb5708a8a69fe9415e0a362cb9
---
.werks/5402 | 21 +++++++
web/plugins/wato/omd_configuration.py | 103 ++++++++++++++++++++++++++++++++++
2 files changed, 124 insertions(+)
diff --git a/.werks/5402 b/.werks/5402
new file mode 100644
index 0000000..6fe0d98
--- /dev/null
+++ b/.werks/5402
@@ -0,0 +1,21 @@
+Title: Number of apache processes can now be configured via Global Settings
+Level: 2
+Component: wato
+Compatible: compat
+Edition: cre
+Version: 1.5.0i1
+Date: 1508761368
+Class: feature
+
+It is now possible to configure the apache configuration option {MaxClients} via
+WATO (Global Settings > Site Management > Apache process tuning).
+
+This option is often changed to tune the site apache to either consume less memory
+(reduce the number of maximum processes) or being able to handle more users in the
+GUI simultaneously.
+
+The option can be configured globally for all sites or in the site specific globals,
+depending on your needs.
+
+The defaul value of this option is read from the existing configuration files
+(etc/apache/apache.conf and etc/apache/conf.d/*.conf) and defaults to {64}.
diff --git a/web/plugins/wato/omd_configuration.py
b/web/plugins/wato/omd_configuration.py
index 11d7734..cb13103 100644
--- a/web/plugins/wato/omd_configuration.py
+++ b/web/plugins/wato/omd_configuration.py
@@ -310,3 +310,106 @@ register_configvar(group,
replication_paths.append(("file", "diskspace",
ConfigDomainDiskspace.diskspace_config))
+
+
+#.
+# .--Apache--------------------------------------------------------------.
+# | _ _ |
+# | / \ _ __ __ _ ___| |__ ___ |
+# | / _ \ | '_ \ / _` |/ __| '_ \ / _ \ |
+# | / ___ \| |_) | (_| | (__| | | | __/ |
+# | /_/ \_\ .__/ \__,_|\___|_| |_|\___| |
+# | |_| |
+# +----------------------------------------------------------------------+
+# | Manage settings of the site apache |
+# '----------------------------------------------------------------------'
+
+class ConfigDomainApache(ConfigDomain):
+ needs_sync = True
+ needs_activation = True
+ ident = "apache"
+
+ def config_dir(self):
+ return cmk.paths.default_config_dir + "/apache.d/wato/"
+
+
+ def activate(self):
+ try:
+ self._write_config_file()
+
+ p = subprocess.Popen(["omd", "restart",
"apache"], shell=False, stdin=open(os.devnull),
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+
+ stdout = p.communicate()[0]
+ if p.returncode != 0:
+ raise Exception(stdout)
+
+ return []
+ except Exception, e:
+ log_exception()
+ return ["Failed to activate apache configuration: %s" %
(traceback.format_exc())]
+
+
+ def _write_config_file(self):
+ config = self._get_effective_config()
+
+ output = wato_fileheader()
+ output += "ServerLimit %d\n" %
config["process_tuning"]["number_of_processes"]
+ output += "MaxClients %d\n" %
config["process_tuning"]["number_of_processes"]
+
+ config_file_path = os.path.join(cmk.paths.omd_root,
"etc/apache/conf.d", "zzz_check_mk.conf")
+ store.save_file(config_file_path, output)
+
+
+
+ def _get_effective_config(self):
+ config = self.default_globals()
+ config.update(self.load(site_specific=False))
+ config.update(self.load(site_specific=True))
+ return config
+
+
+ def default_globals(self):
+ return {
+ "process_tuning": {
+ "number_of_processes" :
self._get_value_from_apache_config("MaxClients", int, 64),
+ }
+ }
+
+
+ def _get_value_from_apache_config(self, varname, conv_func, default_value):
+ config_files = [ os.path.join(cmk.paths.omd_root,
"etc/apache/apache.conf") ]
+ config_files += sorted(glob.glob(os.path.join(cmk.paths.omd_root,
"etc/apache/conf.d", "*.conf")))
+
+ value = default_value
+
+ for config_file in config_files:
+ if config_file.endswith("zzz_check_mk.conf"):
+ continue # Skip the file written by this config domain
+
+ for line in open(config_file):
+ if line.lstrip().startswith("MaxClients"):
+ raw_value = line.split()[1]
+ value = conv_func(raw_value)
+
+ return value
+
+
+register_configvar(group,
+ "process_tuning",
+ Dictionary(
+ title = _("Apache process tuning"),
+ elements = [
+ ("number_of_processes", Integer(
+ title = _("Number of apache processes"),
+ help = _("Use this value to tune the maximum number of apache client
requests that will be processed simultaneously "
+ "(maximum number of apache server processes allowed to
start). In case you have a lot of incoming "
+ "requests in parallel it may be a good idea to increase
this value. But do this carefully, more is "
+ "not always better. The apache processes normally need a
decent amount of memory and you should "
+ "only configure as many apache processes as your system can
handle in high load situations."),
+ minvalue = 5,
+ )),
+ ],
+ ),
+ domain = ConfigDomainApache,
+)