From ebea62bfccc03c5da4a4bef199e1a4b97a0bedc8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zden=C4=9Bk=20=C5=A0ustr?= Date: Wed, 30 May 2012 16:22:48 +0000 Subject: [PATCH] - Provide server statistics in text format as well - Contruct stats list systematically - Return error code if statistics cannot be retireved --- org.glite.lb.server/src/lb_html.c | 119 +++++++++++---------------------- org.glite.lb.server/src/lb_html.h | 2 +- org.glite.lb.server/src/lb_proto.c | 12 +++- org.glite.lb.server/src/server_stats.h | 40 ++++++++++- 4 files changed, 85 insertions(+), 88 deletions(-) diff --git a/org.glite.lb.server/src/lb_html.c b/org.glite.lb.server/src/lb_html.c index 1711f59..acee5c9 100644 --- a/org.glite.lb.server/src/lb_html.c +++ b/org.glite.lb.server/src/lb_html.c @@ -534,89 +534,46 @@ int edg_wll_WSDLOutput(edg_wll_Context ctx UNUSED_VAR, char **message, char *fil return 0; } -int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message) { +int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message, int text) { char *out; + char* times[SERVER_STATISTICS_COUNT]; + int i; + char *out_tmp; + time_t *starttime; + + for (i = 0; i < SERVER_STATISTICS_COUNT; i++) + if (starttime = edg_wll_ServerStatisticsGetStart(ctx, i)) + if (text) asprintf(&(times[i]), "%ld", *starttime); + else times[i] = strdup((const char*)ctime(starttime)); + else + times[i] = NULL; + + if (!text) asprintf(&out, "\n\nServer Usage Statistics\n\n" + "

LB Server Usage Statistics

\n" + "%s" + "\n" + "\n", + edg_wll_ServerStatisticsInTmp() ? "WARNING: L&B statistics are stored in /tmp, please, configure L&B server to make them really persistent!

\n" : ""); + else + asprintf(&out, ""); + + for (i = 0; i < SERVER_STATISTICS_COUNT; i++) { + asprintf(&out_tmp, text ? "%s%s=%i,%s\n" : "%s\n", out, + text ? edg_wll_server_statistics_type_key[i] : edg_wll_server_statistics_type_title[i], + edg_wll_ServerStatisticsGetValue(ctx, i), + times[i]); + free(out); + out = out_tmp; + } - if (ctx->count_server_stats == 2 && !ctx->noAuth && !check_authz_policy_ctx(ctx, ADMIN_ACCESS)) - { - asprintf(&out,"

LB Server Usage Statistics

\n" - "Only superusers can view server usage statistics on this particular server.\n"); - } - else - { - char* times[SERVER_STATISTICS_COUNT]; - int i; - char *head; - for (i = 0; i < SERVER_STATISTICS_COUNT; i++) - if (edg_wll_ServerStatisticsGetStart(ctx, i)) - times[i] = strdup((const char*)ctime(edg_wll_ServerStatisticsGetStart(ctx, i))); - else - times[i] = 0; - - if (edg_wll_ServerStatisticsInTmp()) - asprintf(&head, - "WARNING: L&B statistics are stored in /tmp, please, configure L&B server to make them really persistent!

\n"); - else - asprintf(&head, " "); - - asprintf(&out, - "

LB Server Usage Statistics

\n" - "%s" - "
VariableValueMeasured from
%s%i%s
\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "
VariableValueMeasured from
gLite job regs%i%s
PBS job regs%i%s
Condor job regs%i%s
CREAM job regs%i%s
Sandbox regs%i%s
Notification regs (legacy interface)%i%s
Notification regs (msg interface)%i%s
Job events%i%s
Notifications sent (legacy)%i%s
Notifications sent (msg)%i%s
L&B protocol accesses%i%s
WS queries%i%s
HTML accesses%i%s
Plain text accesses%i%s
RSS accesses%i%s
\n", - head, - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_GLITEJOB_REGS), - times[SERVER_STATS_GLITEJOB_REGS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_PBSJOB_REGS), - times[SERVER_STATS_PBSJOB_REGS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_CONDOR_REGS), - times[SERVER_STATS_CONDOR_REGS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_CREAM_REGS), - times[SERVER_STATS_CREAM_REGS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_SANDBOX_REGS), - times[SERVER_STATS_SANDBOX_REGS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_NOTIF_LEGACY_REGS), - times[SERVER_STATS_NOTIF_LEGACY_REGS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_NOTIF_MSG_REGS), - times[SERVER_STATS_NOTIF_MSG_REGS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_JOB_EVENTS), - times[SERVER_STATS_JOB_EVENTS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_NOTIF_LEGACY_SENT), - times[SERVER_STATS_NOTIF_LEGACY_SENT], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_NOTIF_MSG_SENT), - times[SERVER_STATS_NOTIF_MSG_SENT], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_LBPROTO), - times[SERVER_STATS_LBPROTO], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_WS_QUERIES), - times[SERVER_STATS_WS_QUERIES], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_HTML_VIEWS), - times[SERVER_STATS_HTML_VIEWS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_TEXT_VIEWS), - times[SERVER_STATS_TEXT_VIEWS], - edg_wll_ServerStatisticsGetValue(ctx, SERVER_STATS_RSS_VIEWS), - times[SERVER_STATS_RSS_VIEWS] - ); - - for (i = 0; i < SERVER_STATISTICS_COUNT; i++) - free(times[i]); - free(head); - } + if (!text) { + asprintf(&out_tmp, "%s\n\n", out); + free(out); + out = out_tmp; + } + + for (i = 0; i < SERVER_STATISTICS_COUNT; i++) + free(times[i]); *message = out; return 0; diff --git a/org.glite.lb.server/src/lb_html.h b/org.glite.lb.server/src/lb_html.h index 682662d..675059d 100644 --- a/org.glite.lb.server/src/lb_html.h +++ b/org.glite.lb.server/src/lb_html.h @@ -33,6 +33,6 @@ int edg_wll_UserNotifsToHTML(edg_wll_Context ctx, char **notifids, char **messag int edg_wll_NotificationToHTML(edg_wll_Context ctx, notifInfo *ni, char **message); char *edg_wll_ErrorToHTML(edg_wll_Context,int); int edg_wll_FileTransferStatusToHTML(edg_wll_Context ctx, edg_wll_JobStat stat, char **message); -int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message); +int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message, int text); #endif /* GLITE_LB_HTML_H */ diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c index e00ef67..9ed3fd5 100644 --- a/org.glite.lb.server/src/lb_proto.c +++ b/org.glite.lb.server/src/lb_proto.c @@ -925,13 +925,19 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, } else if (extra_opt == HTTP_EXTRA_OPTION_CONFIGURATION) { // also browser-readable HTML version here? isadm = ctx->noAuth || edg_wll_amIroot(ctx->peerName, ctx->fqans,&ctx->authz_policy); - edg_wll_ConfigurationToText(ctx, isadm, &message); edg_wll_ServerStatisticsIncrement(ctx, SERVER_STATS_TEXT_VIEWS); /* GET /?stats*/ } else if (extra_opt == HTTP_EXTRA_OPTION_STATS) { - edg_wll_StatisticsToHTML(ctx, &message); - edg_wll_ServerStatisticsIncrement(ctx, SERVER_STATS_HTML_VIEWS); + isadm = ctx->noAuth || edg_wll_amIroot(ctx->peerName, ctx->fqans,&ctx->authz_policy); + if ( !isadm && ctx->count_server_stats == 2 ) { + ret = HTTP_UNAUTH; + edg_wll_SetError(ctx, EPERM, "Only superusers can view server usage statistics on this particular server."); + } + else { + edg_wll_StatisticsToHTML(ctx, &message, text); + edg_wll_ServerStatisticsIncrement(ctx, SERVER_STATS_HTML_VIEWS); + } /* GET [something else]: not understood */ } else ret = HTTP_BADREQ; free(requestPTR); requestPTR = NULL; diff --git a/org.glite.lb.server/src/server_stats.h b/org.glite.lb.server/src/server_stats.h index d05c4f6..152e0d3 100644 --- a/org.glite.lb.server/src/server_stats.h +++ b/org.glite.lb.server/src/server_stats.h @@ -13,8 +13,6 @@ typedef struct _edg_wll_server_statistics{ time_t start; } edg_wll_server_statistics; -#define SERVER_STATISTICS_COUNT 15 - enum edg_wll_server_statistics_type{ SERVER_STATS_GLITEJOB_REGS = 0, SERVER_STATS_PBSJOB_REGS, @@ -30,8 +28,44 @@ enum edg_wll_server_statistics_type{ SERVER_STATS_NOTIF_LEGACY_SENT, SERVER_STATS_NOTIF_MSG_SENT, SERVER_STATS_WS_QUERIES, - SERVER_STATS_LBPROTO + SERVER_STATS_LBPROTO, + SERVER_STATISTICS_COUNT }; +// Add new values in front of LAST and do not change order + +static const char *edg_wll_server_statistics_type_title[] = { + "gLite job regs", + "PBS job regs", + "Condor job regs", + "CREAM job regs", + "Sandbox regs", + "Job events", + "HTML accesses", + "Plain text accesses", + "RSS accesses", + "Notification regs (legacy interface)", + "Notification regs (msg interface)", + "Notifications sent (legacy)", + "Notifications sent (msg)", + "WS queries", + "L&B protocol accesses" }; + +static const char *edg_wll_server_statistics_type_key[] = { + "glite_jobs", + "pbs_jobs", + "condor_jobs", + "cream_jobs", + "sb_ft_jobs", + "events", + "queries_html", + "queries_text", + "queries_rss", + "notif_regs_legacy", + "notif_regs_msg", + "notifs_legacy", + "notis_msg", + "queries_ws", + "queries_api" }; int edg_wll_InitServerStatistics(edg_wll_Context ctx, char *prefix); -- 1.8.2.3