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.

62 lines
1.3KB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdarg.h>
  5. #include <unistd.h>
  6. #include "configfile.h"
  7. #include "logging.h"
  8. #include "network.h"
  9. #include "rrdtool.h"
  10. #define BUFSIZE 512
  11. #define SUBMIT_NET_ONLY 0x01
  12. static int submit_flags;
  13. static const char *hostname;
  14. int probe_init(void)
  15. {
  16. const char *fwd_only = config_get_string("global", "forward_only", "false");
  17. submit_flags = 0;
  18. if (!strncmp(fwd_only, "true", 4))
  19. submit_flags |= SUBMIT_NET_ONLY;
  20. static char hostname_buf[32];
  21. if (gethostname(hostname_buf, sizeof(hostname_buf)) != 0)
  22. strcpy(hostname_buf, "localhost");
  23. hostname = config_get_string("global", "hostname", hostname_buf);
  24. return 0;
  25. }
  26. int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... )
  27. {
  28. char *buffer = malloc(BUFSIZE);
  29. if (buffer == NULL) {
  30. log_print(LOG_ERROR, "probe_submit: out of memory");
  31. return -1;
  32. }
  33. va_list az;
  34. va_start(az, fmt);
  35. int len = vsnprintf(buffer, BUFSIZE, fmt, az);
  36. va_end(az);
  37. if (len < 0 || len >= BUFSIZE) {
  38. log_print(LOG_ERROR, "probe_submit: %s arguments too long", plugin->name);
  39. free(buffer);
  40. return -1;
  41. }
  42. net_submit(hostname, plugin->name, filename, ds_id, buffer);
  43. if (!(submit_flags & SUBMIT_NET_ONLY))
  44. rrd_submit(hostname, plugin->name, filename, ds_id, buffer);
  45. free(buffer);
  46. return 0;
  47. }