You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ec...@apache.org on 2007/12/10 23:37:23 UTC
svn commit: r603080 - in
/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client:
GraphsBuilder.java StatsGraph.java
Author: ecraig
Date: Mon Dec 10 14:37:22 2007
New Revision: 603080
URL: http://svn.apache.org/viewvc?rev=603080&view=rev
Log:
GERONIMO-3693
monitoring client does not perform operations correctly
Patch by Viet Nguyen
Modified:
geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java
geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/StatsGraph.java
Modified: geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java?rev=603080&r1=603079&r2=603080&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java (original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/GraphsBuilder.java Mon Dec 10 14:37:22 2007
@@ -31,17 +31,15 @@
import org.apache.geronimo.plugins.monitoring.client.util.DBManager;
-public class GraphsBuilder
-{
- private String ip = new String();
- private int timeFrame;
- private int snapCount;
- private MRCConnector mrc = new MRCConnector();
+public class GraphsBuilder {
+ private String ip = new String();
+ private int timeFrame;
+ private int snapCount;
+ private MRCConnector mrc = new MRCConnector();
private Connection con;
// constructor
- public GraphsBuilder(Connection con)
- {
+ public GraphsBuilder(Connection con) {
// TODO: Database pull stuff may go here... based on server ID...\
this.con = con;
}
@@ -51,7 +49,9 @@
StatsGraph graph = null;
PreparedStatement pStmt = null;
ResultSet rsServer = null;
- pStmt = con.prepareStatement("SELECT * from graphs WHERE enabled=1 AND graph_id=" + graph_id);
+ pStmt = con
+ .prepareStatement("SELECT * from graphs WHERE enabled=1 AND graph_id="
+ + graph_id);
ResultSet rs = pStmt.executeQuery();
if (rs.next()) {
String mBeanName = rs.getString("mbean");
@@ -70,39 +70,44 @@
float warninglevel1 = rs.getFloat("warninglevel1");
String description = rs.getString("description");
boolean showArchive = rs.getInt("archive") == 1 ? true : false;
-
- pStmt = con.prepareStatement("SELECT * from servers WHERE enabled=1 AND server_id=" + server_id);
+
+ pStmt = con
+ .prepareStatement("SELECT * from servers WHERE enabled=1 AND server_id="
+ + server_id);
rsServer = pStmt.executeQuery();
if (rsServer.next()) {
ip = rsServer.getString("ip");
String username = rsServer.getString("username");
String password = rsServer.getString("password");
int port = rsServer.getInt("port");
- // close the connection before calling the MRCConnector because it opens another
- // connection to the db to update the SERVERS.last_seen attribute
+ // close the connection before calling the MRCConnector because
+ // it opens another
+ // connection to the db to update the SERVERS.last_seen
+ // attribute
try {
con.close();
- } catch(Exception e) {
+ } catch (Exception e) {
throw e;
}
mrc = new MRCConnector(ip, username, password, port);
snapCount = timeFrame
/ java.lang.Integer
- .valueOf(java.lang.Long.toString((mrc.getSnapshotDuration() / new Long(60000))));
+ .valueOf(java.lang.Long
+ .toString((mrc.getSnapshotDuration() / new Long(
+ 60000))));
HashMap<String, ArrayList<Object>> DataList = new HashMap<String, ArrayList<Object>>();
DataList.put(graphName1, new ArrayList<Object>());
- if (!dataName2.equals("time") && (dataName2 != null)
- && !dataName2.equals("null") && !dataName2.equals(""))
- {
+ if ((dataName2 != null) && !dataName2.equals("time")
+ && !dataName2.equals("null") && !dataName2.equals("")) {
DataList.put(graphName2, new ArrayList<Object>());
}
if ((timeFrame / 1440 >= 30))
snapCount = 17;
- else
- {
- if (((timeFrame / 1440) == 7) && ((timeFrame / 60) > 24) && snapCount >= 14) {
+ else {
+ if (((timeFrame / 1440) == 7) && ((timeFrame / 60) > 24)
+ && snapCount >= 14) {
snapCount = 16;
} else {
snapCount = 12; // default for anything else
@@ -116,93 +121,114 @@
String prettyTimeFrame = new String();
DecimalFormat fmt = new DecimalFormat("0.##");
if (timeFrame / 60 > 24) {
- prettyTimeFrame = fmt.format((float) (timeFrame / 1440)) + " day";
+ prettyTimeFrame = fmt.format((float) (timeFrame / 1440))
+ + " day";
} else {
if (timeFrame > 60) {
- prettyTimeFrame = fmt.format((float) timeFrame / 60) + " hour";
+ prettyTimeFrame = fmt.format((float) timeFrame / 60)
+ + " hour";
} else {
prettyTimeFrame = fmt.format(timeFrame) + " minute";
}
}
- int skipCount = (int) ((timeFrame / (mrc.getSnapshotDuration() / 60000))) / (snapCount - 2);
+ int skipCount = (int) ((timeFrame / (mrc.getSnapshotDuration() / 60000)))
+ / (snapCount - 2);
snapCount = snapCount + 2;
- TreeMap<Long, Long> snapshotList = mrc
- .getSpecificStatistics(mBeanName, dataName1, snapCount, skipCount, showArchive);
+ TreeMap<Long, Long> snapshotList1 = mrc
+ .getSpecificStatistics(mBeanName, dataName1, snapCount,
+ skipCount, showArchive);
+ TreeMap<Long, Long> snapshotList2 = mrc
+ .getSpecificStatistics(mBeanName, dataName2, snapCount,
+ skipCount, showArchive);
// Check if snapshotList is empty
- if (snapshotList.size() == 0) {
- snapshotList.put(System.currentTimeMillis(), new Long(0));
+ if (snapshotList1.size() == 0) {
+ snapshotList1.put(System.currentTimeMillis(), new Long(0));
+ snapshotList2.put(System.currentTimeMillis(), new Long(0));
/*
- * If there are not enough snapshots available to fill the requested
- * number, insert some with values of 0 and the proper times.
+ * If there are not enough snapshots available to fill the
+ * requested number, insert some with values of 0 and the
+ * proper times.
*/
- while (snapshotList.size() < snapCount) {
+ while (snapshotList1.size() < snapCount) {
// Temporary, always is first element (oldest)
- Long timeFix = snapshotList.firstKey();
+ Long timeFix = snapshotList1.firstKey();
// Calculate appropriate time, add it to the submap,
// then
// add
// that to the tempMap
- snapshotList.put((timeFix - (mrc.getSnapshotDuration() * skipCount)), new Long(0));
+ snapshotList1.put(
+ (timeFix - (mrc.getSnapshotDuration() * skipCount)), new Long(0));
+ snapshotList2.put(
+ (timeFix - (mrc.getSnapshotDuration() * skipCount)), new Long(0));
}
}
- for (Iterator<Long> it = snapshotList.keySet().iterator(); it.hasNext(); ) {
+ for (Iterator<Long> it = snapshotList1.keySet().iterator(); it.hasNext();) {
Long current = it.next();
snapshot_time.add(current);
ArrayList<Object> ArrayListTemp = DataList.get(graphName1);
- ArrayListTemp.add(snapshotList.get(current));
+ ArrayListTemp.add(snapshotList1.get(current));
DataList.put(graphName1, ArrayListTemp);
- if (!dataName2.equals("time") && (dataName2 != null)
- && !dataName2.equals("null") && !dataName2.equals("")) {
- ArrayList<Object> ArrayListTemp2 = DataList.get(graphName2);
- ArrayListTemp2.add(snapshotList.get(current));
+ if ((dataName2 != null) && !dataName2.equals("time")
+ && !dataName2.equals("null")
+ && !dataName2.equals("")) {
+ ArrayList<Object> ArrayListTemp2 = DataList
+ .get(graphName2);
+ ArrayListTemp2.add(snapshotList2.get(current));
DataList.put(graphName2, ArrayListTemp2);
}
PrettyTime.add((Long) current / 1000);
}
if (dataName2.equals("time")) {
- graph = (new StatsGraph(graph_id, ip + " - "
- + xlabel + " - " + prettyTimeFrame, description, "Time - " + prettyTimeFrame,
- ylabel, data1operation
- .charAt(0), DataList.get(graphName1), operation, data2operation.charAt(0), PrettyTime,
- snapshot_time, (int) (mrc.getSnapshotDuration() / 1000), timeFrame, color, warninglevel1, warninglevel1));
- } else if (!dataName2.equals("time") && (dataName2 != null)
- && !dataName2.equals("null") && !dataName2.equals("")) {
- graph = (new StatsGraph(graph_id, ip + " - "
- + xlabel + " - " + prettyTimeFrame, description, "Time - " + prettyTimeFrame,
- ylabel, data1operation.charAt(0), DataList.get(graphName1), operation,
- data2operation.charAt(0), DataList
- .get(graphName2), snapshot_time,
- (int) (mrc.getSnapshotDuration() / 1000),
- timeFrame, color, warninglevel1, warninglevel1));
- } else if (dataName2 == null || dataName2.equals("null") || dataName2.equals("")) {
- graph = (new StatsGraph(graph_id, ip + " - "
- + xlabel + " - " + prettyTimeFrame, description, "Time - " + prettyTimeFrame,
- ylabel, data1operation.charAt(0), DataList.get(graphName1), operation, snapshot_time,
+ graph = (new StatsGraph(graph_id, ip + " - " + xlabel
+ + " - " + prettyTimeFrame, description, "Time - "
+ + prettyTimeFrame, ylabel,
+ data1operation.charAt(0), DataList.get(graphName1),
+ operation, data2operation.charAt(0), PrettyTime,
+ snapshot_time,
(int) (mrc.getSnapshotDuration() / 1000),
timeFrame, color, warninglevel1, warninglevel1));
+ } else if (!dataName2.equals("time") && (dataName2 != null)
+ && !dataName2.equals("null") && !dataName2.equals("")) {
+ graph = (new StatsGraph(graph_id, ip + " - " + xlabel
+ + " - " + prettyTimeFrame, description, "Time - "
+ + prettyTimeFrame, ylabel,
+ data1operation.charAt(0), DataList.get(graphName1),
+ operation, data2operation.charAt(0), DataList
+ .get(graphName2), snapshot_time, (int) (mrc
+ .getSnapshotDuration() / 1000), timeFrame,
+ color, warninglevel1, warninglevel1));
+ } else if (dataName2 == null || dataName2.equals("null")
+ || dataName2.equals("")) {
+ graph = (new StatsGraph(graph_id, ip + " - " + xlabel
+ + " - " + prettyTimeFrame, description, "Time - "
+ + prettyTimeFrame, ylabel,
+ data1operation.charAt(0), DataList.get(graphName1),
+ operation, snapshot_time, (int) (mrc
+ .getSnapshotDuration() / 1000), timeFrame,
+ color, warninglevel1, warninglevel1));
} else {
graph = (new StatsGraph());
}
}
}
-
+
// check to see if graph was successfully populated
- if(graph != null) {
+ if (graph != null) {
// get the current date
Format formatter = null;
formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = new Date(System.currentTimeMillis());
String currentTime = formatter.format(date);
- // the graph was successfully operated on,
+ // the graph was successfully operated on,
// so update the last_seen attribute
DBManager dbManager = new DBManager();
Connection conn = dbManager.getConnection();
Statement stmt = conn.createStatement();
- stmt.executeUpdate(
- "UPDATE GRAPHS SET LAST_SEEN='" + currentTime + "' WHERE GRAPH_ID=" + graph_id);
+ stmt.executeUpdate("UPDATE GRAPHS SET LAST_SEEN='" + currentTime
+ + "' WHERE GRAPH_ID=" + graph_id);
conn.close();
}
return graph;
Modified: geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/StatsGraph.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/StatsGraph.java?rev=603080&r1=603079&r2=603080&view=diff
==============================================================================
--- geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/StatsGraph.java (original)
+++ geronimo/sandbox/monitoring/client/client-war/src/main/java/org/apache/geronimo/plugins/monitoring/client/StatsGraph.java Mon Dec 10 14:37:22 2007
@@ -21,8 +21,7 @@
import java.util.ArrayList;
import java.util.Date;
-public class StatsGraph
-{
+public class StatsGraph {
private String GraphName;
private String DivName;
private String Description;
@@ -30,19 +29,29 @@
private String DivImplement;
private String XAxisLabel;
private String YAxisLabel;
- private int SnapshotDuration;
- private int TimeFrame;
- private int PointCount;
+ private int SnapshotDuration;
+ private int TimeFrame;
+ private int PointCount;
private String HexColor;
private String GraphJS;
- public StatsGraph(Integer graph_id, String graphName, String description,
- String xAxisLabel, String yAxisLabel, char data1operation,
- ArrayList<Object> dataSet1, String operation, char data2operation,
- ArrayList<Object> dataSet2, ArrayList<Object> snapshotTimes,
- int snapshotDuration, int timeFrame, String hexColor,
- float warninglevel1, float warninglevel2)
- {
+ public StatsGraph(
+ Integer graph_id,
+ String graphName,
+ String description,
+ String xAxisLabel,
+ String yAxisLabel,
+ char data1operation,
+ ArrayList<Object> dataSet1,
+ String operation,
+ char data2operation,
+ ArrayList<Object> dataSet2,
+ ArrayList<Object> snapshotTimes,
+ int snapshotDuration,
+ int timeFrame,
+ String hexColor,
+ float warninglevel1,
+ float warninglevel2) {
DivName = "graph" + graph_id + "Container";
GraphName = graphName;
@@ -60,47 +69,53 @@
DivImplement = "<div id=\"" + DivName + "\"></div>" + "\n";
GraphJS = "var " + "graph" + graph_id + "Data = \n" + "[\n";
- if (data1operation == 'D' && data2operation == 'D')
- for (int i = 1; i < dataSet1.size(); i++)
- {
- if (((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1)) < 0)
+ if (data1operation == 'D' && data2operation == 'D') {
+ for (int i = 1; i < dataSet1.size(); i++) {
+ if (((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1)) < 0) {
dataSet1.set(i - 1, dataSet1.get(i));
- GraphJS = GraphJS + " { index: " + (i)
- + ", value: Math.round(("
- + ((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1))
- + operation
- + ((Long) dataSet2.get(i) - (Long) dataSet2.get(i - 1))
- + ")*10)/10 },\n";
+ GraphJS = GraphJS
+ + " { index: "
+ + (i)
+ + ", value: Math.round(("
+ + ((Long) dataSet1.get(i) - (Long) dataSet1
+ .get(i - 1));
+ // ensure there is not a division by 0
+ GraphJS += appendOperation(operation, (Long) dataSet2.get(i) - (Long) dataSet2.get(i - 1));
+ GraphJS += ")*10)/10 },\n";
+ }
}
+ }
if (data1operation == 'D' && data2operation != 'D')
- for (int i = 1; i < dataSet1.size(); i++)
- {
+ for (int i = 1; i < dataSet1.size(); i++) {
if (((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1)) < 0)
dataSet1.set(i - 1, dataSet1.get(i));
GraphJS = GraphJS + " { index: " + (i)
+ ", value: Math.round(("
- + ((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1))
- + operation + (dataSet2.get(i)) + ")*10)/10 },\n";
+ + ((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1));
+ // ensure there is not a division by 0
+ GraphJS += appendOperation(operation, (Long) dataSet2.get(i));
+ GraphJS += ")*10)/10 },\n";
}
if (data1operation != 'D' && data2operation == 'D')
- for (int i = 1; i < dataSet1.size(); i++)
- {
+ for (int i = 1; i < dataSet1.size(); i++) {
if (((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1)) < 0)
dataSet1.set(i - 1, dataSet1.get(i));
GraphJS = GraphJS + " { index: " + (i)
- + ", value: Math.round((" + (dataSet1.get(i))
- + operation
- + ((Long) dataSet2.get(i) - (Long) dataSet2.get(i - 1))
- + ")*10)/10 },\n";
+ + ", value: Math.round((" + (dataSet1.get(i));
+ // ensure there is not a division by 0
+ GraphJS += appendOperation(operation, (Long) dataSet2.get(i) - (Long) dataSet2.get(i - 1));
+ GraphJS += ")*10)/10 },\n";
}
if (data1operation != 'D' && data2operation != 'D')
- for (int i = 1; i < dataSet1.size(); i++)
- {
- if (((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1)) < 0)
+ for (int i = 1; i < dataSet1.size(); i++) {
+ if (((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1)) < 0) {
dataSet1.set(i - 1, dataSet1.get(i));
+ }
GraphJS = GraphJS + " { index: " + (i)
- + ", value: Math.round((" + (dataSet1.get(i))
- + operation + (dataSet2.get(i)) + ")*10)/10 },\n";
+ + ", value: Math.round((" + (dataSet1.get(i));
+ // ensure there is not a division by 0
+ GraphJS += appendOperation(operation, (Long) dataSet2.get(i));
+ GraphJS += ")*10)/10 },\n";
}
GraphJS = GraphJS + "];\n";
@@ -154,12 +169,10 @@
Format formatter = new SimpleDateFormat("HH:mm");
if ((timeFrame / 1440) > 7)
formatter = new SimpleDateFormat("M/d");
- else
- {
+ else {
if ((timeFrame / 60) > 24)
formatter = new SimpleDateFormat("E a");
- else
- {
+ else {
// if (timeFrame > 60)
// formatter = new SimpleDateFormat("HH:mm");
// else
@@ -167,8 +180,7 @@
}
}
- for (int i = 1; i < dataSet1.size(); i++)
- {
+ for (int i = 1; i < dataSet1.size(); i++) {
Date date = new Date((Long) snapshotTimes.get(i));
// System.out.println("StatsGraph Says: Time object "+i+" is
// "+snapshotTimes.get(i));
@@ -267,9 +279,9 @@
public StatsGraph(Integer graph_id, String graphName, String description,
String xAxisLabel, String yAxisLabel, char data1operation,
ArrayList<Object> dataSet1, String operation,
- ArrayList<Object> snapshotTimes, int snapshotDuration, int timeFrame,
- String hexColor, float warninglevel1, float warninglevel2)
- {
+ ArrayList<Object> snapshotTimes, int snapshotDuration,
+ int timeFrame, String hexColor, float warninglevel1,
+ float warninglevel2) {
DivName = "graph" + graph_id + "Container";
GraphName = graphName;
@@ -288,8 +300,7 @@
GraphJS = "var " + "graph" + graph_id + "Data = \n" + "[\n";
if (data1operation == 'D')
- for (int i = 1; i < dataSet1.size(); i++)
- {
+ for (int i = 1; i < dataSet1.size(); i++) {
if (((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1)) < 0)
dataSet1.set(i - 1, dataSet1.get(i));
GraphJS = GraphJS + " { index: " + (i)
@@ -298,8 +309,7 @@
+ operation + ")*10)/10 },\n";
}
if (data1operation != 'D')
- for (int i = 1; i < dataSet1.size(); i++)
- {
+ for (int i = 1; i < dataSet1.size(); i++) {
if (((Long) dataSet1.get(i) - (Long) dataSet1.get(i - 1)) < 0)
dataSet1.set(i - 1, dataSet1.get(i));
GraphJS = GraphJS + " { index: " + (i)
@@ -358,12 +368,10 @@
Format formatter = new SimpleDateFormat("HH:mm");
if ((timeFrame / 1440) > 7)
formatter = new SimpleDateFormat("M/d");
- else
- {
+ else {
if ((timeFrame / 60) > 24)
formatter = new SimpleDateFormat("E a");
- else
- {
+ else {
// if (timeFrame > 60)
// formatter = new SimpleDateFormat("HH:mm");
// else
@@ -371,8 +379,7 @@
}
}
- for (int i = 1; i < dataSet1.size(); i++)
- {
+ for (int i = 1; i < dataSet1.size(); i++) {
Date date = new Date((Long) snapshotTimes.get(i));
// System.out.println("StatsGraph Says: Time object "+i+" is
// "+snapshotTimes.get(i));
@@ -468,73 +475,70 @@
}
- public StatsGraph()
- {
+ private String appendOperation(String operation, Long number) {
+ String retval = "";
+ // ensure there is not a division by 0
+ if (operation.equals("/") && number == 0) {
+ retval += "*0";
+ } else {
+ retval += operation + number;
+ }
+ return retval;
+ }
+
+ public StatsGraph() {
}
- public void redraw()
- {
+ public void redraw() {
}
- public String getJS()
- {
+ public String getJS() {
return GraphJS;
}
- public String getDiv()
- {
+ public String getDiv() {
return DivDefine;
}
- public String getDivImplement()
- {
+ public String getDivImplement() {
return DivImplement;
}
- public String getDivName()
- {
+ public String getDivName() {
return DivName;
}
- public String getXAxis()
- {
+ public String getXAxis() {
return XAxisLabel;
}
- public String getYAxis()
- {
+ public String getYAxis() {
return YAxisLabel;
}
- public String getName()
- {
+ public String getName() {
return GraphName;
}
- public String getDescription()
- {
+ public String getDescription() {
return Description;
}
- public int getSnapshotDuration()
- {
+ public int getSnapshotDuration() {
return SnapshotDuration;
}
- public int getTimeFrame()
- {
+ public int getTimeFrame() {
return TimeFrame;
}
- public int getPointCount()
- {
+ public int getPointCount() {
return PointCount;
}
- public String getColor()
- {
+ public String getColor() {
return HexColor;
}
}