From: Pavel Rochnyak Date: Tue, 28 Aug 2018 15:31:01 +0000 (+0600) Subject: Merge pull request #2907 from Stackdriver/pkg-fix X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=c6bbe9f6737ec8611c1ab6146a1d0d32d9365eea;hp=2ea44cd8935a750f54460da6bc33d9c60d5237c0 Merge pull request #2907 from Stackdriver/pkg-fix Fix warning that pkgdatadir and pkglibdir were previously defined. --- diff --git a/src/chrony.c b/src/chrony.c index 6fb369a2..913aab94 100644 --- a/src/chrony.c +++ b/src/chrony.c @@ -38,6 +38,11 @@ #include /* ntohs/ntohl */ #endif +/* AIX doesn't have MSG_DONTWAIT */ +#ifndef MSG_DONTWAIT +#define MSG_DONTWAIT MSG_NONBLOCK +#endif + #define CONFIG_KEY_HOST "Host" #define CONFIG_KEY_PORT "Port" #define CONFIG_KEY_TIMEOUT "Timeout" @@ -440,6 +445,15 @@ static int chrony_recv_response(tChrony_Response *p_resp, } } +static void chrony_flush_recv_queue(void) { + char buf[1]; + + if (g_chrony_is_connected) { + while (recv(g_chrony_socket, buf, sizeof(buf), MSG_DONTWAIT) > 0) + ; + } +} + static int chrony_query(const int p_command, tChrony_Request *p_req, tChrony_Response *p_resp, size_t *p_resp_size) { /* Check connection. We simply perform one try as collectd already handles @@ -964,6 +978,9 @@ static int chrony_read(void) { g_chrony_seq_is_initialized = 1; } + /* Ignore late responses that may have been received */ + chrony_flush_recv_queue(); + /* Get daemon stats */ rc = chrony_request_daemon_stats(); if (rc != CHRONY_RC_OK) diff --git a/src/collectd.conf.in b/src/collectd.conf.in index fb1471f1..af652145 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -1276,6 +1276,7 @@ # # Host "redis.example.com" # Port "6379" +# #Socket "/var/run/redis/redis.sock" # Timeout 2000 # # #Database 0 diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 1134541a..6e6d6eaf 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -7359,6 +7359,7 @@ parameters and set of user-defined queries for this node. Host "localhost" Port "6379" + #Socket "/var/run/redis/redis.sock" Timeout 2000 ReportCommandStats false ReportCpuUsage true @@ -7392,6 +7393,11 @@ The B option is the TCP port on which the Redis instance accepts connections. Either a service name of a port number may be given. Please note that numerical port numbers must be given as a string, too. +=item B I + +Connect to Redis using the UNIX domain socket at I. If this +setting is given, the B and B settings are ignored. + =item B I Use I to authenticate when connecting to I. diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c index b93e9cc9..c2017aca 100644 --- a/src/daemon/plugin.c +++ b/src/daemon/plugin.c @@ -146,6 +146,7 @@ static bool plugin_ctx_key_initialized; static long write_limit_high; static long write_limit_low; +static pthread_mutex_t statistics_lock = PTHREAD_MUTEX_INITIALIZER; static derive_t stats_values_dropped; static bool record_statistics; @@ -2076,7 +2077,6 @@ static bool check_drop_value(void) /* {{{ */ EXPORT int plugin_dispatch_values(value_list_t const *vl) { int status; - static pthread_mutex_t statistics_lock = PTHREAD_MUTEX_INITIALIZER; if (check_drop_value()) { if (record_statistics) { @@ -2106,6 +2106,15 @@ plugin_dispatch_multivalue(value_list_t const *template, /* {{{ */ gauge_t sum = 0.0; va_list ap; + if (check_drop_value()) { + if (record_statistics) { + pthread_mutex_lock(&statistics_lock); + stats_values_dropped++; + pthread_mutex_unlock(&statistics_lock); + } + return 0; + } + assert(template->values_len == 1); /* Calculate sum for Gauge to calculate percent if needed */ diff --git a/src/dbi.c b/src/dbi.c index fe9bc516..899c802c 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -603,15 +603,16 @@ static int cdbi_read_database_query(cdbi_database_t *db, /* {{{ */ } /* }}} */ /* Get the next row from the database. */ + if (!dbi_result_has_next_row(res)) + break; + status = dbi_result_next_row(res); /* {{{ */ if (status != 1) { - if (dbi_conn_error(db->connection, NULL) != 0) { - char errbuf[1024]; - WARNING("dbi plugin: cdbi_read_database_query (%s, %s): " - "dbi_result_next_row failed: %s.", - db->name, udb_query_get_name(q), - cdbi_strerror(db->connection, errbuf, sizeof(errbuf))); - } + char errbuf[1024]; + WARNING("dbi plugin: cdbi_read_database_query (%s, %s): " + "dbi_result_next_row failed: %s.", + db->name, udb_query_get_name(q), + cdbi_strerror(db->connection, errbuf, sizeof(errbuf))); break; } /* }}} */ } /* }}} while (42) */ diff --git a/src/redis.c b/src/redis.c index 41442b66..e24abd54 100644 --- a/src/redis.c +++ b/src/redis.c @@ -70,6 +70,7 @@ typedef struct redis_node_s redis_node_t; struct redis_node_s { char *name; char *host; + char *socket; char *passwd; int port; struct timeval timeout; @@ -97,9 +98,11 @@ static void redis_node_free(void *arg) { rq = next; } - redisFree(rn->redisContext); + if (rn->redisContext) + redisFree(rn->redisContext); sfree(rn->name); sfree(rn->host); + sfree(rn->socket); sfree(rn->passwd); sfree(rn); } /* void redis_node_free */ @@ -212,6 +215,8 @@ static int redis_config_node(oconfig_item_t *ci) /* {{{ */ rn->port = status; status = 0; } + } else if (strcasecmp("Socket", option->key) == 0) { + status = cf_util_get_string(option, &rn->socket); } else if (strcasecmp("Query", option->key) == 0) { redis_query_t *rq = redis_config_query(option); if (rq == NULL) { @@ -590,15 +595,23 @@ static void redis_check_connection(redis_node_t *rn) { if (rn->redisContext) return; - redisContext *rh = redisConnectWithTimeout(rn->host, rn->port, rn->timeout); + redisContext *rh; + if (rn->socket != NULL) + rh = redisConnectUnixWithTimeout(rn->socket, rn->timeout); + else + rh = redisConnectWithTimeout(rn->host, rn->port, rn->timeout); if (rh == NULL) { ERROR("redis plugin: can't allocate redis context"); return; } if (rh->err) { - ERROR("redis plugin: unable to connect to node `%s' (%s:%d): %s.", rn->name, - rn->host, rn->port, rh->errstr); + if (rn->socket) + ERROR("redis plugin: unable to connect to node `%s' (%s): %s.", rn->name, + rn->socket, rh->errstr); + else + ERROR("redis plugin: unable to connect to node `%s' (%s:%d): %s.", + rn->name, rn->host, rn->port, rh->errstr); redisFree(rh); return; } @@ -759,8 +772,14 @@ static int redis_read(user_data_t *user_data) /* {{{ */ { redis_node_t *rn = user_data->data; - DEBUG("redis plugin: querying info from node `%s' (%s:%d).", rn->name, - rn->host, rn->port); +#if COLLECT_DEBUG + if (rn->socket) + DEBUG("redis plugin: querying info from node `%s' (%s).", rn->name, + rn->socket); + else + DEBUG("redis plugin: querying info from node `%s' (%s:%d).", rn->name, + rn->host, rn->port); +#endif redis_check_connection(rn);