From dc807917aaad2a88c0f79584b90d6253710a3734 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 20 Jun 2014 09:39:25 +1000 Subject: [PATCH 1/3] Add elapsed time to user and pool stats --- src/stratifier.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 49bbe00e..16965448 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -195,6 +195,7 @@ struct user_instance { tv_t last_share; time_t last_stats; + time_t start_time; double dsps1; double dsps5; @@ -1110,9 +1111,13 @@ static user_instance_t *authorise_user(const char *workername) ck_ilock(&instance_lock); HASH_FIND_STR(user_instances, username, instance); if (!instance) { + ts_t now; + /* New user instance */ instance = ckzalloc(sizeof(user_instance_t)); strcpy(instance->username, username); + ts_realtime(&now); + instance->start_time = now.tv_sec; ck_ulock(&instance_lock); instance->id = user_instance_id++; @@ -2020,16 +2025,19 @@ static void update_userstats(ckpool_t *ckp) ck_rlock(&instance_lock); HASH_ITER(hh, user_instances, instance, tmp) { double ghs1, ghs5, ghs60, ghs1440; + int elapsed; if (instance->last_stats > now_t - 600) continue; + elapsed = now_t - instance->start_time; instance->last_stats = now_t; ghs1 = instance->dsps1 * nonces; ghs5 = instance->dsps5 * nonces; ghs60 = instance->dsps60 * nonces; ghs1440 = instance->dsps1440 * nonces; - val = json_pack("{ss,ss,sf,sf,sf,sf,ss,ss,ss,ss}", + val = json_pack("{ss,si,ss,sf,sf,sf,sf,ss,ss,ss,ss}", "poolinstance", ckp->name, + "elapsed", elapsed, "username", instance->username, "hashrate", ghs1, "hashrate5m", ghs5, @@ -2196,8 +2204,9 @@ static void *statsupdate(void *arg) ts_realtime(&ts_now); sprintf(cdfield, "%lu,%lu", ts_now.tv_sec, ts_now.tv_nsec); - val = json_pack("{ss,si,si,sf,sf,sf,sf,ss,ss,ss,ss}", + val = json_pack("{ss,si,si,si,sf,sf,sf,sf,ss,ss,ss,ss}", "poolinstance", ckp->name, + "elapsed", diff.tv_sec, "users", stats.users, "workers", stats.workers, "hashrate", ghs1, From e40128a2da1e3dab782ec34ed4c00a14858dc63b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 20 Jun 2014 09:58:51 +1000 Subject: [PATCH 2/3] Allow the loglevel to be changed on the fly --- src/ckpool.c | 25 +++++++++++++++++++++++++ src/connector.c | 4 ++++ src/generator.c | 4 ++++ src/stratifier.c | 2 ++ 4 files changed, 35 insertions(+) diff --git a/src/ckpool.c b/src/ckpool.c index 84639d9e..674aadf8 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -130,6 +130,17 @@ void ckmsgq_add(ckmsgq_t *ckmsgq, void *data) mutex_unlock(&ckmsgq->lock); } +static void broadcast_proc(ckpool_t *ckp, const char *buf) +{ + int i; + + for (i = 0; i < ckp->proc_instances; i++) { + proc_instance_t *pi = ckp->children[i]; + + send_proc(pi, buf); + } +} + /* Listen for incoming global requests. Always returns a response if possible */ static void *listener(void *arg) { @@ -159,6 +170,20 @@ retry: } else if (!strncasecmp(buf, "ping", 4)) { LOGDEBUG("Listener received ping request"); send_unix_msg(sockd, "pong"); + } else if (!strncasecmp(buf, "loglevel", 8)) { + int loglevel; + + if (sscanf(buf, "loglevel=%d", &loglevel) != 1) { + LOGWARNING("Failed to parse loglevel message %s", buf); + send_unix_msg(sockd, "Failed"); + } else if (loglevel < LOG_EMERG || loglevel > LOG_DEBUG) { + LOGWARNING("Invalid loglevel %d sent", loglevel); + send_unix_msg(sockd, "Invalid"); + } else { + ckp->loglevel = loglevel; + broadcast_proc(ckp, buf); + send_unix_msg(sockd, "success"); + } } else if (!strncasecmp(buf, "getfd", 5)) { char *msg; diff --git a/src/connector.c b/src/connector.c index 9c5c5a68..ae0893ce 100644 --- a/src/connector.c +++ b/src/connector.c @@ -506,6 +506,10 @@ retry: ci->accept = false; goto retry; } + if (!strncasecmp(buf, "loglevel", 8)) { + sscanf(buf, "loglevel=%d", &ckp->loglevel); + goto retry; + } LOGDEBUG("Connector received message: %s", buf); if (!strncasecmp(buf, "shutdown", 8)) diff --git a/src/generator.c b/src/generator.c index af2fa6aa..e6853ae0 100644 --- a/src/generator.c +++ b/src/generator.c @@ -279,6 +279,8 @@ retry: LOGNOTICE("Submitting block data!"); if (submit_block(cs, buf + 12)) send_proc(ckp->stratifier, "block"); + } else if (!strncasecmp(buf, "loglevel", 8)) { + sscanf(buf, "loglevel=%d", &ckp->loglevel); } else if (!strncasecmp(buf, "ping", 4)) { LOGDEBUG("Generator received ping request"); send_unix_msg(sockd, "pong"); @@ -1253,6 +1255,8 @@ retry: pthread_cancel(proxi->pth_precv); pthread_cancel(proxi->pth_psend); goto reconnect; + } else if (!strncasecmp(buf, "loglevel", 8)) { + sscanf(buf, "loglevel=%d", &ckp->loglevel); } else if (!strncasecmp(buf, "ping", 4)) { LOGDEBUG("Proxy received ping request"); send_unix_msg(sockd, "pong"); diff --git a/src/stratifier.c b/src/stratifier.c index 16965448..783aa9a3 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -963,6 +963,8 @@ retry: } else if (!strncasecmp(buf, "block", 5)) { block_solve(ckp); update_base(ckp); + } else if (!strncasecmp(buf, "loglevel", 8)) { + sscanf(buf, "loglevel=%d", &ckp->loglevel); } else { json_t *val = json_loads(buf, 0, NULL); From b289046ffe644de2f76ff0d5b312c1c654fda06e Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 20 Jun 2014 12:02:51 +1000 Subject: [PATCH 3/3] Demote the socket file exists message to notice level --- src/ckpool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ckpool.c b/src/ckpool.c index 674aadf8..a9f234c1 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -529,7 +529,7 @@ static bool write_pid(ckpool_t *ckp, const char *path, pid_t pid) if (!stat(path, &statbuf)) { int oldpid; - LOGWARNING("File %s exists", path); + LOGNOTICE("File %s exists", path); fp = fopen(path, "r"); if (!fp) { LOGEMERG("Failed to open file %s", path);