rrd based system stats
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

124 lines
3.6 KiB

  1. /***************************************************************************
  2. * Copyright (C) 06/2006 by Olaf Rempel *
  3. * razzor@kopf-tisch.de *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  19. ***************************************************************************/
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include "helper.h"
  24. #include "plugins.h"
  25. #include "probe.h"
  26. #define DS_STAT 1
  27. #define DS_GC 2
  28. struct sammler_plugin plugin;
  29. static const char *ds_def_stat = {
  30. "DS:in_hit:DERIVE:15:0:U "
  31. "DS:in_slow_tot:DERIVE:15:0:U "
  32. "DS:in_slow_mc:DERIVE:15:0:U "
  33. "DS:in_no_route:DERIVE:15:0:U "
  34. "DS:in_brd:DERIVE:15:0:U "
  35. "DS:in_martian_dst:DERIVE:15:0:U "
  36. "DS:in_martian_src:DERIVE:15:0:U "
  37. "DS:out_hit:DERIVE:15:0:U "
  38. "DS:out_slow_tot:DERIVE:15:0:U "
  39. "DS:out_slow_mc:DERIVE:15:0:U "
  40. "DS:in_hlist_search:DERIVE:15:0:U "
  41. "DS:out_hlist_search:DERIVE:15:0:U "
  42. };
  43. static const char *ds_def_gc = {
  44. "DS:entries:GAUGE:15:0:U "
  45. "DS:gc_total:DERIVE:15:0:U "
  46. "DS:gc_ignored:DERIVE:15:0:U "
  47. "DS:gc_goal_miss:DERIVE:15:0:U "
  48. "DS:gc_dst_overflow:DERIVE:15:0:U "
  49. };
  50. static const char * get_ds(int ds_id)
  51. {
  52. switch (ds_id) {
  53. case DS_STAT:
  54. return ds_def_stat;
  55. case DS_GC:
  56. return ds_def_gc;
  57. default:
  58. return NULL;
  59. }
  60. }
  61. static int probe(void)
  62. {
  63. FILE *fp;
  64. char *val[17], filename[16];
  65. unsigned long long arr[17];
  66. int i, len, cpu = 0;
  67. fp = fopen("/proc/net/stat/rt_cache", "r");
  68. if (fp == NULL) {
  69. log_print(LOG_WARN, "plugin rtstat");
  70. return -1;
  71. }
  72. while (fgets(plugin.buffer, plugin.bufsize, fp) != NULL) {
  73. if (!strncmp(plugin.buffer, "entries", 7))
  74. continue;
  75. if (strsplit(plugin.buffer, " \t\n", val, 17) != 17)
  76. continue;
  77. for (i = 0; i < 17; i++)
  78. arr[i] = strtoll(val[i], NULL, 16);
  79. len = snprintf(filename, sizeof(filename), "rtstat-%d.rrd", cpu);
  80. if (len < 0 || len >= sizeof(filename))
  81. continue;
  82. probe_submit(&plugin, filename, DS_STAT,
  83. "%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
  84. arr[1], arr[2], arr[3], arr[4],
  85. arr[5], arr[6], arr[7], arr[8],
  86. arr[9], arr[10], arr[15], arr[16]);
  87. len = snprintf(filename, sizeof(filename), "rtcache-%d.rrd", cpu);
  88. if (len < 0 || len >= sizeof(filename))
  89. continue;
  90. probe_submit(&plugin, filename, DS_GC,
  91. "%llu:%llu:%llu:%llu:%llu",
  92. arr[0], arr[11], arr[12], arr[13], arr[14]);
  93. cpu++;
  94. }
  95. fclose(fp);
  96. return 0;
  97. }
  98. struct sammler_plugin plugin = {
  99. .name = "rtstat",
  100. .interval = 10,
  101. .bufsize = 1024,
  102. .probe = &probe,
  103. .get_ds = &get_ds,
  104. };