> From: Jeff Garzik <jgarzik@xxxxxxxxx> > Subject: Re: Tabled issues > Date: Mon, 29 Mar 2010 15:32:33 -0400 > I asserted that the standard stats dump facility must dump > all available statistics. That does not exclude other methods > of stat(us) dumping. Your patch added new stats to the HTML-pretty > version of output, but failed to add the new stats to the standard > stat dump facility. Your wish is my command. Signed-off-by: Pete Zaitcev <zaitcev@xxxxxxxxxx> --- server/replica.c | 28 +++++++++++++++++++++++++ server/server.c | 47 ++++++++++++++++++++++++++++++++++-------- server/status.c | 22 +------------------ server/storage.c | 50 +++++++++++++++++++++++++++++++++++++++++---- server/tabled.h | 3 ++ 5 files changed, 117 insertions(+), 33 deletions(-) commit 6bba495d750dcc7ebe63938b91d4bb22740879fe Author: Pete Zaitcev <zaitcev@xxxxxxxxx> Date: Thu Apr 1 18:58:08 2010 -0600 Make signal+applog and HTTP displays uniform. diff --git a/server/replica.c b/server/replica.c index abdd647..e774824 100644 --- a/server/replica.c +++ b/server/replica.c @@ -871,6 +871,34 @@ void rep_start() kscan_enabled = true; } +void rep_stats() +{ + bool running; + unsigned long kcnt; + time_t last; + + applog(LOG_INFO, "REP: Jobs: queued %d active %d done %d", + queue.njobs, active.njobs, done.njobs); + + g_mutex_lock(kscan_mutex); + running = kscan_running; + last = kscan_last; + kcnt = kscan_cnt; + g_mutex_unlock(kscan_mutex); + + if (running) { + applog(LOG_INFO, "REP: run Active started %lu scanned %lu", + (long) last, kcnt); + } else { + if (last) + applog(LOG_INFO, + "REP: run Done started %lu scanned %lu", + (long) last, kcnt); + else + applog(LOG_INFO, "REP: run None"); + } +} + bool rep_status(struct client *cli, GList *content) { time_t now; diff --git a/server/server.c b/server/server.c index e0d785c..72db151 100644 --- a/server/server.c +++ b/server/server.c @@ -370,21 +370,50 @@ static void stats_signal(int signo) write(tabled_srv.ev_pipe[1], &cmd, 1); } -#define X(stat) \ - applog(LOG_INFO, "STAT %s %lu", #stat, tabled_srv.stats.stat) - static void stats_dump(void) { - X(poll); - X(event); - X(tcp_accept); - X(opt_write); - applog(LOG_INFO, "State: TDB %s", + applog(LOG_INFO, "STATE: TDB %s", state_name_tdb[tabled_srv.state_tdb]); + applog(LOG_INFO, + "STATS: poll %lu event %lu tcp_accept %lu opt_write %lu", + tabled_srv.stats.poll, + tabled_srv.stats.event, + tabled_srv.stats.tcp_accept, + tabled_srv.stats.opt_write); stor_stats(); + rep_stats(); } -#undef X +bool stat_status(struct client *cli, GList *content) +{ + char *str; + + /* + * The loadavg is system dependent, we'll figure it out later. + * On Linux, applications read from /proc/loadavg. + */ + if (asprintf(&str, + "<h1>Status</h1>" + "<p>Host %s port %s</p>\r\n", + tabled_srv.ourhost, tabled_srv.port) < 0) + return false; + content = g_list_append(content, str); + if (asprintf(&str, + "<p>State: TDB %s</p>\r\n", + state_name_tdb[tabled_srv.state_tdb]) < 0) + return false; + content = g_list_append(content, str); + if (asprintf(&str, + "<p>Stats: " + "poll %lu event %lu tcp_accept %lu opt_write %lu</p>\r\n", + tabled_srv.stats.poll, + tabled_srv.stats.event, + tabled_srv.stats.tcp_accept, + tabled_srv.stats.opt_write) < 0) + return false; + content = g_list_append(content, str); + return true; +} static bool cli_write_free(struct client *cli, struct client_write *tmp, bool done) diff --git a/server/status.c b/server/status.c index bb67ac9..2029c09 100644 --- a/server/status.c +++ b/server/status.c @@ -114,25 +114,6 @@ out: return false; } -static bool stat_status(struct client *cli, GList *content) -{ - char *str; - - /* - * The loadavg is system dependent, we'll figure it out later. - * On Linux, applications read from /proc/loadavg. - */ - if (asprintf(&str, - "<h1>Status</h1>" - "<p>Host %s port %s</p>\r\n" - "<p>Stats: poll %lu event %lu</p>\r\n", - tabled_srv.ourhost, tabled_srv.port, - tabled_srv.stats.poll, tabled_srv.stats.event) < 0) - return false; - content = g_list_append(content, str); - return true; -} - static bool stat_root(struct client *cli) { GList *content = NULL; @@ -149,7 +130,8 @@ static bool stat_root(struct client *cli) if (!stat_status(cli, content)) goto out_err; - + if (!stor_status(cli, content)) + goto out_err; if (!rep_status(cli, content)) goto out_err; diff --git a/server/storage.c b/server/storage.c index 913ef33..7dab625 100644 --- a/server/storage.c +++ b/server/storage.c @@ -533,11 +533,53 @@ void stor_stats() g_mutex_lock(tabled_srv.bigmutex); now = time(NULL); list_for_each_entry(sn, &tabled_srv.all_stor, all_link) { - applog(LOG_INFO, "SN nid %u %s last %lu (+ %ld) ref %d name %s", - sn->id, sn->up? "up": "down", - (long) sn->last_up, (long) (now - sn->last_up), - sn->ref, sn->hostname); + if (sn->last_up) { + applog(LOG_INFO, + "SN: nid %u %s ref %d name %s last %lu (+ %ld)", + sn->id, sn->up? "up": "down", + sn->ref, sn->hostname, + (long) sn->last_up, (long) (now - sn->last_up)); + } else { + applog(LOG_INFO, + "SN: nid %u %s ref %d name %s", + sn->id, sn->up? "up": "down", + sn->ref, sn->hostname); + } } g_mutex_unlock(tabled_srv.bigmutex); } +bool stor_status(struct client *cli, GList *content) +{ + struct storage_node *sn; + static char tag_down[] = + "<span style=\"background-color:red\">down</span>"; + time_t now; + char *str; + int rc; + + g_mutex_lock(tabled_srv.bigmutex); + now = time(NULL); + list_for_each_entry(sn, &tabled_srv.all_stor, all_link) { + if (sn->last_up) { + rc = asprintf(&str, + "SN: nid %u %s ref %d name %s" + " last %lu (+ %ld)<br />\r\n", + sn->id, sn->up? "up": tag_down, + sn->ref, sn->hostname, + (long) sn->last_up, + (long) (now - sn->last_up)); + } else { + rc = asprintf(&str, + "SN: nid %u %s ref %d name %s<br />\r\n", + sn->id, sn->up? "up": tag_down, + sn->ref, sn->hostname); + } + if (rc < 0) + break; + content = g_list_append(content, str); + } + g_mutex_unlock(tabled_srv.bigmutex); + return true; +} + diff --git a/server/tabled.h b/server/tabled.h index 72bf20d..b4f51ed 100644 --- a/server/tabled.h +++ b/server/tabled.h @@ -315,6 +315,7 @@ extern void req_sign(struct http_req *req, const char *bucket, const char *key, extern int debugging; extern struct server tabled_srv; extern struct compiled_pat patterns[]; +extern bool stat_status(struct client *cli, GList *content); extern bool cli_err(struct client *cli, enum errcode code); extern bool cli_err_write(struct client *cli, char *hdr, char *content); extern bool cli_resp_xml(struct client *cli, int http_status, GList *content); @@ -357,6 +358,7 @@ extern void stor_add_node(uint32_t nid, const char *hostname, const char *portstr, struct geo *locp); extern int stor_node_check(struct storage_node *stn); extern void stor_stats(void); +extern bool stor_status(struct client *cli, GList *content); /* storparse.c */ extern void stor_parse(char *fname, const char *text, size_t len); @@ -364,6 +366,7 @@ extern void stor_parse(char *fname, const char *text, size_t len); /* replica.c */ extern void rep_init(struct event_base *ev_base); extern void rep_start(void); +extern void rep_stats(void); extern bool rep_status(struct client *cli, GList *content); #endif /* __TABLED_H__ */ -- To unsubscribe from this list: send the line "unsubscribe hail-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html