projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
turbostat plugin: Use parse_value_file().
[collectd.git]
/
src
/
teamspeak2.c
diff --git
a/src/teamspeak2.c
b/src/teamspeak2.c
index
d4bf2aa
..
a1cde32
100644
(file)
--- a/
src/teamspeak2.c
+++ b/
src/teamspeak2.c
@@
-18,17
+18,17
@@
*
* Authors:
* Stefan Hacker <d0t at dbclan dot de>
*
* Authors:
* Stefan Hacker <d0t at dbclan dot de>
- * Florian Forster <octo at
verplant
.org>
+ * Florian Forster <octo at
collectd
.org>
**/
#include "collectd.h"
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "common.h"
#include "plugin.h"
-#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/types.h>
-#include <sys/socket.h>
#include <netdb.h>
/*
#include <netdb.h>
/*
@@
-84,13
+84,12
@@
static int tss2_add_vserver (int vserver_port)
}
/* Allocate memory */
}
/* Allocate memory */
- entry =
(vserver_list_t *) malloc (sizeof (vserver_list_t
));
+ entry =
calloc (1, sizeof (*entry
));
if (entry == NULL)
{
if (entry == NULL)
{
- ERROR ("teamspeak2 plugin:
m
alloc failed.");
+ ERROR ("teamspeak2 plugin:
c
alloc failed.");
return (-1);
}
return (-1);
}
- memset (entry, 0, sizeof (vserver_list_t));
/* Save data */
entry->port = vserver_port;
/* Save data */
entry->port = vserver_port;
@@
-141,12
+140,12
@@
static void tss2_submit_gauge (const char *plugin_instance,
if (type_instance != NULL)
sstrncpy (vl.type_instance, type_instance,
sizeof (vl.type_instance));
if (type_instance != NULL)
sstrncpy (vl.type_instance, type_instance,
sizeof (vl.type_instance));
-
+
plugin_dispatch_values (&vl);
} /* void tss2_submit_gauge */
static void tss2_submit_io (const char *plugin_instance, const char *type,
plugin_dispatch_values (&vl);
} /* void tss2_submit_gauge */
static void tss2_submit_io (const char *plugin_instance, const char *type,
-
counter_t rx, counter
_t tx)
+
derive_t rx, derive
_t tx)
{
/*
* Submits the io rx/tx tuple to the collectd daemon
{
/*
* Submits the io rx/tx tuple to the collectd daemon
@@
-154,8
+153,8
@@
static void tss2_submit_io (const char *plugin_instance, const char *type,
value_t values[2];
value_list_t vl = VALUE_LIST_INIT;
value_t values[2];
value_list_t vl = VALUE_LIST_INIT;
- values[0].
counter
= rx;
- values[1].
counter
= tx;
+ values[0].
derive
= rx;
+ values[1].
derive
= tx;
vl.values = values;
vl.values_len = 2;
vl.values = values;
vl.values_len = 2;
@@
-200,9
+199,7
@@
static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
* Returns connected file objects or establishes the connection
* if it's not already present
*/
* Returns connected file objects or establishes the connection
* if it's not already present
*/
- struct addrinfo ai_hints;
struct addrinfo *ai_head;
struct addrinfo *ai_head;
- struct addrinfo *ai_ptr;
int sd = -1;
int status;
int sd = -1;
int status;
@@
-218,12
+215,11
@@
static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
}
/* Get all addrs for this hostname */
}
/* Get all addrs for this hostname */
- memset (&ai_hints, 0, sizeof (ai_hints));
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM
+ };
status = getaddrinfo ((config_host != NULL) ? config_host : DEFAULT_HOST,
(config_port != NULL) ? config_port : DEFAULT_PORT,
status = getaddrinfo ((config_host != NULL) ? config_host : DEFAULT_HOST,
(config_port != NULL) ? config_port : DEFAULT_PORT,
@@
-237,7
+233,7
@@
static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
}
/* Try all given hosts until we can connect to one */
}
/* Try all given hosts until we can connect to one */
- for (ai_ptr = ai_head; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (
struct addrinfo *
ai_ptr = ai_head; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
/* Create socket */
sd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
{
/* Create socket */
sd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
@@
-258,6
+254,7
@@
static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
WARNING ("teamspeak2 plugin: connect failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
close (sd);
WARNING ("teamspeak2 plugin: connect failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
close (sd);
+ sd = -1;
continue;
}
continue;
}
@@
-299,6
+296,13
@@
static int tss2_get_socket (FILE **ret_read_fh, FILE **ret_write_fh)
char *buffer_ptr;
buffer_ptr = fgets (buffer, sizeof (buffer), global_read_fh);
char *buffer_ptr;
buffer_ptr = fgets (buffer, sizeof (buffer), global_read_fh);
+ if (buffer_ptr == NULL)
+ {
+ WARNING ("teamspeak2 plugin: Unexpected EOF received "
+ "from remote host %s:%s.",
+ config_host ? config_host : DEFAULT_HOST,
+ config_port ? config_port : DEFAULT_PORT);
+ }
buffer[sizeof (buffer) - 1] = 0;
if (memcmp ("[TS]\r\n", buffer, 6) != 0)
buffer[sizeof (buffer) - 1] = 0;
if (memcmp ("[TS]\r\n", buffer, 6) != 0)
@@
-345,7
+349,7
@@
static int tss2_receive_line (FILE *fh, char *buffer, int buffer_size)
* Receive a single line from the given file object
*/
char *temp;
* Receive a single line from the given file object
*/
char *temp;
-
+
/*
* fgets is blocking but much easier then doing anything else
* TODO: Non-blocking Version would be safer
/*
* fgets is blocking but much easier then doing anything else
* TODO: Non-blocking Version would be safer
@@
-428,18
+432,18
@@
static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh,
char buffer[4096];
char *value;
char *endptr = NULL;
char buffer[4096];
char *value;
char *endptr = NULL;
-
+
status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
if (status != 0)
{
status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
if (status != 0)
{
- /* Set to NULL just to make sure noone uses these FHs anymore. */
+ /* Set to NULL just to make sure no
one uses these FHs anymore. */
read_fh = NULL;
write_fh = NULL;
ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
return (-1);
}
buffer[sizeof (buffer) - 1] = 0;
read_fh = NULL;
write_fh = NULL;
ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
return (-1);
}
buffer[sizeof (buffer) - 1] = 0;
-
+
if (strncmp ("average_packet_loss=", buffer,
strlen ("average_packet_loss=")) == 0)
{
if (strncmp ("average_packet_loss=", buffer,
strlen ("average_packet_loss=")) == 0)
{
@@
-455,9
+459,9
@@
static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh,
}
value++;
}
}
value++;
}
-
+
value = &buffer[20];
value = &buffer[20];
-
+
packet_loss = strtod (value, &endptr);
if (value == endptr)
{
packet_loss = strtod (value, &endptr);
if (value == endptr)
{
@@
-482,7
+486,7
@@
static int tss2_vserver_gapl (FILE *read_fh, FILE *write_fh,
buffer);
}
}
buffer);
}
}
-
+
*ret_value = packet_loss;
return (0);
} /* int tss2_vserver_gapl */
*ret_value = packet_loss;
return (0);
} /* int tss2_vserver_gapl */
@@
-498,14
+502,14
@@
static int tss2_read_vserver (vserver_list_t *vserver)
gauge_t users = NAN;
gauge_t channels = NAN;
gauge_t servers = NAN;
gauge_t users = NAN;
gauge_t channels = NAN;
gauge_t servers = NAN;
-
counter
_t rx_octets = 0;
-
counter
_t tx_octets = 0;
-
counter
_t rx_packets = 0;
-
counter
_t tx_packets = 0;
+
derive
_t rx_octets = 0;
+
derive
_t tx_octets = 0;
+
derive
_t rx_packets = 0;
+
derive
_t tx_packets = 0;
gauge_t packet_loss = NAN;
int valid = 0;
gauge_t packet_loss = NAN;
int valid = 0;
- char plugin_instance[DATA_MAX_NAME_LEN];
+ char plugin_instance[DATA_MAX_NAME_LEN]
= { 0 }
;
FILE *read_fh;
FILE *write_fh;
FILE *read_fh;
FILE *write_fh;
@@
-521,8
+525,6
@@
static int tss2_read_vserver (vserver_list_t *vserver)
if (vserver == NULL)
{
/* Request global information */
if (vserver == NULL)
{
/* Request global information */
- memset (plugin_instance, 0, sizeof (plugin_instance));
-
status = tss2_send_request (write_fh, "gi\r\n");
}
else
status = tss2_send_request (write_fh, "gi\r\n");
}
else
@@
-552,12
+554,12
@@
static int tss2_read_vserver (vserver_list_t *vserver)
char *key;
char *value;
char *endptr = NULL;
char *key;
char *value;
char *endptr = NULL;
-
+
/* Read one line of the server's answer */
status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
if (status != 0)
{
/* Read one line of the server's answer */
status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
if (status != 0)
{
- /* Set to NULL just to make sure noone uses these FHs anymore. */
+ /* Set to NULL just to make sure no
one uses these FHs anymore. */
read_fh = NULL;
write_fh = NULL;
ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
read_fh = NULL;
write_fh = NULL;
ERROR ("teamspeak2 plugin: tss2_receive_line failed.");
@@
-717,7
+719,7
@@
static int tss2_config (const char *key, const char *value)
/*
* Interpret configuration values
*/
/*
* Interpret configuration values
*/
- if (strcasecmp ("Host", key) == 0)
+
if (strcasecmp ("Host", key) == 0)
{
char *temp;
{
char *temp;
@@
-747,7
+749,7
@@
static int tss2_config (const char *key, const char *value)
{
/* Server variable found */
int status;
{
/* Server variable found */
int status;
-
+
status = tss2_add_vserver (atoi (value));
if (status != 0)
return (1);
status = tss2_add_vserver (atoi (value));
if (status != 0)
return (1);
@@
-767,7
+769,6
@@
static int tss2_read (void)
* Poll function which collects global and vserver information
* and submits it to collectd
*/
* Poll function which collects global and vserver information
* and submits it to collectd
*/
- vserver_list_t *vserver;
int success = 0;
int status;
int success = 0;
int status;
@@
-783,7
+784,7
@@
static int tss2_read (void)
}
/* Handle vservers */
}
/* Handle vservers */
- for (vserver = server_list; vserver != NULL; vserver = vserver->next)
+ for (vserver
_list_t *vserver
= server_list; vserver != NULL; vserver = vserver->next)
{
status = tss2_read_vserver (vserver);
if (status == 0)
{
status = tss2_read_vserver (vserver);
if (status == 0)
@@
-797,10
+798,10
@@
static int tss2_read (void)
continue;
}
}
continue;
}
}
-
+
if (success == 0)
return (-1);
if (success == 0)
return (-1);
- return (0);
+
return (0);
} /* int tss2_read */
static int tss2_shutdown(void)
} /* int tss2_read */
static int tss2_shutdown(void)
@@
-826,7
+827,7
@@
static int tss2_shutdown(void)
/* Get rid of the configuration */
sfree (config_host);
sfree (config_port);
/* Get rid of the configuration */
sfree (config_host);
sfree (config_port);
-
+
return (0);
} /* int tss2_shutdown */
return (0);
} /* int tss2_shutdown */