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.
 
 
 

111 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 <mntent.h>
  23. #include <sys/vfs.h>
  24. #include <string.h>
  25. #include "plugins.h"
  26. #include "probe.h"
  27. struct sammler_plugin plugin;
  28. static const char *ds_def = {
  29. "DS:block_total:GAUGE:15:0:U "
  30. "DS:block_free:GAUGE:15:0:U "
  31. };
  32. static const char * get_ds(int ds_id)
  33. {
  34. return ds_def;
  35. }
  36. static int probe(void)
  37. {
  38. FILE *fp;
  39. struct mntent *mnt;
  40. struct statfs fs;
  41. char *slash, filename[64];
  42. int len;
  43. fp = setmntent("/etc/mtab", "r");
  44. if (fp == NULL) {
  45. log_print(LOG_WARN, "plugin mount");
  46. return -1;
  47. }
  48. while ((mnt = getmntent(fp)) != NULL) {
  49. if (!strcmp(mnt->mnt_fsname, "none"))
  50. continue;
  51. if (!strcmp(mnt->mnt_fsname, "proc"))
  52. continue;
  53. if (!strcmp(mnt->mnt_fsname, "sysfs"))
  54. continue;
  55. if (!strcmp(mnt->mnt_fsname, "udev"))
  56. continue;
  57. if (!strcmp(mnt->mnt_fsname, "devpts"))
  58. continue;
  59. if (!strcmp(mnt->mnt_type, "nfs"))
  60. continue;
  61. if (!strcmp(mnt->mnt_type, "tmpfs"))
  62. continue;
  63. if (statfs(mnt->mnt_dir, &fs) == -1) {
  64. log_print(LOG_WARN, "plugin mount: statfs(%s)", mnt->mnt_dir);
  65. continue;
  66. }
  67. if (fs.f_blocks == 0)
  68. continue;
  69. slash = mnt->mnt_fsname;
  70. while (slash && (slash = strchr(slash, '/'))) {
  71. slash = strchr(slash, '/');
  72. *slash++ = '_';
  73. }
  74. len = snprintf(filename, sizeof(filename), "mount%s.rrd", mnt->mnt_fsname);
  75. if (len < 0 || len >= sizeof(filename)) {
  76. log_print(LOG_WARN, "plugin mount: file name too long", mnt->mnt_fsname);
  77. continue;
  78. }
  79. probe_submit(&plugin, filename, 0, "%lu:%lu",
  80. fs.f_blocks * (fs.f_bsize /1024),
  81. fs.f_bfree * (fs.f_bsize /1024));
  82. }
  83. endmntent(fp);
  84. return 0;
  85. }
  86. struct sammler_plugin plugin = {
  87. .name = "mount",
  88. .interval = 10,
  89. .probe = &probe,
  90. .get_ds = &get_ds,
  91. };