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
3.2 KiB

  1. /***************************************************************************
  2. * Copyright (C) 04/2009 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 <unistd.h>
  24. #include <sys/socket.h>
  25. #include <sys/types.h>
  26. #include <sys/un.h>
  27. #include "configfile.h"
  28. #include "helper.h"
  29. #include "list.h"
  30. #include "logging.h"
  31. #include "plugins.h"
  32. #include "probe.h"
  33. struct sammler_plugin plugin;
  34. static const char *socket_path;
  35. static const char *ds_def = {
  36. "DS:ibat:GAUGE:15:U:U "
  37. "DS:ubat:GAUGE:15:0:U "
  38. "DS:uin:GAUGE:15:0:U "
  39. };
  40. static const char * get_ds(int ds_id)
  41. {
  42. return ds_def;
  43. }
  44. static int probe(void)
  45. {
  46. int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
  47. if (sockfd == -1) {
  48. log_print(LOG_WARN, "plugin alixusv: socket()");
  49. return -1;
  50. }
  51. struct sockaddr_un addr;
  52. addr.sun_family = AF_UNIX;
  53. strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path));
  54. int len = sizeof(addr.sun_family) + strlen(addr.sun_path);
  55. if (connect(sockfd, (struct sockaddr *)&addr, len) < 0) {
  56. log_print(LOG_ERROR, "plugin alixusv: connect(%s)", addr.sun_path);
  57. close(sockfd);
  58. return 0;
  59. }
  60. char buf[64] = "status";
  61. write(sockfd, buf, strlen(buf));
  62. len = read(sockfd, buf, sizeof(buf));
  63. if (len <= 0) {
  64. log_print(LOG_ERROR, "plugin alixusv: read()");
  65. close(sockfd);
  66. return -1;
  67. }
  68. close(sockfd);
  69. char *field[4];
  70. if (strsplit(buf, ": \t\n", field, 4) != 4)
  71. return -1;
  72. int ibat = strtoll(field[1], NULL, 10);
  73. int ubat = strtoll(field[2], NULL, 10);
  74. int uin = strtoll(field[3], NULL, 10);
  75. probe_submit(&plugin, "alixusv.rrd", 0, "%d:%d:%d", ibat, ubat, uin);
  76. return 0;
  77. }
  78. static int init(void)
  79. {
  80. socket_path = config_get_string("p_alixusv", "socket", NULL);
  81. return (socket_path == NULL) ? -1 : 0;
  82. }
  83. struct sammler_plugin plugin = {
  84. .name = "alixusv",
  85. .interval = 10,
  86. .init = &init,
  87. .probe = &probe,
  88. .get_ds = &get_ds,
  89. };