Add monitor hook (Redis and files)

closes #4
This commit is contained in:
Jan-Piet Mens
2015-08-15 13:18:27 +02:00
parent a5c76dcf1f
commit b050057200
3 changed files with 30 additions and 3 deletions
+14
View File
@@ -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)
+14 -3
View File
@@ -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) {
}
}
+2
View File
@@ -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