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.
 
 
 

107 lines
2.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 BUFSIZE 1024
  28. struct sammler_plugin plugin;
  29. static char *buffer;
  30. static const char *ds_def = {
  31. "DS:byte_in:COUNTER:15:0:U "
  32. "DS:byte_out:COUNTER:15:0:U "
  33. "DS:pkt_in:COUNTER:15:0:U "
  34. "DS:pkt_out:COUNTER:15:0:U "
  35. };
  36. static const char * get_ds(int ds_id)
  37. {
  38. return ds_def;
  39. }
  40. static int probe(void)
  41. {
  42. FILE *fp;
  43. char *stats, *device;
  44. char *val[16], filename[32];
  45. int len;
  46. fp = fopen("/proc/net/dev", "r");
  47. if (fp == NULL) {
  48. log_print(LOG_WARN, "plugin netdev");
  49. return -1;
  50. }
  51. while (fgets(buffer, BUFSIZE, fp) != NULL) {
  52. if (!(stats = strchr(buffer, ':')))
  53. continue;
  54. *stats++ = '\0';
  55. device = buffer;
  56. while (*device == ' ')
  57. device++;
  58. if (*device == '\0')
  59. continue;
  60. if (strsplit(stats, " \t\n", val, 16) != 16)
  61. continue;
  62. len = snprintf(filename, sizeof(filename), "net-%s.rrd", device);
  63. if (len < 0 || len >= sizeof(filename))
  64. continue;
  65. probe_submit(&plugin, filename, 0, "%s:%s:%s:%s",
  66. val[0], val[8], val[1], val[9]);
  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 = "netdev",
  83. .interval = 10,
  84. .init = &init,
  85. .fini = &fini,
  86. .probe = &probe,
  87. .get_ds = &get_ds,
  88. };