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.
 
 
 

126 lines
3.4 KiB

  1. /***************************************************************************
  2. * Copyright (C) 10/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 "configfile.h"
  24. #include "helper.h"
  25. #include "list.h"
  26. #include "logging.h"
  27. #include "plugins.h"
  28. #include "probe.h"
  29. struct sammler_plugin plugin;
  30. struct hwmon_entry {
  31. struct list_head list;
  32. char *name;
  33. char *path;
  34. };
  35. static LIST_HEAD(hwmon_list);
  36. static const char *ds_def = {
  37. "DS:temp:GAUGE:15:0:U "
  38. };
  39. static const char * get_ds(int ds_id)
  40. {
  41. return ds_def;
  42. }
  43. static int probe(void)
  44. {
  45. struct hwmon_entry *entry;
  46. list_for_each_entry(entry, &hwmon_list, list) {
  47. FILE *fp = fopen(entry->path, "r");
  48. if (fp == NULL) {
  49. log_print(LOG_WARN, "plugin hwmon: fopen(%s)", entry->path);
  50. continue;
  51. }
  52. int temp;
  53. if (fscanf(fp, "%d\n", &temp) != 1) {
  54. log_print(LOG_WARN, "plugin hwmon: fscanf()");
  55. fclose(fp);
  56. continue;
  57. }
  58. fclose(fp);
  59. char filename[32];
  60. int len = snprintf(filename, sizeof(filename), "hwmon-%s.rrd", entry->name);
  61. if (len < 0 || len >= sizeof(filename))
  62. continue;
  63. probe_submit(&plugin, filename, 0, "%d", temp);
  64. }
  65. return 0;
  66. }
  67. static int init_cb(struct strtoken *tokens, void *privdata)
  68. {
  69. if (tokens->count != 2) {
  70. log_print(LOG_ERROR, "p_hwmon: parse error");
  71. return -1;
  72. }
  73. struct hwmon_entry *entry = malloc(sizeof(struct hwmon_entry));
  74. if (entry == NULL) {
  75. log_print(LOG_ERROR, "p_hwmon: out of memory");
  76. return -1;
  77. }
  78. entry->name = strdup(tokens->field[0]);
  79. entry->path = strdup(tokens->field[1]);
  80. log_print(LOG_DEBUG, "p_hwmon: added sensor '%s' (%s)", entry->name, entry->path);
  81. list_add_tail(&entry->list, &hwmon_list);
  82. return 0;
  83. }
  84. static int init(void)
  85. {
  86. config_get_strtokens("p_hwmon", "temp", ",", 2, init_cb, NULL);
  87. return 0;
  88. }
  89. static int fini(void)
  90. {
  91. struct hwmon_entry *entry, *tmp;
  92. list_for_each_entry_safe(entry, tmp, &hwmon_list, list) {
  93. free(entry->name);
  94. free(entry->path);
  95. free(entry);
  96. }
  97. return 0;
  98. }
  99. struct sammler_plugin plugin = {
  100. .name = "hwmon",
  101. .interval = 10,
  102. .init = &init,
  103. .fini = &fini,
  104. .probe = &probe,
  105. .get_ds = &get_ds,
  106. };