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.
 
 
 

112 lines
3.2 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 "logging.h"
  24. #include "plugins.h"
  25. #include "probe.h"
  26. #define BUFSIZE 1024
  27. struct sammler_plugin plugin;
  28. static char *buffer;
  29. static const char *ds_def = {
  30. "DS:pgalloc_high:DERIVE:15:0:U "
  31. "DS:pgalloc_normal:DERIVE:15:0:U "
  32. "DS:pgalloc_dma:DERIVE:15:0:U "
  33. "DS:pgfree:DERIVE:15:0:U "
  34. "DS:pgfault:DERIVE:15:0:U "
  35. };
  36. static const char * get_ds(int ds_id)
  37. {
  38. return ds_def;
  39. }
  40. struct vmstat_ {
  41. unsigned long long pgalloc_high;
  42. unsigned long long pgalloc_normal;
  43. unsigned long long pgalloc_dma;
  44. unsigned long long pgfree;
  45. unsigned long long pgfault;
  46. };
  47. static int probe(void)
  48. {
  49. FILE *fp;
  50. struct vmstat_ vmstat;
  51. memset(&vmstat, 0, sizeof(vmstat));
  52. fp = fopen("/proc/vmstat", "r");
  53. if (fp == NULL) {
  54. log_print(LOG_WARN, "plugin vmstat");
  55. return -1;
  56. }
  57. while (fgets(buffer, BUFSIZE, fp) != NULL) {
  58. if (!strncmp(buffer, "pgalloc_high", 12))
  59. vmstat.pgalloc_high = atoll(buffer + 13);
  60. else if (!strncmp(buffer, "pgalloc_normal", 14))
  61. vmstat.pgalloc_normal = atoll(buffer + 15);
  62. else if (!strncmp(buffer, "pgalloc_dma", 11))
  63. vmstat.pgalloc_dma = atoll(buffer + 12);
  64. else if (!strncmp(buffer, "pgfree", 6))
  65. vmstat.pgfree = atoll(buffer + 7);
  66. else if (!strncmp(buffer, "pgfault", 7))
  67. vmstat.pgfault = atoll(buffer + 8);
  68. }
  69. probe_submit(&plugin, "vmstat.rrd", 0, "%llu:%llu:%llu:%llu:%llu",
  70. vmstat.pgalloc_high, vmstat.pgalloc_normal,
  71. vmstat.pgalloc_dma, vmstat.pgfree, vmstat.pgfault);
  72. fclose(fp);
  73. return 0;
  74. }
  75. static int init(void)
  76. {
  77. buffer = malloc(BUFSIZE);
  78. return (buffer == NULL) ? -1 : 0;
  79. }
  80. static int fini(void)
  81. {
  82. free(buffer);
  83. return 0;
  84. }
  85. struct sammler_plugin plugin = {
  86. .name = "vmstat",
  87. .interval = 10,
  88. .init = &init,
  89. .fini = &fini,
  90. .probe = &probe,
  91. .get_ds = &get_ds,
  92. };