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.
 
 
 

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