Browse Source

Ported to Drupal 7.

Frederic G. MARAND 5 years ago
parent
commit
61e817ba71

+ 83 - 0
INSTALL.md

@@ -0,0 +1,83 @@
+# Installing the Drupal Munin server
+
+## 1. Install Munin and the module
+
+The module is designed for Munin 1.4.4 and above. Use the normal Munin deployment
+for your platform.
+
+It is known to work, albeit with some warnings and limitations, on the older
+Munin 1.2.6 (Ubuntu 9.04/Karmic).
+
+On Debian/Ubuntu, you will find configuration in `/etc/munin`. 
+
+- Install the module on Drupal, and enable the submodules you wish to use. 
+- Default submodules are provided to monitor Drupal core (content, users), and
+  the PHP APC opcode cache. 
+
+
+## 2. Declare the plugin to Munin
+
+A sample plugin is provided with the module as `plugins/munin-drupal_`, which
+you can either use as such or customize as needed. The sample plugin uses `CURL`
+to contact your Drupal site to obtain its data.
+
+You will usually copy it to a directory in your `$PATH`, like `/usr/local/bin`,
+or create a link to it from that directory, like:
+
+```
+ln -s <drupal>/sites/all/modules/munin_api/plugins/munin-drupal_ /usr/local/bin/munin-drupal_
+```
+
+## 3. Configure the plugin in Munin
+
+Edit the `/etc/munin/plugin-conf/munin-node` file to declare the plugin.
+
+Add a section for your plugin. If you are using the sample plugin provided with
+the module, it needs to know the hostname of the site to monitor, which is not
+always the same site as your Munin instance.
+```ini
+[drupal_*]
+env.HOST mysitename.mydomain.tld
+```
+
+
+## 4. Check
+
+Once declaration and configuration are done, you need to force `munin-node` to
+update its configuration. On Ubuntu 10.10, for instance, use:
+
+```
+sudo service munin-node reload
+```
+
+Assuming you enabled Drupal core and APC monitoring. You can then check the module configuration:
+
+```
+munin-run drupal_core config
+munin-run drupal_apc config  
+```  
+Then check their data:
+ 
+```
+munin-run drupal_core
+munin-run drupal_apc  
+```
+
+  
+## 5. Modify configuration
+
+Any time you enable/disable a Munin submodule or modify its settings, you will
+need to force a `munin-node` configuration reload so that the server knows what
+to plot.
+
+
+## 6. Access control
+
+In the Drupal UI:
+
+- The Munin API settings form
+  - is located at: `admin/config/munin_api`
+  - is controlled by permission: `administer site configuration`
+- The Munin report pages
+  - start at: `admin/reports/munin_api`  
+  - are controlled by permission: `access site reports`

+ 0 - 90
INSTALL.txt

@@ -1,90 +0,0 @@
-Installing the Drupal Munin server
-----------------------------------
-
-1 Install Munin and the module
-------------------------------
-
-The module is designed for Munin 1.4.4 and above. Use the normal Munin deployment for your platform.
-
-It is known to work, albeit with some warnings and limitations, on Munin 1.2.6 (Ubuntu 9.04/Karmic).
-
-On Debian/Ubuntu, you will find configuration in /etc/munin 
-
-Install the module on Drupal, and enable the submodules you wish to use. 
-Default submodules are provided to monitor Drupal core (content, users), and the 
-PHP APC opcode cache. 
-
-
-2 Declare the plugin to Munin
------------------------------
-
-A sample plugin is provided with the module as plugins/munin-drupal_, which you
-can either use as such or customize as needed. The sample plugin uses CURL to
-contact your Drupal site to obtain its data. 
-
-You will usually copy it to a directory in your $PATH, like /usr/local/bin, or 
-createa link to it from that directory, like:
-
-  ln -s <drupal>/sites/all/modules/munin_api/plugins/munin-drupal_ /usr/local/bin/munin-drupal_
- 
-
-3 Configure the plugin in Munin
--------------------------------
-
-Edit the /etc/munin/plugin-conf/munin-node file to declare the plugin
-
-Add a section for your plugin. If you are using the sample plugin provided with
-the module, it needs to know the hostname of the site to monitor, which is not 
-always the same site as your Munin instance.
-
-  [drupal_*]
-  env.HOST mysitename.mydomain.tld
-
-
-4 Check
--------
-
-Once declaration and configuration are done, you need to force munin-node to
-update its configuration. On Ubuntu 10.10, for instance, use:
-
-  sudo service munin-node reload
-
-Assuming you enabled Drupal core and APC monitoring. You can then check the module configuration:
-
-  munin-run drupal_core config
-  munin-run drupal_apc config  
-  
-Then check their data:
- 
-  munin-run drupal_core
-  munin-run drupal_apc  
-
-  
-5 Modify configuration
-----------------------
-
-Any time you enable/disable a Munin submodule or modify its settings, you will
-need to force a munin-node configuration reload so that the server knows what to 
-plot.
-
-
-6 Access control
-----------------
-
-In the Drupal UI:
-
-- The Munin API settings form 
-
-  - is located at:
-    admin/settings/munin_api
-
-  - is controlled by permission: 
-    administer site configuration
-    
-- The Munin report pages
- 
-  - start at:
-    admin/reports/munin_api
-    
-  - are controlled by the permission:
-    access site reports

+ 5 - 0
help/munin_api.help.ini

@@ -2,3 +2,8 @@
 title = What it munin_api ?
 weight = -10
 line break = FALSE
+
+[paths]
+title = Munin API Paths
+weight = 0
+line break = FALSE

+ 29 - 0
help/paths.html

@@ -0,0 +1,29 @@
+<h4>Configuration</h4>
+
+<ul>
+  <li><a href="&base_url&admin/config/munin_api">admin/config/munin_api</a>
+    Munin API configuration</li>
+  <li><a href="&base_url&admin/reports/munin_api">admin/reports/munin_api</a>
+    Reports about Munin data collector submodules and their probes</li>
+  <li><a href="&base_url&admin/reports/munin_api/[collector]">admin/reports/munin_api/[collector]</a>
+    Report on the specified collector submodule</li>
+</ul>
+
+<h4>Data</h4>
+
+<ul>
+  <li><a href="&base_url&munin_api/[graph]">munin_api/[graph]</a>
+    Munin data for a graph</li>
+  <li><a href="&base_url&munin_api/[graph]/config">munin_api/[graph]/config</a>
+    Munin configuration for a graph</li>
+</ul>
+
+<h4>Help</h4>
+
+<ul>
+  <li><a href="http://features.osinet.eu/munin-api-drupal">Complete documentation</a> (off-site)</li>
+  <li><a href="&base_url&admin/help/munin_api">admin/help/munin_api</a>
+    Default help page</li>
+  <li><a href="&base_url&admin/help/ah/munin_api">admin/help/ah/munin_api</a>
+    Advanced help main page</li>
+</ul>

+ 10 - 14
modules/munin_apc/munin_apc.info

@@ -1,22 +1,18 @@
-; $Id$
-;
+
 ; @file
-; APC instrumentation for Munin: module manifest
-; 
+; APC instrumentation for Munin API: module manifest
+;
+
+; @copyright (c) 2011-2019 Ouest Systèmes Informatiques
 ;
-; @author Frederic G. MARAND
-; 
-; @copyright (c) 2011 Ouest Systèmes Informatiques
-; 
 ; Licensed under the General Public License version 2 or later.
 
 name = "Munin APC"
 description = "APC information collector for Munin"
 package = Administration
+core = 7.x
+php = 7.1
 
-core = 6.x
-
-project = "munin_api"
-datestamp = "1296219892"
-project status url = http://features.osinet.eu/fserver
-version = "6.x-1.0-dev11b0901"
+; Technically, there is no dependency. However, this collector is useless
+; without the main Munin API module, so better mark the latter as a dependency.
+dependencies[] = munin_api

+ 23 - 5
modules/munin_apc/munin_apc.install

@@ -1,12 +1,10 @@
 <?php
-// $Id$
+
 /**
  * @file
  * Drupal APC instrumentation for Munin: installation.
  *
- * @author Frederic G. MARAND
- *
- * @copyright (c) 2011 Ouest Systèmes Informatiques
+ * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
  *
  * Licensed under the General Public License version 2 or later.
  */
@@ -23,4 +21,24 @@ function munin_apc_enable() {
  */
 function munin_apc_disable() {
   variable_set('menu_rebuild_needed', TRUE);
-}
+}
+
+/**
+ * Implements hook_requirements().
+ *
+ * Since this module requires PHP >= 7.1, the only suported version of APC is
+ * actually APCu.
+ */
+function munin_apc_requirements($phase) {
+  $requirements = [];
+  $t = get_t();
+  if (!function_exists('apcu_sma_info') || !function_exists('apcu_cache_info')) {
+    $requirements['munin_apc'] = [
+      'title' => $t('APCu'),
+      'description' => $t('APCu functions apc_sma_info / apcu_cache_info not found'),
+      'severity' => REQUIREMENT_ERROR,
+    ];
+  }
+
+  return $requirements;
+}

+ 83 - 85
modules/munin_apc/munin_apc.module

@@ -1,12 +1,10 @@
 <?php
-// $Id$
+
 /**
  * @file
- * APC instrumentation for Munin
- *
- * @author Frederic G. MARAND
+ * APCu instrumentation for Munin.
  *
- * @copyright (c) 2011 Ouest Systèmes Informatiques
+ * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
  *
  * Licensed under the General Public License version 2 or later.
  */
@@ -14,82 +12,83 @@
 /**
  * Implements hook_munin_api_info().
  *
- * @return
- *   An array of Munin graph informations, index by graph name, each containing
- *   an array of field information.
+ * Returns an array of Munin graph informations, indexed by graph name, each
+ * containing an array of field information.
  */
 function munin_apc_munin_api_info() {
-  $int = array(
+  $int = [
     '#graph_printf' => '%d',
-  );
-
-  $ret = array(
-    '#title'       => t('APC'),
-    '#description' => t('Graphs about PHP APC memory yse'),
-
-    'munin_apc' => array(
-      '#title'       => t('APC Caching'),
-      '#info'        => t('Collect memory-level information for the Alternative PHP Cache. This graph uses IEC binary sizes.'),
-      '#graph_args'  => '--base 1024 --lower-limit 0',
-
-      'total_size' => $int + array(
-        '#label'     => t('Bytes allocated'),
-        '#type'      => MUNIN_API_GAUGE,
-        '#info'      => t('Number of bytes allocated to APC.')
-      ),
-      'used_size'  => $int + array(
-        '#label'     => t('Bytes in use'),
-        '#type'      => MUNIN_API_GAUGE,
-        '#info'      => t('Number of bytes actually used by APC, either cached or deleted'),
-      ),
-    ),
-
-    'munin_apc_entries' => array(
-      '#title'       => t('APC Entries'),
-      '#info'        => t('Collect entries-level information for the Alternative PHP Cache.'),
-      '#graph_args'  => '--base 1000 --lower-limit 0',
-
-      'num_hits'   => $int + array(
-        '#label'     => t('Hits since last restart'),
-        '#type'      => MUNIN_API_COUNTER,
-      ),
-      'num_misses' => $int + array(
-        '#label'     => t('Misses since last restart'),
-        '#type'      => MUNIN_API_COUNTER,
-      ),
-      'num_inserts' => $int + array(
-        '#label'     => t('Insertions since last restart'),
-        '#type'      => MUNIN_API_COUNTER,
-      ),
-//      'hit_rate'   => $int + array(
-//        '#label'     => t('Hit/miss ratio since last restart'),
-//        '#type'      => MUNIN_API_GAUGE,
-//      ),
-      'cache_entries' => $int + array(
-        '#label'     => t('Number of cache entries'),
-        '#type'      => MUNIN_API_GAUGE,
-      ),
-      'deleted_entries' => $int + array(
-        '#label'     => t('Number of deleted entries'),
-        '#type'      => MUNIN_API_GAUGE,
-        '#info'      => t('Deleted entries lingering until the garbage collection TTL elapses'),
-      ),
-    ),
-
-    'munin_apc_uptime' => array(
-      '#title'     => t('APC Uptime'),
-      '#info'      => t('Uptime information for the Alternative PHP Cache.'),
+  ];
+
+  $ret = [
+    '#title' => t('APCu'),
+    '#description' => t('Graphs about PHP APCu memory use'),
+
+    'munin_apc' => [
+      '#title' => t('APCu Caching'),
+      '#info' => t('Collect memory-level information for the Alternative PHP Cache for user data). This graph uses IEC binary sizes.'),
+      '#graph_args' => '--base 1024 --lower-limit 0',
+
+      'total_size' => $int + [
+        '#label' => t('Bytes allocated'),
+        '#type' => MUNIN_API_GAUGE,
+        '#info' => t('Number of bytes allocated to APCu.'),
+      ],
+      'used_size' => $int + [
+        '#label' => t('Bytes in use'),
+        '#type' => MUNIN_API_GAUGE,
+        '#info' => t('Number of bytes actually used by APCu, either cached or deleted'),
+      ],
+    ],
+
+    'munin_apc_entries' => [
+      '#title' => t('APCu Entries'),
+      '#info' => t('Collect entries-level information for APCu.'),
+      '#graph_args' => '--base 1000 --lower-limit 0',
+
+      'num_hits' => $int + [
+        '#label' => t('Hits since last restart'),
+        '#type' => MUNIN_API_COUNTER,
+      ],
+      'num_misses' => $int + [
+        '#label' => t('Misses since last restart'),
+        '#type' => MUNIN_API_COUNTER,
+      ],
+      'num_inserts' => $int + [
+        '#label' => t('Insertions since last restart'),
+        '#type' => MUNIN_API_COUNTER,
+      ],
+      /*
+      'hit_rate' => $int + [
+        '#label' => t('Hit/miss ratio since last restart'),
+        '#type' => MUNIN_API_GAUGE,
+      ],
+       */
+      'cache_entries' => $int + [
+        '#label' => t('Number of cache entries'),
+        '#type' => MUNIN_API_GAUGE,
+      ],
+      'deleted_entries' => $int + [
+        '#label' => t('Number of deleted entries'),
+        '#type' => MUNIN_API_GAUGE,
+        '#info' => t('Deleted entries lingering until the garbage collection TTL elapses'),
+      ],
+    ],
+
+    'munin_apc_uptime' => [
+      '#title' => t('APC Uptime'),
+      '#info' => t('Uptime information for APCu.'),
       '#graph_vlabel' => t('Uptime in days'),
-      '#graph_scale'  => 'no',
+      '#graph_scale' => 'no',
 
-      'uptime'     => $int + array(
-        '#label'     => t('Up-time of APC instance'),
-        '#type'      => MUNIN_API_GAUGE,
-        '#info'      => t('Days since last APC restart.'),
-        '#draw'      => MUNIN_API_DRAW_AREA,
-      ),
-    ),
-  );
+      'uptime' => $int + [
+        '#label' => t('Up-time of APCu instance'),
+        '#type' => MUNIN_API_GAUGE,
+        '#info' => t('Days since last APCu restart.'),
+        '#draw' => MUNIN_API_DRAW_AREA,
+      ],
+    ],
+  ];
 
   return $ret;
 }
@@ -102,25 +101,24 @@ function munin_apc_munin_api_info() {
  */
 function munin_apc_munin_api_fetch($graph_name) {
 
-  static $cache = array();
+  static $cache = [];
 
   if (empty($cache)) {
-    $info = apc_sma_info();
-    $ret = array();
+    $info = apcu_sma_info();
 
-    // SMA Info
+    // SMA Info.
     $total = $info['num_seg'] * $info['seg_size'];
     $cache['munin_apc']['total_size'] = (int) $total;
     $cache['munin_apc']['used_size'] = (int) ($total - $info['avail_mem']);
 
-    // Cache info
-    $info = apc_cache_info();
-    $cache['munin_apc_uptime']['uptime'] = (time() - $info['start_time']) / 86400;
-    foreach (array('num_hits', 'num_misses', 'num_inserts') as $field) {
+    // Cache info.
+    $info = apcu_cache_info();
+    $cache['munin_apc_uptime']['uptime'] = (REQUEST_TIME - $info['start_time']) / 86400;
+    foreach (['num_hits', 'num_misses', 'num_inserts'] as $field) {
       $cache['munin_apc_entries'][$field] = $info[$field];
     }
 
-    $cache['munin_apc_entries']['cache_entries']   = count($info['cache_list']);
+    $cache['munin_apc_entries']['cache_entries']   = $info['num_entries'] ?? count($info['cache_list']);
     $cache['munin_apc_entries']['deleted_entries'] = count($info['deleted_list']);
   }
 

+ 9 - 14
modules/munin_core/munin_core.info

@@ -1,22 +1,17 @@
-; $Id$
-;
+
 ; @file
-; Drupal core instrumentation for Munin: module manifest
-; 
+; Drupal core instrumentation for Munin API: module manifest
+;
+; @copyright (c) 2011-2019 Ouest Systèmes Informatiques
 ;
-; @author Frederic G. MARAND
-; 
-; @copyright (c) 2011 Ouest Systèmes Informatiques
-; 
 ; Licensed under the General Public License version 2 or later.
 
 name = "Munin Core"
 description = "Core Drupal information collector for Munin"
 package = Administration
+core = 7.x
+php = 7.1
 
-core = 6.x
-
-project = "munin_api"
-datestamp = "1296219892"
-project status url = http://features.osinet.eu/fserver
-version = "6.x-1.0-dev11b0901"
+; Technically, there is no dependency. However, this collector is useless
+; without the main Munin API module, so better mark the latter as a dependency.
+dependencies[] = munin_api

+ 2 - 4
modules/munin_core/munin_core.install

@@ -1,12 +1,10 @@
 <?php
-// $Id$
+
 /**
  * @file
  * Core Drupal instrumentation for  Munin: installation.
  *
- * @author Frederic G. MARAND
- *
- * @copyright (c) 2011 Ouest Systèmes Informatiques
+ * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
  *
  * Licensed under the General Public License version 2 or later.
  */

+ 170 - 132
modules/munin_core/munin_core.module

@@ -1,12 +1,10 @@
 <?php
-// $Id$
+
 /**
  * @file
- * Core Drupal instrumentation for Munin
- *
- * @author Frederic G. MARAND
+ * Core Drupal instrumentation for Munin.
  *
- * @copyright (c) 2011 Ouest Systèmes Informatiques
+ * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
  *
  * Licensed under the General Public License version 2 or later.
  */
@@ -14,121 +12,127 @@
 /**
  * Implements hook_munin_api_info().
  *
- * @return
- *   An array of Munin probes informations, index by probe name.
+ * Returns an array of Munin probes informations, index by probe name.
  */
 function munin_core_munin_api_info() {
-  $int = array(
+  $int = [
     '#graph_printf' => "'%d'",
-  );
+  ];
 
-  /**
-   * Ignore anon and auth roles: no user carries them in users_roles anyway.
-   */
-  $sq = 'SELECT r.rid, r.name FROM {role} r WHERE r.rid > 2 ORDER BY 2';
+  /* Ignore anon and auth roles: no user carries them in users_roles anyway. */
+  $sq = <<<SQL
+SELECT r.rid, r.name 
+FROM {role} r 
+WHERE r.rid > 2 
+ORDER BY 2
+SQL;
   $q = db_query($sq);
-  $roles = array();
-  while ($o = db_fetch_object($q)) {
+  $roles = [];
+  foreach ($q as $o) {
     $roles[$o->rid] = $o->name;
   }
 
-  $ret = array(
-    '#title'     => t('Drupal'),
-    '#description'  => t('Graphs about Drupal core'),
+  $ret = [
+    '#title' => t('Drupal'),
+    '#description' => t('Graphs about Drupal core'),
 
-    'munin_core' => array(
-      '#title'     => t('Core user-related statistics'),
-      '#info'      => t('Core statistics regarding users and sessions.'),
+    'munin_core' => [
+      '#title' => t('Core user-related statistics'),
+      '#info' => t('Core statistics regarding users and sessions.'),
       '#graph_vlabel' => t('Anon/blocked (-) vs Logged/Active (+)'),
 
-      'anon_current'  => $int + array(
-        '#label'      => t('Sessions, anon'),
+      'anon_current' => $int + [
+        '#label' => t('Sessions, anon'),
         '#type' => MUNIN_API_GAUGE,
-        '#info'       => t('The number of anonymous sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table.'),
-        '#graph'      => 'no',
-      ),
-      'user_current'  => $int + array(
-        '#label'      => t('Sessions'),
+        '#info' => t('The number of anonymous sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table.'),
+        '#graph' => 'no',
+      ],
+
+      'user_current' => $int + [
+        '#label' => t('Sessions'),
         '#type' => MUNIN_API_GAUGE,
-        '#info'       => t('The number of sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table. Anonymous sessions display as negative.'),
-        '#negative'   => 'anon_current',
-      ),
+        '#info' => t('The number of sessions not older than 5 minutes. Only meaningful if you are not using an alternate sessions implementation not using the sessions table. Anonymous sessions display as negative.'),
+        '#negative' => 'anon_current',
+      ],
 
-      'user_blocked_count' => $int + array(
-        '#label'      => t('Users, blocked'),
+      'user_blocked_count' => $int + [
+        '#label' => t('Users, blocked'),
         '#type' => MUNIN_API_GAUGE,
-        '#info'       => t('The number of users with status = 0'),
-        '#graph'      => 'no',
-      ),
-      'user_active_count' => $int + array(
-        '#label'      => t('Users'),
+        '#info' => t('The number of users with status = 0'),
+        '#graph' => 'no',
+      ],
+
+      'user_active_count' => $int + [
+        '#label' => t('Users'),
         '#type' => MUNIN_API_GAUGE,
-        '#info'       => t('The number of users. Blocked users display as negative.'),
-        '#negative'   => 'user_blocked_count',
-      ),
-    ),
-
-    'munin_core_roles' => array(
-      '#title'     => t('Core role statistics'),
-      '#info'      => t('Information about users roles.'),
+        '#info' => t('The number of users. Blocked users display as negative.'),
+        '#negative' => 'user_blocked_count',
+      ],
+    ],
+
+    'munin_core_roles' => [
+      '#title' => t('Core role statistics'),
+      '#info' => t('Information about users roles.'),
       '#graph_vlabel' => t('Users by roles'),
-    ),
+    ],
 
-    'munin_core_content' => array(
-      '#title'     => t('Core content statistics'),
-      '#info'      => t('Information about nodes, comments and terms.'),
+    'munin_core_content' => [
+      '#title' => t('Core content statistics'),
+      '#info' => t('Information about nodes, comments and terms.'),
       '#graph_vlabel' => t('Entries unpub(-)/pub(+)'),
 
-      'node_count_unpub' => $int + array(
-        '#label'      => t('Nodes, unpublished'),
+      'node_count_unpub' => $int + [
+        '#label' => t('Nodes, unpublished'),
         '#type' => MUNIN_API_GAUGE,
-        '#graph'      => 'no',
-      ),
-      'node_count' => $int + array(
-        '#label'      => t('Nodes'),
-        '#info'       => t('Unpublished nodes display as negative.'),
+        '#graph' => 'no',
+      ],
+
+      'node_count' => $int + [
+        '#label' => t('Nodes'),
+        '#info' => t('Unpublished nodes display as negative.'),
         '#type' => MUNIN_API_GAUGE,
-        '#negative'   => 'node_count_unpub',
-      ),
+        '#negative' => 'node_count_unpub',
+      ],
 
-      'comment_count_unpub' => $int + array(
-        '#label'      => t('Comments, unpublished'),
+      'comment_count_unpub' => $int + [
+        '#label' => t('Comments, unpublished'),
         '#type' => MUNIN_API_GAUGE,
-        '#graph'      => 'no',
-      ),
-      'comment_count' => $int + array(
-        '#label'      => t('Comments'),
-        '#info'       => t('Unpublished comments display as negative.'),
+        '#graph' => 'no',
+      ],
+
+      'comment_count' => $int + [
+        '#label' => t('Comments'),
+        '#info' => t('Unpublished comments display as negative.'),
         '#type' => MUNIN_API_GAUGE,
-        '#negative'   => 'comment_count_unpub',
-      ),
-    ),
+        '#negative' => 'comment_count_unpub',
+      ],
+    ],
 
-    'munin_core_taxonomy' => array(
-      '#title'     => t('Core taxonomy statistics'),
-      '#info'      => t('Core statistics regarding taxonomy.'),
+    'munin_core_taxonomy' => [
+      '#title' => t('Core taxonomy statistics'),
+      '#info' => t('Core statistics regarding taxonomy.'),
       '#graph_vlabel' => t('Vocabularies (-)/Terms (+)'),
 
-      'vocab_count' => $int + array(
-        '#label'      => t('Vocabularies'),
-        '#info'       => t('Vocabularies'),
+      'vocab_count' => $int + [
+        '#label' => t('Vocabularies'),
+        '#info' => t('Vocabularies'),
         '#type' => MUNIN_API_GAUGE,
-      ),
-      'term_count' => $int + array(
-        '#label'      => t('Terms'),
-        '#info'       => t('Total terms across all vocabularies'),
+      ],
+      'term_count' => $int + [
+        '#label' => t('Terms'),
+        '#info' => t('Total terms across all vocabularies'),
         '#type' => MUNIN_API_GAUGE,
-      ),
-    ),
-  );
-
-  foreach ($roles as $rid => $name) {
-    $machine_name = str_replace(' ', '_', $name);
-    $ret['munin_core_roles']['role_'. $machine_name] = $int + array(
-      '#label'        => $name,
-      '#info'         => t('Number of users with the @role role', array('@role' => $name)),
-      '#type'   => MUNIN_API_GAUGE,
-    );
+      ],
+    ],
+  ];
+
+  foreach ($roles as $role) {
+    $machine_name = str_replace(' ', '_', $role);
+    $ret['munin_core_roles']['role_' . $machine_name] = $int + [
+      '#label' => $role,
+      '#info' => t('Number of users with the @role role', ['@role' => $role]),
+      '#type' => MUNIN_API_GAUGE,
+    ];
   }
   variable_set('munin_core_roles', $roles);
   return $ret;
@@ -142,39 +146,54 @@ function munin_core_munin_api_info() {
 function munin_core_munin_api_fetch($graph_name) {
   switch ($graph_name) {
     case 'munin_core':
-      $sq = 'SELECT COUNT(u.uid) cnt, u.status FROM {users} u WHERE u.uid <> 0 GROUP BY 2';
+      $sq = <<<SQL
+SELECT COUNT(u.uid) cnt, u.status 
+FROM {users} u 
+WHERE u.uid <> 0 
+GROUP BY 2
+SQL;
       $result = db_query($sq);
-      $users = array(0 => 0, 1 => 0);
-      while ($row = db_fetch_object($result)) {
+      $users = [0 => 0, 1 => 0];
+      foreach ($result as $row) {
         $users[$row->status] = $row->cnt;
       }
 
       $ret['user_active_count'] = $users[1];
       $ret['user_blocked_count'] = $users[0];
 
+      $sq = <<<SQL
+SELECT COUNT(*) cnt 
+FROM {sessions} s 
+WHERE s.uid <> 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60
+SQL;
+      $ret['user_current'] = db_query($sq)
+        ->fetchField();
 
-      $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.uid <> 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60';
-      $ret['user_current'] = db_result(db_query($sq));
-
-      $sq = 'SELECT COUNT(*) cnt FROM {sessions} s WHERE s.uid = 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60';
-      $ret['anon_current'] = db_result(db_query($sq));
+      $sq = <<<SQL
+SELECT COUNT(*) cnt
+FROM {sessions} s
+WHERE s.uid = 0 AND s.timestamp >= UNIX_TIMESTAMP() - 5*60
+SQL;
+      $ret['anon_current'] = db_query($sq)
+        ->fetchField();
       break;
 
     case 'munin_core_roles':
-      $roles = variable_get('munin_core_roles', array());
-      $ph = db_placeholders($roles);
-      $sq = <<<EOT
-SELECT COUNT(ur.uid) cnt, r.rid, r.name
+      $roles = variable_get('munin_core_roles', []);
+      $sq = <<<SQL
+SELECT COUNT(ur.uid) cnt, 
+  r.rid, r.name
 FROM {role} r
   LEFT JOIN {users_roles} ur ON r.rid = ur.rid
-WHERE r.rid IN ($ph)
+WHERE r.rid IN (:roles)
 GROUP BY 2, 3
-EOT;
-      $ret = array();
-      $q = db_query($sq, array_keys($roles));
-      while ($o = db_fetch_object($q)) {
+SQL;
+      $ret = [];
+      $q = db_query($sq, [':roles' => array_keys($roles)]);
+      foreach ($q as $o) {
         $name = str_replace(' ', '_', $o->name);
-        $ret['role_'. $name] = empty($o->cnt) ? 0 : $o->cnt; // Can be NULL
+        // Can be NULL.
+        $ret['role_' . $name] = empty($o->cnt) ? 0 : $o->cnt;
       }
       break;
 
@@ -186,10 +205,15 @@ EOT;
         'comment_count' => 0,
       );
 
-      $sq = 'SELECT COUNT(*) cnt, n.status FROM {node} n GROUP BY n.status';
-      // No db_rewrite_sql(): this is an administrative mechanism
+      $sq = <<<SQL
+SELECT COUNT(*) cnt, n.status
+FROM {node} n 
+GROUP BY n.status
+SQL;
+      // No dynamic-query addTag('node_access'): this is an administrative
+      // mechanism, which needs to count all nodes.
       $q = db_query($sq);
-      while ($o = db_fetch_object($q)) {
+      foreach ($q as $o) {
         switch ($o->status) {
           case 0:
             $ret['node_count_unpub'] = $o->cnt;
@@ -202,39 +226,53 @@ EOT;
           default:
             watchdog('munin_core', 'Nodes with status @status reported: @count', array(
               '@status' => $o->status,
-              '@count'  => $o->cnt,
+              '@count' => $o->cnt,
             ), WATCHDOG_NOTICE);
         }
       }
 
-      $sq = 'SELECT COUNT(*) cnt, c.status FROM {comments} c GROUP BY c.status';
-      $q = db_query($sq);
-      // No db_rewrite_sql(): this is an administrative mechanism
-      while ($o = db_fetch_object($q)) {
-        switch ($o->status) {
-          case 1:
-            $ret['comment_count_unpub'] = $o->cnt;
-            break;
+      // Unlike node, comment may be disabled.
+      if (module_exists('comment')) {
+        $sq = <<<SQL
+SELECT COUNT(*) cnt, c.status 
+FROM {comments} c 
+GROUP BY c.status
+SQL;
+        $q = db_query($sq);
+        // No dynamic-query addTag('node_access'): this is an administrative
+        // mechanism, which needs to count all nodes.
+        foreach ($q as $o) {
+          switch ($o->status) {
+            case 1:
+              $ret['comment_count_unpub'] = $o->cnt;
+              break;
 
-          case 0:
-            $ret['comment_count'] = $o->cnt;
-            break;
+            case 0:
+              $ret['comment_count'] = $o->cnt;
+              break;
 
-          default:
-            watchdog('munin_core', 'Comments with status @status reported: @count', array(
-              '@status' => $o->status,
-              '@count'  => $o->cnt,
-            ), WATCHDOG_NOTICE);
+            default:
+              watchdog('munin_core', 'Comments with status @status reported: @count', array(
+                '@status' => $o->status,
+                '@count' => $o->cnt,
+              ), WATCHDOG_NOTICE);
+          }
         }
       }
       break;
 
     case 'munin_core_taxonomy':
-      $sq = 'SELECT COUNT(*) FROM {term_data}';
-      $ret['term_count'] = db_result(db_query($sq));
+      if (!module_exists('taxonomy')) {
+        $ret['term_count'] = 0;
+        $ret['vocab_count'] = 0;
+      }
+      else {
+        $sq = 'SELECT COUNT(*) FROM {taxonomy_term_data}';
+        $ret['term_count'] = db_query($sq)->fetchField();
 
-      $sq = 'SELECT COUNT(*) FROM {vocabulary}';
-      $ret['vocab_count'] = db_result(db_query($sq));
+        $sq = 'SELECT COUNT(*) FROM {taxonomy_vocabulary}';
+        $ret['vocab_count'] = db_query($sq)->fetchField();
+      }
       break;
   }
 

+ 7 - 12
munin_api.info

@@ -1,22 +1,17 @@
-; $Id$
-;
 ; @file
 ; Munin API for Drupal: module manifest
-; 
 ;
-; @author Frederic G. MARAND
-; 
-; @copyright (c) 2011 Ouest Systèmes Informatiques
-; 
+; @copyright (c) 2011-2019 Ouest Systèmes Informatiques
+;
 ; Licensed under the General Public License version 2 or later.
 
 name = "Munin API"
 description = "An API to make modules instrumented for Munin stats"
 package = Administration
+core = 7.x
+php = 7.1
 
-core = 6.x
+dependencies[] = advanced_help
 
-project = "munin_api"
-datestamp = "1296219892"
-project status url = http://features.osinet.eu/fserver
-version = "6.x-1.0-dev11b0901"
+configure = admin/config/munin_api
+;project status url = http://features.osinet.eu/fserver

+ 54 - 37
munin_api.install

@@ -1,79 +1,96 @@
 <?php
-// $Id$
+
 /**
  * @file
  * Munin API for Drupal: installation and runtime checks.
  *
- * @author Frederic G. MARAND
- *
- * @copyright (c) 2011 Ouest Systèmes Informatiques
+ * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
  *
  * Licensed under the General Public License version 2 or later.
  */
 
+use Drupal\munin_api\Munin;
+
+require_once __DIR__ . '/src/Munin.php';
+
 /**
  * Implements hook_requirements().
  */
 function munin_api_requirements($phase) {
   $ret = array();
+  $t = get_t();
   if ($phase == 'runtime') {
-    $count = count(module_implements('munin_api_info'));
+    $count = count(module_implements(Munin::HOOK_INFO));
     switch ($count) {
       case 0:
-        $req = array(
-          'title' => t('Munin plugin modules'),
-          'value' => t('No plugin found'),
-          'description' => t('Munin API is enabled, but does not find any plugin, including the one built into the API.'),
+        $req = [
+          'title' => $t('Munin plugin modules'),
+          'value' => $t('No plugin found'),
+          'description' => $t('Munin API is enabled, but does not find any plugin, including the one built into the API.'),
           'severity' => REQUIREMENT_ERROR,
-          );
+        ];
         break;
 
       case 1:
-        $req = array(
-          'title' => t('Munin plugin modules'),
-          'value' => t('No Munin plugin module enabled beyond API'),
-          'description' => t('Munin API is enabled, but no plugin module is enabled to report to it except the one built within the API. You should either <a href="!link">enable some plugin modules</a> or <a href="!link">disable and uninstall Munin API</a>.', array(
-            '!link' => url('admin/build/modules'),
-          )),
+        $req = [
+          'title' => $t('Munin plugin modules'),
+          'value' => $t('No Munin plugin module enabled beyond API'),
+          'description' => $t('Munin API is enabled, but no plugin module is enabled to report to it except the one built within the API. You should either <a href="!link">enable some plugin modules</a> or <a href="!link">disable and uninstall Munin API</a>.', [
+            '!link' => url('admin/modules'),
+          ]),
           'severity' => REQUIREMENT_INFO,
-        );
+        ];
         break;
 
       default:
-        $req = array(
-          'title' => t('Munin plugin modules'),
-          // format plural although $count >= 2 because some languages have several plural forms
+        $req = [
+          'title' => $t('Munin plugin modules'),
+          // Format plural although $count >= 2 because some languages have
+          // several plural forms.
           'value' => format_plural($count, '1 Munin plugin enabled.',
-            '<a href="!link">@count Munin plugins</a> enabled.', array('!link' => url('admin/reports/munin_api'))),
+            '<a href="!link">@count Munin plugins</a> enabled.', [
+              '!link' => url(Munin::R_REPORTS),
+            ]
+          ),
           'severity' => REQUIREMENT_OK,
-        );
+        ];
     }
     $ret[] = $req;
   }
   elseif ($phase != 'install') {
-    // This should never happen and points to a severe error somewhere
-    watchdog('munin_api', 'Invalid phase %phase passed to %function', array(
+    // This should never happen and points to a severe error somewhere.
+    watchdog(Munin::MODULE, 'Invalid phase %phase passed to %function', [
       '%phase' => $phase,
       '%function' => __FUNCTION__,
-    ), WATCHDOG_ERROR);
+    ], WATCHDOG_ERROR);
   }
-  // else $phase == 'install', nothing to do.
+  /* else $phase == 'install', nothing to do. */
 
   return $ret;
 }
 
 /**
- * Implements hook_uninstall()
+ * Implements hook_install().
+ */
+function munin_api_install() {
+  variable_set(Munin::V_INIT_PATH, Munin::D_INIT_PATH);
+  variable_set(Munin::V_LAST, 0);
+  // Ensure reporting is indeed opt-in, forcing default to off.
+  variable_set(Munin::V_NEXT_REPORT, 0);
+  variable_set(Munin::V_WATCHDOG, Munin::D_WATCHDOG);
+}
+
+/**
+ * Implements hook_uninstall().
  */
 function munin_api_uninstall() {
-  $vars = array(
-    'init_path',
-    'last',
-    'next_report',
-    'watchdog',
-  );
-  foreach ($vars as $tail) {
-    $name = 'munin_api_'. $tail;
-    variable_del($name);
+  $vars = [
+    Munin::V_INIT_PATH,
+    Munin::V_LAST,
+    Munin::V_NEXT_REPORT,
+    Munin::V_WATCHDOG,
+  ];
+  foreach ($vars as $var) {
+    variable_del($var);
   }
-}
+}

+ 1 - 4
munin_api.js

@@ -1,12 +1,9 @@
-// $Id$
 
 /**
  * @file
  * Munin API for Drupal: settings UI eye candy
  *
- * @author Frederic G. MARAND
- *
- * @copyright (c) 2011 Ouest Systèmes Informatiques
+ * @copyright (c) 2011-2019 Ouest Systèmes Informatiques
  *
  * Licensed under the General Public License version 2 or later.
  */

File diff suppressed because it is too large
+ 125 - 70
munin_api.module


+ 4 - 4
plugins/munin-drupal_

@@ -2,20 +2,20 @@
 #
 # Munin plugin using the munin_api module and submodules to log Drupal info.
 #
-# (c) 2011 Ouest Systèmes Informatiques (OSInet)
+# (c) 2011-2019 Ouest Systèmes Informatiques (OSInet)
 #
 # Licensed under the General Public License version 2 or later.
 #
-# This plugin uses CURL to access the Drupal instance over HTTP. For most 
+# This plugin uses CURL to access the Drupal instance over HTTP. For most
 # plugin modules, this could also work in CLI mode using Drush, and a Drush
-# plugin implementation is a no-brainer. However, in most cases, this will be a 
+# plugin implementation is a no-brainer. However, in most cases, this will be a
 # lower performance option, because CLI code is not cached in APC, causing
 # extra I/O load to fetch the files from disk everytime, whereas they will
 # normally be cached in APC when using HTTP access.
 
 SUB=$(basename $0 | sed s/drupal_/munin_/)
 
-# The timeout needs to be "not too short", because on 
+# The timeout needs to be "not too short", because on
 # system reboot, munin will often send probes before
 # Apache is ready and, if they timeout, will not register
 # the Munin plugins invoking this scripts for further

+ 37 - 0
src/Munin.php

@@ -0,0 +1,37 @@
+<?php
+
+namespace Drupal\munin_api;
+
+/**
+ * Class Munin contains constants to avoid magic strings in the module code.
+ */
+class Munin {
+  const MODULE = 'munin_api';
+
+  // The meta-probe, monitoring Munin from Drupal.
+  const PROBE_MUNIN = 'munin_munin';
+
+  // The module hooks.
+  const HOOK_FETCH = self::MODULE . '_fetch';
+  const HOOK_INFO = self::MODULE . '_info';
+
+  // Routes (paths in D7).
+  const R_BASE = self::MODULE;
+  const R_CONFIG = 'admin/config/' . self::MODULE;
+  const R_REPORTS = 'admin/reports/' . self::MODULE;
+
+  // Variables (config, settings, state in D7).
+  const V_INIT_PATH = self::MODULE . '_init_path';
+  const V_LAST = self::MODULE . '_last';
+  const V_NEXT_REPORT = self::MODULE . '_next_report';
+  const V_WATCHDOG = self::MODULE . '_watchdog';
+
+  const V_WATCHDOG_CRON = 'cron';
+  const V_WATCHDOG_NONE = 'none';
+  const V_WATCHDOG_INIT = 'init';
+
+  // Variable defaults.
+  const D_INIT_PATH = '/^$/';
+  const D_WATCHDOG = self::V_WATCHDOG_CRON;
+
+}

Some files were not shown because too many files changed in this diff