X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fipvs.c;h=92690e88e0098635a8cc56fe9c6191116b81082e;hb=51181b899668ad2c232a152d6e5e787c4eb049cc;hp=87eee108a79410853b6f02e107697b7a358f465a;hpb=c57f2a191b63ce73fc432befebe9fa3af97c8eb5;p=collectd.git diff --git a/src/ipvs.c b/src/ipvs.c index 87eee108..92690e88 100644 --- a/src/ipvs.c +++ b/src/ipvs.c @@ -31,21 +31,21 @@ */ #include "collectd.h" + #include "plugin.h" #include "common.h" #if HAVE_ARPA_INET_H # include #endif /* HAVE_ARPA_INET_H */ -#if HAVE_SYS_SOCKET_H -# include -#endif /* HAVE_SYS_SOCKET_H */ #if HAVE_NETINET_IN_H # include #endif /* HAVE_NETINET_IN_H */ /* this can probably only be found in the kernel sources */ -#if HAVE_NET_IP_VS_H +#if HAVE_LINUX_IP_VS_H +# include +#elif HAVE_NET_IP_VS_H # include #elif HAVE_IP_VS_H # include @@ -195,7 +195,7 @@ static int get_pi (struct ip_vs_service_entry *se, char *pi, size_t size) (se->protocol == IPPROTO_TCP) ? "TCP" : "UDP", ntohs (se->port)); - if ((0 > len) || (size <= len)) { + if ((0 > len) || (size <= ((size_t) len))) { log_err ("plugin instance truncated: %s", pi); return -1; } @@ -218,25 +218,24 @@ static int get_ti (struct ip_vs_dest_entry *de, char *ti, size_t size) len = ssnprintf (ti, size, "%s_%u", inet_ntoa (addr), ntohs (de->port)); - if ((0 > len) || (size <= len)) { + if ((0 > len) || (size <= ((size_t) len))) { log_err ("type instance truncated: %s", ti); return -1; } return 0; } /* get_ti */ -static void cipvs_submit_connections (char *pi, char *ti, counter_t value) +static void cipvs_submit_connections (const char *pi, const char *ti, + derive_t value) { value_t values[1]; value_list_t vl = VALUE_LIST_INIT; - values[0].counter = value; + values[0].derive = value; vl.values = values; vl.values_len = 1; - vl.interval = interval_g; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ipvs", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); @@ -248,20 +247,18 @@ static void cipvs_submit_connections (char *pi, char *ti, counter_t value) return; } /* cipvs_submit_connections */ -static void cipvs_submit_if (char *pi, char *t, char *ti, - counter_t rx, counter_t tx) +static void cipvs_submit_if (const char *pi, const char *t, const char *ti, + derive_t rx, derive_t tx) { 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.interval = interval_g; - sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "ipvs", sizeof (vl.plugin)); sstrncpy (vl.plugin_instance, pi, sizeof (vl.plugin_instance)); @@ -273,7 +270,8 @@ static void cipvs_submit_if (char *pi, char *t, char *ti, return; } /* cipvs_submit_if */ -static void cipvs_submit_dest (char *pi, struct ip_vs_dest_entry *de) { +static void cipvs_submit_dest (const char *pi, struct ip_vs_dest_entry *de) +{ struct ip_vs_stats_user stats = de->stats; char ti[DATA_MAX_NAME_LEN]; @@ -294,16 +292,17 @@ static void cipvs_submit_service (struct ip_vs_service_entry *se) char pi[DATA_MAX_NAME_LEN]; - int i = 0; - if (0 != get_pi (se, pi, sizeof (pi))) + { + free (dests); return; + } cipvs_submit_connections (pi, NULL, stats.conns); cipvs_submit_if (pi, "if_packets", NULL, stats.inpkts, stats.outpkts); cipvs_submit_if (pi, "if_octets", NULL, stats.inbytes, stats.outbytes); - for (i = 0; i < dests->num_dests; ++i) + for (size_t i = 0; i < dests->num_dests; ++i) cipvs_submit_dest (pi, &dests->entrytable[i]); free (dests); @@ -313,7 +312,6 @@ static void cipvs_submit_service (struct ip_vs_service_entry *se) static int cipvs_read (void) { struct ip_vs_get_services *services = NULL; - int i = 0; if (sockfd < 0) return (-1); @@ -321,7 +319,7 @@ static int cipvs_read (void) if (NULL == (services = ipvs_get_services ())) return -1; - for (i = 0; i < services->num_services; ++i) + for (size_t i = 0; i < services->num_services; ++i) cipvs_submit_service (&services->entrytable[i]); free (services);