Browse Source

Add API function to get worker stats

master
Con Kolivas 10 years ago
parent
commit
fe93a914e1
  1. 44
      src/stratifier.c

44
src/stratifier.c

@ -2451,13 +2451,51 @@ static void getuser(sdata_t *sdata, const char *buf, int *sockd)
"user", user->username, "id", user->id, "workers", user->workers, "user", user->username, "id", user->id, "workers", user->workers,
"bestdiff", user->best_diff, "dsps1", user->dsps1, "dsps5", user->dsps5, "bestdiff", user->best_diff, "dsps1", user->dsps1, "dsps5", user->dsps5,
"dsps60", user->dsps60, "dsps1440", user->dsps1440, "dsps10080", user->dsps10080, "dsps60", user->dsps60, "dsps1440", user->dsps1440, "dsps10080", user->dsps10080,
"lastshare", user->last_update.tv_sec); "lastshare", user->last_share.tv_sec);
out: out:
free(username); free(username);
send_api_response(val, *sockd); send_api_response(val, *sockd);
_Close(sockd); _Close(sockd);
} }
static worker_instance_t *get_worker(sdata_t *sdata, user_instance_t *user, const char *workername);
static void getworker(sdata_t *sdata, const char *buf, int *sockd)
{
char *tmp, *username, *workername = NULL;
worker_instance_t *worker;
user_instance_t *user;
json_error_t err_val;
json_t *val = NULL;
val = json_loads(buf, 0, &err_val);
if (unlikely(!val)) {
val = json_encode_errormsg(&err_val);
goto out;
}
if (!json_get_string(&workername, val, "worker")) {
val = json_errormsg("Failed to find worker key");
goto out;
}
if (!strlen(workername)) {
val = json_errormsg("Zero length worker key");
goto out;
}
tmp = strdupa(workername);
username = strsep(&tmp, "._");
user = get_user(sdata, username);
worker = get_worker(sdata, user, workername);
JSON_CPACK(val, "{ss,ss,sI,sf,sf,sf,sf,si,sf,si,sb}",
"user", username, "worker", workername, "id", user->id,
"dsps1", worker->dsps1, "dsps5", worker->dsps5, "dsps60", worker->dsps60,
"dsps1440", worker->dsps1440, "lastshare", worker->last_share.tv_sec,
"bestdiff", worker->best_diff, "mindiff", worker->mindiff, "idle", worker->idle);
out:
free(workername);
send_api_response(val, *sockd);
_Close(sockd);
}
/* Return the user masked priority value of the proxy */ /* Return the user masked priority value of the proxy */
static int proxy_prio(const proxy_t *proxy) static int proxy_prio(const proxy_t *proxy)
{ {
@ -2639,6 +2677,10 @@ retry:
getuser(sdata, buf + 8, &sockd); getuser(sdata, buf + 8, &sockd);
goto retry; goto retry;
} }
if (cmdmatch(buf, "getworker")) {
getworker(sdata, buf + 10, &sockd);
goto retry;
}
if (cmdmatch(buf, "getproxy")) { if (cmdmatch(buf, "getproxy")) {
getproxy(sdata, buf + 9, &sockd); getproxy(sdata, buf + 9, &sockd);
goto retry; goto retry;

Loading…
Cancel
Save