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.
 
 
 

141 lines
3.8 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 "logging.h"
  25. #include "plugins.h"
  26. #include "probe.h"
  27. #define DS_STAT 1
  28. #define DS_GC 2
  29. #define BUFSIZE 1024
  30. struct sammler_plugin plugin;
  31. static char *buffer;
  32. static const char *ds_def_stat = {
  33. "DS:in_hit:DERIVE:15:0:U "
  34. "DS:in_slow_tot:DERIVE:15:0:U "
  35. "DS:in_slow_mc:DERIVE:15:0:U "
  36. "DS:in_no_route:DERIVE:15:0:U "
  37. "DS:in_brd:DERIVE:15:0:U "
  38. "DS:in_martian_dst:DERIVE:15:0:U "
  39. "DS:in_martian_src:DERIVE:15:0:U "
  40. "DS:out_hit:DERIVE:15:0:U "
  41. "DS:out_slow_tot:DERIVE:15:0:U "
  42. "DS:out_slow_mc:DERIVE:15:0:U "
  43. "DS:in_hlist_search:DERIVE:15:0:U "
  44. "DS:out_hlist_search:DERIVE:15:0:U "
  45. };
  46. static const char *ds_def_gc = {
  47. "DS:entries:GAUGE:15:0:U "
  48. "DS:gc_total:DERIVE:15:0:U "
  49. "DS:gc_ignored:DERIVE:15:0:U "
  50. "DS:gc_goal_miss:DERIVE:15:0:U "
  51. "DS:gc_dst_overflow:DERIVE:15:0:U "
  52. };
  53. static const char * get_ds(int ds_id)
  54. {
  55. switch (ds_id) {
  56. case DS_STAT:
  57. return ds_def_stat;
  58. case DS_GC:
  59. return ds_def_gc;
  60. default:
  61. return NULL;
  62. }
  63. }
  64. static int probe(void)
  65. {
  66. FILE *fp;
  67. char *val[17], filename[16];
  68. unsigned long long arr[17];
  69. int i, len, cpu = 0;
  70. fp = fopen("/proc/net/stat/rt_cache", "r");
  71. if (fp == NULL) {
  72. log_print(LOG_WARN, "plugin rtstat");
  73. return -1;
  74. }
  75. while (fgets(buffer, BUFSIZE, fp) != NULL) {
  76. if (!strncmp(buffer, "entries", 7))
  77. continue;
  78. if (strsplit(buffer, " \t\n", val, 17) != 17)
  79. continue;
  80. for (i = 0; i < 17; i++)
  81. arr[i] = strtoll(val[i], NULL, 16);
  82. len = snprintf(filename, sizeof(filename), "rtstat-%d.rrd", cpu);
  83. if (len < 0 || len >= sizeof(filename))
  84. continue;
  85. probe_submit(&plugin, filename, DS_STAT,
  86. "%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
  87. arr[1], arr[2], arr[3], arr[4],
  88. arr[5], arr[6], arr[7], arr[8],
  89. arr[9], arr[10], arr[15], arr[16]);
  90. len = snprintf(filename, sizeof(filename), "rtcache-%d.rrd", cpu);
  91. if (len < 0 || len >= sizeof(filename))
  92. continue;
  93. probe_submit(&plugin, filename, DS_GC,
  94. "%llu:%llu:%llu:%llu:%llu",
  95. arr[0], arr[11], arr[12], arr[13], arr[14]);
  96. cpu++;
  97. }
  98. fclose(fp);
  99. return 0;
  100. }
  101. static int init(void)
  102. {
  103. buffer = malloc(BUFSIZE);
  104. return (buffer == NULL) ? -1 : 0;
  105. }
  106. static int fini(void)
  107. {
  108. free(buffer);
  109. return 0;
  110. }
  111. struct sammler_plugin plugin = {
  112. .name = "rtstat",
  113. .interval = 10,
  114. .init = &init,
  115. .fini = &fini,
  116. .probe = &probe,
  117. .get_ds = &get_ds,
  118. };