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.
 
 
 

57 lines
1.2 KiB

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