#include "collectd.h"
-#include "common.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include <hiredis/hiredis.h>
#include <sys/time.h>
struct redis_node_s {
char *name;
char *host;
+ char *socket;
char *passwd;
int port;
struct timeval timeout;
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 */
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) {
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;
}
"total_connections_received", DS_TYPE_DERIVE);
redis_handle_info(rn->name, rr->str, "total_operations", NULL,
"total_commands_processed", DS_TYPE_DERIVE);
- redis_handle_info(rn->name, rr->str, "operations_per_second", NULL,
- "instantaneous_ops_per_sec", DS_TYPE_GAUGE);
redis_handle_info(rn->name, rr->str, "expired_keys", NULL, "expired_keys",
DS_TYPE_DERIVE);
redis_handle_info(rn->name, rr->str, "evicted_keys", NULL, "evicted_keys",
{
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);