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.
 
 
 

153 lines
4.1 KiB

  1. /***************************************************************************
  2. * Copyright (C) 06/2010 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 <unistd.h>
  23. #include <string.h>
  24. #include <stdint.h>
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <fcntl.h>
  28. #include "configfile.h"
  29. #include "logging.h"
  30. #include "plugins.h"
  31. #include "probe.h"
  32. #include "sgio.h"
  33. int verbose = 0;
  34. int prefer_ata12 = 0;
  35. struct sammler_plugin plugin;
  36. struct device_entry {
  37. struct list_head list;
  38. char *devpath;
  39. };
  40. static LIST_HEAD(device_list);
  41. static const char *ds_def = {
  42. "DS:active:GAUGE:90:0:1 "
  43. };
  44. static const char * get_ds(int ds_id)
  45. {
  46. return ds_def;
  47. }
  48. static int probe(void)
  49. {
  50. struct device_entry *entry;
  51. list_for_each_entry(entry, &device_list, list) {
  52. int fd = open(entry->devpath, O_RDONLY|O_NONBLOCK);
  53. if (fd < 0) {
  54. log_print(LOG_ERROR, "%s: failed to open %s", plugin.name, entry->devpath);
  55. continue;
  56. }
  57. uint8_t args[4] = { ATA_OP_CHECKPOWERMODE1, 0, 0, 0 };
  58. if (do_drive_cmd(fd, args)) {
  59. args[0] = ATA_OP_CHECKPOWERMODE2;
  60. if (do_drive_cmd(fd, args)) {
  61. log_print(LOG_ERROR, "%s: failed to query %s", plugin.name, entry->devpath);
  62. close(fd);
  63. continue;
  64. }
  65. }
  66. /*
  67. switch (args[2]) {
  68. case 0x00: state = "standby"; break;
  69. case 0x40: state = "NVcache_spindown"; break;
  70. case 0x41: state = "NVcache_spinup"; break;
  71. case 0x80: state = "idle"; break;
  72. case 0xff: state = "active/idle"; break;
  73. default: state = "unknown"; break;
  74. }
  75. */
  76. char *dev = strrchr(entry->devpath, '/');
  77. if (dev == NULL) {
  78. dev = entry->devpath;
  79. } else {
  80. dev++;
  81. }
  82. char filename[32];
  83. int len = snprintf(filename, sizeof(filename), "diskstandby-%s.rrd", dev);
  84. if (len < 0 || len >= sizeof(filename))
  85. continue;
  86. probe_submit(&plugin, filename, 0, "%u", (args[2] == 0xff) ? 1 : 0);
  87. close(fd);
  88. }
  89. return 0;
  90. }
  91. static int init_cb(struct strtoken *tokens, void *privdata)
  92. {
  93. if (tokens->count != 1) {
  94. log_print(LOG_ERROR, "%s: parse error", plugin.name);
  95. return -1;
  96. }
  97. struct device_entry *entry = malloc(sizeof(struct device_entry));
  98. if (entry == NULL) {
  99. log_print(LOG_ERROR, "%s: out of memory", plugin.name);
  100. return -1;
  101. }
  102. entry->devpath = strdup(tokens->field[0]);
  103. log_print(LOG_INFO, "%s: added device '%s'", plugin.name, entry->devpath);
  104. list_add_tail(&entry->list, &device_list);
  105. return 0;
  106. }
  107. static int init(void)
  108. {
  109. config_get_strtokens("p_diskstandby", "device", ",", 1, init_cb, NULL);
  110. return 0;
  111. }
  112. static int fini(void)
  113. {
  114. struct device_entry *entry, *tmp;
  115. list_for_each_entry_safe(entry, tmp, &device_list, list) {
  116. free(entry->devpath);
  117. free(entry);
  118. }
  119. return 0;
  120. }
  121. struct sammler_plugin plugin = {
  122. .name = "diskstandby",
  123. .interval = 60,
  124. .init = &init,
  125. .fini = &fini,
  126. .probe = &probe,
  127. .get_ds = &get_ds,
  128. };