ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilGlobalCacheMetricsCollectedObjective.php
Go to the documentation of this file.
1 <?php
2 
24 use ILIAS\Setup;
25 
27 {
28  protected function getTentativePreconditions(Environment $environment): array
29  {
30  return [
32  new \ilDatabaseInitializedObjective()
33  ];
34  }
35 
36  protected function collectFrom(Environment $environment, Storage $storage): void
37  {
38  $db = $environment->getResource(Environment::RESOURCE_DATABASE);
39  $client_ini = $environment->getResource(Environment::RESOURCE_CLIENT_INI);
40 
41  if (!$client_ini) {
42  return;
43  }
44 
45  $config = (new ilGlobalCacheSettingsAdapter($client_ini, $db))->getConfig();
46 
47  $service = $config->getAdaptorName();
48  $storage->storeConfigText(
49  "service",
50  $service,
51  "The backend that is used for the ILIAS cache."
52  );
53  $storage->storeConfigBool(
54  "active",
55  $config->isActivated()
56  );
57 
58  $servers = $config->getNodes();
59  if (
60  $service === Config::MEMCACHED &&
61  $servers !== []
62  ) {
63  $server_collection = [];
64  foreach ($servers as $server) {
65  $host = new Metric(
66  Metric::STABILITY_CONFIG,
67  Metric::TYPE_TEXT,
68  $server->getHost()
69  );
70  $port = new Metric(
71  Metric::STABILITY_CONFIG,
72  Metric::TYPE_GAUGE,
73  $server->getPort()
74  );
75  $weight = new Metric(
76  Metric::STABILITY_CONFIG,
77  Metric::TYPE_GAUGE,
78  $server->getWeight()
79  );
80 
81  $server_collection[] = new Metric(
82  Metric::STABILITY_CONFIG,
83  Metric::TYPE_COLLECTION,
84  [
85  "host" => $host,
86  "port" => $port,
87  "weight" => $weight
88  ],
89  "Configured memcached node."
90  );
91  }
92 
93  $nodes = new Metric(
94  Metric::STABILITY_CONFIG,
95  Metric::TYPE_COLLECTION,
96  $server_collection,
97  "Collection of configured memcached nodes."
98  );
99  $storage->store("memcached_nodes", $nodes);
100  }
101 
102  $component_activation = [];
103  foreach (ilGlobalCache::getAvailableComponents() as $component) {
104  $component_activation[$component] = new Metric(
105  Metric::STABILITY_CONFIG,
106  Metric::TYPE_BOOL,
107  $config->isComponentActivated($component)
108  );
109  }
110  $component_activation = new Metric(
111  Metric::STABILITY_CONFIG,
112  Metric::TYPE_COLLECTION,
113  $component_activation,
114  "Which components are activated to use caching?"
115  );
116  $storage->store(
117  "components",
118  $component_activation
119  );
120  }
121 }
storeConfigText(string $key, string $value, string $description=null)
store(string $key, Metric $metric)
Store some metric in the storage.
A metric is something we can measure about the system.
Definition: Metric.php:33
Base class to simplify collection of metrics.
storeConfigBool(string $key, bool $value, string $description=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getResource(string $id)
Consumers of this method should check if the result is what they expect, e.g.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$server
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
$service
Definition: ltiservices.php:43