munin_api.module 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * An API to help modules expose their instrumentation to Munin.
  6. */
  7. define('MUNIN_API_COUNTER', 'counter');
  8. define('MUNIN_API_GAUGE', 'gauge');
  9. /**
  10. * Menu loader for %menu_api_instance.
  11. */
  12. function munin_api_instance_load($name) {
  13. $module = module_invoke($name, 'munin_api_info');
  14. $module = empty($module)
  15. ? FALSE
  16. : $module[$name];
  17. return $module;
  18. }
  19. function munin_api_menu() {
  20. $items = array();
  21. $items['admin/reports/munin_api'] = array(
  22. 'title' => 'Munin',
  23. 'description' => 'Reports about Munin data collectors and their probes',
  24. 'page callback' => 'munin_api_page_report_global',
  25. 'access arguments' => array('access site reports'),
  26. );
  27. $items['admin/reports/munin_api/list'] = array(
  28. 'type' => MENU_DEFAULT_LOCAL_TASK,
  29. 'title' => 'General',
  30. );
  31. $items['admin/reports/munin_api/list/%munin_api_instance'] = array(
  32. 'type' => MENU_CALLBACK,
  33. 'page callback' => 'munin_api_page_report_instance',
  34. 'page arguments' => array(4),
  35. 'access arguments' => array('access site reports'),
  36. );
  37. return $items;
  38. }
  39. /**
  40. * Page callback for Munin report
  41. *
  42. * @return string
  43. */
  44. function munin_api_page_report_global() {
  45. $items = module_invoke_all('munin_api_info');
  46. $header = array(
  47. t('Module'),
  48. t('Description'),
  49. t('Stats'),
  50. );
  51. $rows = array();
  52. foreach ($items as $name => $item) {
  53. $link_title = $item['#title'] ? $item['#title'] : $name;
  54. $rows[] = array(
  55. l($link_title, 'admin/reports/munin_api/list/'. $name),
  56. isset($item['#description']) ? $item['#description'] : t('&lt;missing&gt;'),
  57. count(element_children($item)),
  58. );
  59. }
  60. $ret = theme('table', $header, $rows);
  61. return $ret;
  62. }
  63. function munin_api_page_report_instance($module) {
  64. $title = isset($module['#title']) ? $module['#title'] : t('Info');
  65. drupal_set_title($title);
  66. $header = array(t('Name'), t('Description'), t('Type'));
  67. $rows = array();
  68. foreach (element_children($module) as $name) {
  69. $rows[] = array(
  70. $name,
  71. isset($module[$name]['#title']) ? $module[$name]['#title'] : t('&lt;missing&gt;'),
  72. $module[$name]['#type'],
  73. );
  74. }
  75. $ret = theme('table', $header, $rows);
  76. return $ret;
  77. }