- server stats file selection is more robust (use /tmp as a last choice)
authorJiří Filipovič <fila@ics.muni.cz>
Thu, 16 Feb 2012 14:00:55 +0000 (14:00 +0000)
committerJiří Filipovič <fila@ics.muni.cz>
Thu, 16 Feb 2012 14:00:55 +0000 (14:00 +0000)
- 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
org.glite.lb.server/src/server_stats.c
org.glite.lb.server/src/server_stats.h

index 9f90c25..31ade56 100644 (file)
@@ -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,
+                        "<b>WARNING: L&B statistics are stored in /tmp, please, configure L&B server to make them really persistent!</b><br/><br/>\n");
+                else
+                        asprintf(&head, "");
+
                 asprintf(&out,
                         "<h2>LB Server Usage Statistics</h2>\n"
+                       "%s"
                         "<table halign=\"left\">\n"
                         "<tr><td>Variable</td><td>Value</td><td>Measured from</td></tr>\n"
                         "<tr><td>gLite job regs</td><td>%i</td><td>%s</td></tr>\n"
@@ -548,6 +556,7 @@ int edg_wll_StatisticsToHTML(edg_wll_Context ctx, char **message) {
                         "<tr><td>Plain text accesses</td><td>%i</td><td>%s</td></tr>\n"
                         "<tr><td>RSS accesses</td><td>%i</td><td>%s</td></tr>\n"
                         "</table>\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;
index d194b6e..79fa7be 100644 (file)
 
 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;
+}
+
 
index e5276d6..b0a2359 100644 (file)
@@ -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 */