Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
CHUKWA-84. Enhance the ability to select time per widget. (Terence Kw…
…an via Eric Yang)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/chukwa/trunk@774159 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
macroadster committed May 13, 2009
1 parent b0d21c1 commit 5e6f09fc0a9a87310cd6e42e8fdd72785319be68
Show file tree
Hide file tree
Showing 29 changed files with 315 additions and 255 deletions.
@@ -675,6 +675,7 @@
<copy todir="${build.dir}/hicc/WEB-INF/lib">
<fileset dir="${basedir}/lib">
<include name="json.jar" />
<include name="jchronic-0.2.3.jar" />
<include name="html-filter-1.0.jar" />
</fileset>
<fileset dir="${common.ivy.lib.dir}">
Binary file not shown.
@@ -23,9 +23,19 @@

import org.apache.hadoop.chukwa.util.XssFilter;

import java.util.Date;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.StringTokenizer;
import java.text.SimpleDateFormat;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.mdimension.jchronic.Chronic;
import com.mdimension.jchronic.Options;
import com.mdimension.jchronic.tags.Pointer;
import com.mdimension.jchronic.utils.Span;
import com.mdimension.jchronic.utils.Time;


public class TimeHandler {
private HttpSession session = null;
@@ -42,6 +52,7 @@ public class TimeHandler {
private String startS = null;
private String endS = null;
private XssFilter xf = null;
private static Log log=LogFactory.getLog(TimeHandler.class);

public TimeHandler(HttpServletRequest request) {
this.tz = TimeZone.getTimeZone("UTC");
@@ -57,6 +68,43 @@ public TimeHandler(HttpServletRequest request, String tz) {
init(request);
}

/*
* Using the Chronic library to parse the english string
* and convert it to a long (millis seconds since 1970)
*/
public long parseDateShorthand(String d) {
Calendar now = Calendar.getInstance();
long l=now.getTimeInMillis();
d=d.trim();
if (d.compareToIgnoreCase("now")==0) {
// do nothing because it is default to now.
} else {
Options options= new Options(false);
options.setCompatibilityMode(true);
options.setNow(now);
try {
Span span = Chronic.parse(d, options);
l = span.getBegin()*1000;
} catch (Exception e) {
// exception when parsing
log.error("parse error for: "+d);
}
}

/*
* debug
*/
/*
SimpleDateFormat sf =
new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date ld=new Date(l);
log.error("Convert:"+d+" to "+Long.toString(l)+" - "+sf.format(ld)+ "-"+ld.getTime());
*/

return l;
}

public void init(HttpServletRequest request) {
xf = new XssFilter(request);
Calendar now = Calendar.getInstance();
@@ -95,6 +143,27 @@ public void init(HttpServletRequest request) {
start = end - (7 * 24 * 60 * 60 * 1000);
} else if (period.equals("last30d")) {
start = end - (30 * 24 * 60 * 60 * 1000);
} else if (period.startsWith("custom;")) {

// default value is between 2 days ago and now
String startString="2 days ago";
String endString="now";

// tokenize the value to "custom;2 days ago;now"
StringTokenizer st=new StringTokenizer(period,";");
if (st.hasMoreTokens()) {
st.nextToken(); // skip the first token
if (st.hasMoreTokens()) {
startString=st.nextToken();
if (st.hasMoreTokens()) {
endString=st.nextToken();
}
}
}

// parse the parameter strings
start = parseDateShorthand(startString);
end = parseDateShorthand(endString);
}
} else if (request.getParameter("start") != null
&& request.getParameter("end") != null) {
@@ -9,18 +9,7 @@
"refresh":"15",
"parameters":[
{"name":"table","type":"string","value":"ClientTrace","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"local_hdfs_read","label":"Metric","options":[
{"label":"Local HDFS Read","value":"local_hdfs_read"},
{"label":"Intra-rack HDFS Read","value":"intra_rack_hdfs_read"},
@@ -10,18 +10,7 @@
"parameters":[
{"name":"table","type":"string","value":"cluster_disk","edit":"0"},
{"name":"group_override","type":"string","value":"mount","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"available","label":"Metric","options":[
{"label":"used","value":"used"},
{"label":"available","value":"available"}
@@ -13,18 +13,7 @@
{"name":"y_axis_max","type":"string","value":"100","edit":"0"},
{"name":"display_percentage","type":"string","value":"1","edit":"0"},
{"name":"metric","type":"string","value":"used_percent","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"width","type":"select","value":"300","label":"Width","options":[
{"label":"300","value":"300"},
{"label":"400","value":"400"},
@@ -9,18 +9,7 @@
"refresh":"15",
"parameters":[
{"name":"table","type":"string","value":"cluster_system_metrics","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"load_15","label":"Metric","options":[
{"label":"Reporting Hosts","value":"host"},
{"label":"load_15","value":"load_15"},
@@ -11,18 +11,7 @@
{"name":"y_axis_max","type":"string","value":"100","edit":"0"},
{"name":"display_percentage","type":"string","value":"1","edit":"0"},
{"name":"table","type":"string","value":"cluster_system_metrics","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"load_15","label":"Metric","options":[
{"label":"cpu_idle_pcnt","value":"cpu_idle_pcnt"},
{"label":"cpu_nice_pcnt","value":"cpu_nice_pcnt"},
@@ -13,18 +13,7 @@
{"name":"find_slope","type":"string","value":"true","edit":"0"},
{"name":"group_items","type":"string","value":"hosts","edit":"0"},
{"name":"group","type":"string","value":"host","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"bytes_read","label":"Metric","options":[
{"label":"block_reports_num_ops","value":"block_reports_num_ops"},
{"label":"block_verification_failures","value":"block_verification_failures"},
@@ -12,18 +12,7 @@
{"name":"normalize_time","type":"string","value":"true","edit":"0"},
{"name":"group_items","type":"string","value":"hosts","edit":"0"},
{"name":"group","type":"string","value":"host","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"heart_beats_avg_time","label":"Metric","options":[
{"label":"block_reports_avg_time","value":"block_reports_avg_time"},
{"label":"copy_block_op_avg_time","value":"copy_block_op_avg_time"},
@@ -9,18 +9,7 @@
"refresh":"15",
"parameters":[
{"name":"table","type":"string","value":"dfs_fsnamesystem","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"capacity_remaining_gb","label":"Metric","options":[
{"label":"blocks_total","value":"blocks_total"},
{"label":"capacity_remaining_gb","value":"capacity_remaining_gb"},
@@ -12,18 +12,7 @@
{"name":"table","type":"string","value":"dfs_namenode","edit":"0"},
{"name":"group_override","type":"string","value":"host","edit":"0"},
{"name":"group","type":"string","value":"host","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"files_created","label":"Metric","options":[
{"label":"add_block_ops","value":"add_block_ops"},
{"label":"create_file_ops","value":"create_file_ops"},
@@ -11,18 +11,7 @@
{"name":"group_override","type":"string","value":"host","edit":"0"},
{"name":"group","type":"string","value":"host","edit":"0"},
{"name":"table","type":"string","value":"dfs_namenode","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"block_report_avg_time","label":"Metric","options":[
{"label":"blocks_corrupted","value":"blocks_corrupted"},
{"label":"safe_mode_time","value":"safe_mode_time"},
@@ -9,18 +9,7 @@
"refresh":"15",
"parameters":[
{"name":"table","type":"string","value":"dfs_throughput","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"heart_beats_avg_time","label":"Metric","options":[
{"label":"hosts","value":"hosts"},
{"label":"block_reports_num_ops","value":"block_reports_num_ops"},
@@ -12,18 +12,7 @@
{"name":"group_override","type":"string","value":"concat(host,mount) as mount","edit":"0"},
{"name":"group","type":"string","value":"host","edit":"0"},
{"name":"group_items","type":"string","value":"hosts","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select_multiple","value":"available","label":"Metric","options":[
{"label":"used","value":"used"},
{"label":"available","value":"available"}
@@ -15,18 +15,7 @@
{"name":"metric","type":"string","value":"used_percent","edit":"0"},
{"name":"group","type":"string","value":"host","edit":"0"},
{"name":"group_items","type":"string","value":"hosts","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"width","type":"select","value":"300","label":"Width","options":[
{"label":"300","value":"300"},
{"label":"400","value":"400"},
@@ -13,18 +13,7 @@
{"name":"group_override","type":"string","value":"concat(host,' ',process_name) as process","edit":"0"},
{"name":"group","type":"string","value":"host","edit":"0"},
{"name":"group_items","type":"string","value":"hosts","edit":"0"},
{"name":"period","type":"select","value":"","label":"Period","options":[
{"label":"Use Time Widget","value":""},
{"label":"Last 1 Hour","value":"last1hr"},
{"label":"Last 2 Hours","value":"last2hr"},
{"label":"Last 3 Hours","value":"last3hr"},
{"label":"Last 6 Hours","value":"last6hr"},
{"label":"Last 12 Hours","value":"last12hr"},
{"label":"Last 24 Hours","value":"last24hr"},
{"label":"Yesterday","value":"yesterday"},
{"label":"Last 7 Days","value":"last7d"},
{"label":"Last 30 Days","value":"last30d"}
]},
{"name":"period","type":"custom","control":"period_control","value":"","label":"Period"},
{"name":"metric","type":"select","value":"gc_timemillis","label":"Metric","options":[
{"label":"gc_timemillis","value":"gc_timemillis"},
{"label":"gc_count","value":"gc_count"},

0 comments on commit 5e6f09f

Please sign in to comment.