From 9027bf5afd824738991850bc935508d96ae2d910 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Filipovi=C4=8D?= Date: Thu, 16 Feb 2012 14:00:55 +0000 Subject: [PATCH] - server stats file selection is more robust (use /tmp as a last choice) - HTML interface warns when stats are in /tmp - statistics explicitly msync to disk (once per hundred modifications) --- org.glite.lb.server/src/lb_html.c | 10 +++++++++ org.glite.lb.server/src/server_stats.c | 41 ++++++++++++++++++++++++++++++---- org.glite.lb.server/src/server_stats.h | 1 + 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/org.glite.lb.server/src/lb_html.c b/org.glite.lb.server/src/lb_html.c index 9f90c25..31ade56 100644 --- a/org.glite.lb.server/src/lb_html.c +++ b/org.glite.lb.server/src/lb_html.c @@ -522,14 +522,22 @@ int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message) { { 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" "\n" "\n" "\n" @@ -548,6 +556,7 @@ int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message) { "\n" "\n" "
VariableValueMeasured from
gLite job regs%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), @@ -582,6 +591,7 @@ int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message) { for (i = 0; i < SERVER_STATISTICS_COUNT; i++) free(times[i]); + free(head); } *message = out; diff --git a/org.glite.lb.server/src/server_stats.c b/org.glite.lb.server/src/server_stats.c index d194b6e..79fa7be 100644 --- a/org.glite.lb.server/src/server_stats.c +++ b/org.glite.lb.server/src/server_stats.c @@ -13,21 +13,44 @@ static edg_wll_server_statistics *serverStatisticsMap = NULL; static int serverStatisticsFD; +static int stats_in_tmp = 0; +static int msync_counter = 0; int edg_wll_InitServerStatistics(edg_wll_Context ctx, char *file) { //TODO get file name from command line char *fname; + char *lblocenv = NULL; if (file) asprintf(&fname, "%s", file); else{ - asprintf(&fname, "/tmp/lb_server_stats"); - glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_INFO, - "server stats file not found, using default %s", fname); + + if (! (lblocenv = getenv("GLITE_LB_LOCATION_VAR"))) { + struct stat info; + if (stat("/var/glite", &info) == 0 && S_ISDIR(info.st_mode)) + asprintf(&fname, "/var/glite/lb_server_stats"); + else { + asprintf(&fname, "/tmp/lb_server_stats"); + stats_in_tmp = 1; + } + glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_INFO, + "server stats file not configured, using default %s", fname); + } + else + asprintf(&fname, "%s/lb_server_stats", lblocenv); } serverStatisticsFD = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); - if (serverStatisticsFD < 0) + if (serverStatisticsFD < 0){ + serverStatisticsFD = open("/tmp/lb_server_stats", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_WARN, + "Server statistics: cannot open %s, trying to use /tmp/lb_server_stats instead.", fname); + stats_in_tmp = 1; + } + if (serverStatisticsFD < 0) { + glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_WARN, "Cannot use server statistics!"); + free(fname); return edg_wll_SetError(ctx,errno,fname); + } off_t size = lseek(serverStatisticsFD, 0, SEEK_END) - lseek(serverStatisticsFD, 0, SEEK_SET); @@ -69,6 +92,8 @@ int edg_wll_InitServerStatistics(edg_wll_Context ctx, char *file) msync(serverStatisticsMap, SERVER_STATISTICS_COUNT*sizeof(*serverStatisticsMap), MS_ASYNC); + free(fname); + return 0; } @@ -88,6 +113,9 @@ int edg_wll_ServerStatisticsIncrement(edg_wll_Context ctx, enum edg_wll_server_s serverStatisticsMap[type].value++; flock(serverStatisticsFD, LOCK_UN); + if (++msync_counter % 100 == 0) + msync(serverStatisticsMap, SERVER_STATISTICS_COUNT*sizeof(*serverStatisticsMap), MS_ASYNC); + return 0; } @@ -123,4 +151,9 @@ time_t* edg_wll_ServerStatisticsGetStart(edg_wll_Context ctx, enum edg_wll_serve return &(serverStatisticsMap[type].start); } +int edg_wll_ServerStatisticsInTmp() +{ + return stats_in_tmp; +} + diff --git a/org.glite.lb.server/src/server_stats.h b/org.glite.lb.server/src/server_stats.h index e5276d6..b0a2359 100644 --- a/org.glite.lb.server/src/server_stats.h +++ b/org.glite.lb.server/src/server_stats.h @@ -38,5 +38,6 @@ int edg_wll_InitServerStatistics(edg_wll_Context ctx, char *file); int edg_wll_ServerStatisticsIncrement(edg_wll_Context ctx, enum edg_wll_server_statistics_type type); int edg_wll_ServerStatisticsGetValue(edg_wll_Context ctx, enum edg_wll_server_statistics_type type); time_t* edg_wll_ServerStatisticsGetStart(edg_wll_Context ctx, enum edg_wll_server_statistics_type type); +int edg_wll_ServerStatisticsInTmp(); #endif /* GLITE_LB_SERVER_STATS_H */ -- 1.8.2.3