munin_api.module 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. function munin_api_menu() {
  10. $items = array();
  11. $items['admin/reports/munin_api'] = array(
  12. 'title' => 'Munin',
  13. 'description' => 'Reports about Munin data collectors and their probes',
  14. 'page callback' => 'munin_api_page_report_global',
  15. 'access arguments' => array('access site reports'),
  16. );
  17. $items['admin/reports/munin_api/list'] = array(
  18. 'type' => MENU_DEFAULT_LOCAL_TASK,
  19. 'title' => 'General',
  20. 'weight' => -1,
  21. );
  22. foreach (module_implements('munin_api_info') as $name) {
  23. $module = module_invoke($name, 'munin_api_info');
  24. $module = $module[$name];
  25. $items['admin/reports/munin_api/'. $name] = array(
  26. 'type' => MENU_LOCAL_TASK,
  27. 'title' => $module['#title'],
  28. 'description' => $module['#description'],
  29. 'page callback' => 'munin_api_page_report_instance',
  30. 'page arguments' => array(3),
  31. 'access arguments' => array('access site reports'),
  32. );
  33. }
  34. return $items;
  35. }
  36. /**
  37. * Page callback for Munin report
  38. *
  39. * @return string
  40. */
  41. function munin_api_page_report_global() {
  42. $items = module_invoke_all('munin_api_info');
  43. $header = array(
  44. t('Module'),
  45. t('Description'),
  46. t('Stats'),
  47. );
  48. $rows = array();
  49. foreach ($items as $name => $item) {
  50. $link_title = $item['#title'] ? $item['#title'] : $name;
  51. $rows[] = array(
  52. l($link_title, 'admin/reports/munin_api/'. $name),
  53. isset($item['#description']) ? $item['#description'] : t('&lt;missing&gt;'),
  54. count(element_children($item)),
  55. );
  56. }
  57. $ret = theme('table', $header, $rows);
  58. return $ret;
  59. }
  60. function munin_api_page_report_instance($module) {
  61. $module = module_invoke($module, 'munin_api_info');
  62. $module = reset($module);
  63. $header = array(t('Name'), t('Description'), t('Type'));
  64. $rows = array();
  65. foreach (element_children($module) as $name) {
  66. $rows[] = array(
  67. $name,
  68. isset($module[$name]['#title']) ? $module[$name]['#title'] : t('&lt;missing&gt;'),
  69. $module[$name]['#type'],
  70. );
  71. }
  72. $ret = theme('table', $header, $rows);
  73. return $ret;
  74. }