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.
 
 
 

103 lines
3.0 KiB

  1. /***************************************************************************
  2. * Copyright (C) 04/2007 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:read_cnt:COUNTER:15:0:U "
  31. "DS:read_sec:COUNTER:15:0:U "
  32. "DS:read_ms:COUNTER:15:0:U "
  33. "DS:write_cnt:COUNTER:15:0:U "
  34. "DS:write_sec:COUNTER:15:0:U "
  35. "DS:write_ms:COUNTER:15:0:U "
  36. };
  37. static const char * get_ds(int ds_id)
  38. {
  39. return ds_def;
  40. }
  41. static int probe(void)
  42. {
  43. FILE *fp = fopen("/proc/diskstats", "r");
  44. if (fp == NULL) {
  45. log_print(LOG_WARN, "plugin diskstats: fopen()");
  46. return -1;
  47. }
  48. while (fgets(buffer, BUFSIZE, fp) != NULL) {
  49. int major, minor;
  50. char device[16];
  51. unsigned int val[11];
  52. int cnt = sscanf(buffer, "%d %d %s %u %u %u %u %u %u %u %u %u %u %u",
  53. &major, &minor, device, &val[0],
  54. &val[1], &val[2], &val[3], &val[4],
  55. &val[5], &val[6], &val[7], &val[8],
  56. &val[9], &val[10]);
  57. if (cnt != 14 || val[0] == 0 || val[1] == 0)
  58. continue;
  59. char filename[32];
  60. int len = snprintf(filename, sizeof(filename), "disk-%s.rrd", device);
  61. if (len < 0 || len >= sizeof(filename))
  62. continue;
  63. probe_submit(&plugin, filename, 0,
  64. "%u:%u:%u:%u:%u:%u",
  65. val[0], val[2], val[3],
  66. val[4], val[6], val[7]);
  67. }
  68. fclose(fp);
  69. return 0;
  70. }
  71. static int init(void)
  72. {
  73. buffer = malloc(BUFSIZE);
  74. return (buffer == NULL) ? -1 : 0;
  75. }
  76. static int fini(void)
  77. {
  78. free(buffer);
  79. return 0;
  80. }
  81. struct sammler_plugin plugin = {
  82. .name = "diskstat",
  83. .interval = 10,
  84. .init = &init,
  85. .fini = &fini,
  86. .probe = &probe,
  87. .get_ds = &get_ds,
  88. };