diff --git a/ghash.c b/ghash.c index e47d477..7471795 100644 --- a/ghash.c +++ b/ghash.c @@ -38,6 +38,7 @@ void ghash_store_redis(redisContext **redis, char *ghash, char *addr, char *cc) return; } + void last_storeredis(redisContext **redis, char *username, char *device, char *jsonstring) { redisReply *r; @@ -89,6 +90,19 @@ int ghash_get_redis_cache(redisContext **redis, char *ghash, UT_string *addr, UT return (found); } + +void monitor_update(struct udata *ud, time_t now, char *topic) +{ + redisReply *r; + + redis_ping(&ud->redis); + + r = redisCommand(ud->redis, "HMSET ot-recorder-monitor time %ld topic %s", now, topic); + if (r) /* FIXME */ + return; + +} + #endif /* !HAVE_REDIS */ int ghash_readcache(struct udata *ud, char *ghash, UT_string *addr, UT_string *cc) diff --git a/misc.c b/misc.c index ddfe51a..84af322 100644 --- a/misc.c +++ b/misc.c @@ -26,7 +26,7 @@ char *bindump(char *buf, long buflen) /* * At each received message, the recorder invokes this function with the * current epoch time and the topic being handled. Use this to update - * a monitoring hoook. + * a monitoring hoook. If we have Redis, use that exclusively. */ void monitorhook(struct udata *userdata, time_t now, char *topic) @@ -35,8 +35,19 @@ void monitorhook(struct udata *userdata, time_t now, char *topic) #ifdef HAVE_REDIS if (ud->useredis) { + monitor_update(ud, now, topic); + return; + } +#else + if (ud->usefiles) { + char mpath[BUFSIZ]; + FILE *fp; + + sprintf(mpath, "%s/monitor", JSONDIR); + if ((fp = fopen(mpath, "w")) != NULL) { + fprintf(fp, "%ld %s\n", now, topic); + fclose(fp); + } } #endif - if (ud->usefiles) { - } } diff --git a/misc.h b/misc.h index cbc6068..8138085 100644 --- a/misc.h +++ b/misc.h @@ -13,4 +13,6 @@ int mkpath(char *path); char *bindump(char *buf, long buflen); void monitorhook(struct udata *ud, time_t now, char *topic); +void monitor_update(struct udata *ud, time_t now, char *topic); + #endif