From e31b615e6201fccda3f2e036c449646e3cfbac25 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 7 Mar 2012 12:12:15 +0100 Subject: [PATCH] Better MONITOR output, now includes client ip:port or the lua string if the command was executed by the scripting engine. --- src/redis.c | 2 +- src/redis.h | 2 +- src/replication.c | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/redis.c b/src/redis.c index 452c3bb75..6d5522e82 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1248,7 +1248,7 @@ void call(redisClient *c, int flags) { /* Sent the command to clients in MONITOR mode, only if the commands are * not geneated from reading an AOF. */ if (listLength(server.monitors) && !server.loading) - replicationFeedMonitors(server.monitors,c->db->id,c->argv,c->argc); + replicationFeedMonitors(c,server.monitors,c->db->id,c->argv,c->argc); /* Call the command. */ redisOpArrayInit(&server.also_propagate); diff --git a/src/redis.h b/src/redis.h index 870439d7b..c18e91700 100644 --- a/src/redis.h +++ b/src/redis.h @@ -932,7 +932,7 @@ int syncReadLine(int fd, char *ptr, ssize_t size, int timeout); /* Replication */ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc); -void replicationFeedMonitors(list *monitors, int dictid, robj **argv, int argc); +void replicationFeedMonitors(redisClient *c, list *monitors, int dictid, robj **argv, int argc); void updateSlavesWaitingBgsave(int bgsaveerr); void replicationCron(void); diff --git a/src/replication.c b/src/replication.c index e82978395..6c0091e8c 100644 --- a/src/replication.c +++ b/src/replication.c @@ -50,17 +50,23 @@ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) { } } -void replicationFeedMonitors(list *monitors, int dictid, robj **argv, int argc) { +void replicationFeedMonitors(redisClient *c, list *monitors, int dictid, robj **argv, int argc) { listNode *ln; listIter li; - int j; + int j, port; sds cmdrepr = sdsnew("+"); robj *cmdobj; + char ip[32]; struct timeval tv; gettimeofday(&tv,NULL); cmdrepr = sdscatprintf(cmdrepr,"%ld.%06ld ",(long)tv.tv_sec,(long)tv.tv_usec); - if (dictid != 0) cmdrepr = sdscatprintf(cmdrepr,"(db %d) ", dictid); + if (c->flags & REDIS_LUA_CLIENT) { + cmdrepr = sdscatprintf(cmdrepr,"[%d lua] ", dictid); + } else { + anetPeerToString(c->fd,ip,&port); + cmdrepr = sdscatprintf(cmdrepr,"[%d %s:%d] ", dictid,ip,port); + } for (j = 0; j < argc; j++) { if (argv[j]->encoding == REDIS_ENCODING_INT) {