accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject svn commit: r1461315 - /accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/DefaultServlet.java
Date Tue, 26 Mar 2013 21:07:57 GMT
Author: ctubbsii
Date: Tue Mar 26 21:07:56 2013
New Revision: 1461315

URL: http://svn.apache.org/r1461315
Log:
ACCUMULO-597 Made graphs on monitor page respect, and show the local timezone. Can be overridden
by setting the TZ environment variable in conf/accumulo-env.sh

Modified:
    accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/DefaultServlet.java

Modified: accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/DefaultServlet.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/DefaultServlet.java?rev=1461315&r1=1461314&r2=1461315&view=diff
==============================================================================
--- accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/DefaultServlet.java
(original)
+++ accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/DefaultServlet.java
Tue Mar 26 21:07:56 2013
@@ -29,7 +29,10 @@ import java.security.PrivilegedAction;
 import java.security.ProtectionDomain;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.List;
+import java.util.TimeZone;
 
 import javax.servlet.ServletException;
 import javax.servlet.ServletOutputStream;
@@ -192,7 +195,7 @@ public class DefaultServlet extends Basi
         
         sb.append(sep);
         sep = ",";
-        sb.append("[" + point.getFirst() + "," + y + "]");
+        sb.append("[" + utc2local(point.getFirst()) + "," + y + "]");
       }
       sb.append("    ];\n");
     }
@@ -217,11 +220,28 @@ public class DefaultServlet extends Basi
       sb.append("data: d" + i + ", " + opts + ", color:\"" + colors[i] + "\" }");
     }
     sb.append("], ");
-    sb.append("{yaxis:{}, xaxis:{mode:\"time\",minTickSize: [1, \"minute\"],timeformat: \"%H:%M\",
ticks:3}});");
+    sb.append("{yaxis:{}, xaxis:{mode:\"time\",minTickSize: [1, \"minute\"],timeformat: \"%H:%M<br
/>" + getShortTZName() + "\", ticks:3}});");
     sb.append("   });\n");
     sb.append("</script>\n");
   }
   
+  /**
+   * Shows the current time zone (based on the current time) short name
+   */
+  private static String getShortTZName() {
+    TimeZone tz = TimeZone.getDefault();
+    return tz.getDisplayName(tz.inDaylightTime(new Date()), TimeZone.SHORT);
+  }
+  
+  /**
+   * Converts a unix timestamp in UTC to one that is relative to the local timezone
+   */
+  private static Long utc2local(Long utcMillis) {
+    Calendar currentCalendar = Calendar.getInstance(); // default timezone
+    currentCalendar.setTimeInMillis(utcMillis + currentCalendar.getTimeZone().getOffset(utcMillis));
+    return currentCalendar.getTime().getTime();
+  }
+  
   @Override
   protected void pageBody(HttpServletRequest req, HttpServletResponse resp, StringBuilder
sb) throws IOException {
     if (req.getRequestURI().equals("/docs") || req.getRequestURI().equals("/docs/apidocs"))
{



Mime
View raw message