Skip to content

Commit b4d3aac

Browse files
author
Anthony Xu
committed
get rrd through http directly instead of xapi plugins
1 parent 15d798d commit b4d3aac

9 files changed

Lines changed: 51 additions & 123 deletions

File tree

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,19 @@
216216
import org.w3c.dom.Node;
217217
import org.w3c.dom.NodeList;
218218
import org.xml.sax.InputSource;
219+
import org.xml.sax.SAXException;
219220

220221
import javax.ejb.Local;
221222
import javax.naming.ConfigurationException;
222223
import javax.xml.parsers.DocumentBuilderFactory;
224+
import javax.xml.parsers.ParserConfigurationException;
223225
import java.io.BufferedReader;
224226
import java.io.File;
225227
import java.io.FileInputStream;
226228
import java.io.IOException;
227229
import java.io.InputStream;
228230
import java.io.InputStreamReader;
229-
import java.io.StringReader;
231+
import java.net.MalformedURLException;
230232
import java.net.URI;
231233
import java.net.URISyntaxException;
232234
import java.net.URL;
@@ -2529,46 +2531,65 @@ protected GetVmDiskStatsAnswer execute(GetVmDiskStatsCommand cmd) {
25292531
return new GetVmDiskStatsAnswer(cmd, null, null, null);
25302532
}
25312533

2532-
protected Object[] getRRDData(Connection conn, int flag) {
2533-
2534-
/*
2535-
* Note: 1 => called from host, hence host stats 2 => called from vm, hence vm stats
2536-
*/
2537-
String stats = "";
25382534

2535+
protected Document getStatsRawXML(Connection conn, boolean host) {
2536+
Date currentDate = new Date();
2537+
String urlStr = "http://" + _host.ip + "/rrd_updates?";
2538+
urlStr += "session_id=" + conn.getSessionReference();
2539+
urlStr += "&host=" + (host ? "true" : "false");
2540+
urlStr += "&cf=" + _consolidationFunction;
2541+
urlStr += "&interval=" + _pollingIntervalInSeconds;
2542+
urlStr += "&start=" + (currentDate.getTime() / 1000 - 1000 - 100);
2543+
2544+
URL url;
2545+
BufferedReader in = null;
25392546
try {
2540-
if (flag == 1) {
2541-
stats = getHostStatsRawXML(conn);
2542-
}
2543-
if (flag == 2) {
2544-
stats = getVmStatsRawXML(conn);
2545-
}
2546-
} catch (Exception e1) {
2547-
s_logger.warn("Error whilst collecting raw stats from plugin: ", e1);
2547+
url = new URL(urlStr);
2548+
url.openConnection();
2549+
URLConnection uc = url.openConnection();
2550+
in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
2551+
InputSource statsSource = new InputSource(in);
2552+
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(statsSource);
2553+
} catch (MalformedURLException e) {
2554+
s_logger.warn("Malformed URL? come on...." + urlStr);
2555+
return null;
2556+
} catch (IOException e) {
2557+
s_logger.warn("Problems getting stats using " + urlStr, e);
2558+
return null;
2559+
} catch (SAXException e) {
2560+
s_logger.warn("Problems getting stats using " + urlStr, e);
25482561
return null;
2562+
} catch (ParserConfigurationException e) {
2563+
s_logger.warn("Problems getting stats using " + urlStr, e);
2564+
return null;
2565+
} finally {
2566+
if (in != null) {
2567+
try {
2568+
in.close();
2569+
} catch (IOException e) {
2570+
s_logger.warn("Unable to close the buffer ", e);
2571+
}
2572+
}
25492573
}
2574+
}
25502575

2551-
// s_logger.debug("The raw xml stream is:"+stats);
2552-
// s_logger.debug("Length of raw xml is:"+stats.length());
25532576

2554-
//stats are null when the host plugin call fails (host down state)
2555-
if (stats == null) {
2556-
return null;
2557-
}
25582577

2559-
StringReader statsReader = new StringReader(stats);
2560-
InputSource statsSource = new InputSource(statsReader);
2578+
protected Object[] getRRDData(Connection conn, int flag) {
25612579

2580+
/*
2581+
* Note: 1 => called from host, hence host stats 2 => called from vm, hence vm stats
2582+
*/
25622583
Document doc = null;
2584+
25632585
try {
2564-
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(statsSource);
2565-
} catch (Exception e) {
2566-
s_logger.warn("Exception caught whilst processing the document via document factory:", e);
2586+
doc = getStatsRawXML(conn, flag == 1 ? true : false);
2587+
} catch (Exception e1) {
2588+
s_logger.warn("Error whilst collecting raw stats from plugin: ", e1);
25672589
return null;
25682590
}
25692591

2570-
if (doc == null) {
2571-
s_logger.warn("Null document found after tryinh to parse the stats source");
2592+
if (doc == null) { //stats are null when the host plugin call fails (host down state)
25722593
return null;
25732594
}
25742595

@@ -2592,7 +2613,7 @@ protected Object[] getRRDData(Connection conn, int flag) {
25922613
}
25932614
}
25942615

2595-
return new Object[] {numRows, numColumns, legend, dataNode};
2616+
return new Object[] { numRows, numColumns, legend, dataNode };
25962617
}
25972618

25982619
protected String getXMLNodeValue(Node n) {
@@ -2630,22 +2651,6 @@ protected double getDataAverage(Node dataNode, int col, int numRows) {
26302651

26312652
}
26322653

2633-
protected String getHostStatsRawXML(Connection conn) {
2634-
Date currentDate = new Date();
2635-
String startTime = String.valueOf(currentDate.getTime() / 1000 - 1000);
2636-
2637-
return callHostPlugin(conn, "vmops", "gethostvmstats", "collectHostStats", String.valueOf("true"), "consolidationFunction", _consolidationFunction, "interval",
2638-
String.valueOf(_pollingIntervalInSeconds), "startTime", startTime);
2639-
}
2640-
2641-
protected String getVmStatsRawXML(Connection conn) {
2642-
Date currentDate = new Date();
2643-
String startTime = String.valueOf(currentDate.getTime() / 1000 - 1000);
2644-
2645-
return callHostPlugin(conn, "vmops", "gethostvmstats", "collectHostStats", String.valueOf("false"), "consolidationFunction", _consolidationFunction, "interval",
2646-
String.valueOf(_pollingIntervalInSeconds), "startTime", startTime);
2647-
}
2648-
26492654
protected State convertToState(Types.VmPowerState ps) {
26502655
final State state = s_statesTable.get(ps);
26512656
return state == null ? State.Unknown : state;

‎scripts/vm/hypervisor/xenserver/hostvmstats.py‎

Lines changed: 0 additions & 61 deletions
This file was deleted.

‎scripts/vm/hypervisor/xenserver/vmops‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ if os.path.exists("/opt/xensource/sm"):
2727
if os.path.exists("/usr/lib/xcp/sm"):
2828
sys.path.extend(["/usr/lib/xcp/sm/", "/usr/local/sbin/", "/sbin/"])
2929
import base64
30-
import hostvmstats
3130
import socket
3231
import stat
3332
import tempfile
@@ -61,15 +60,6 @@ def add_to_VCPUs_params_live(session, args):
6160
return 'false'
6261
return 'true'
6362

64-
@echo
65-
def gethostvmstats(session, args):
66-
collect_host_stats = args['collectHostStats']
67-
consolidation_function = args['consolidationFunction']
68-
interval = args['interval']
69-
start_time = args['startTime']
70-
result = hostvmstats.get_stats(session, collect_host_stats, consolidation_function, interval, start_time)
71-
return result
72-
7363
@echo
7464
def setup_iscsi(session, args):
7565
uuid=args['uuid']
@@ -1502,7 +1492,7 @@ def network_rules(session, args):
15021492
logging.debug("Failed to network rule !")
15031493

15041494
if __name__ == "__main__":
1505-
XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi, "gethostvmstats": gethostvmstats,
1495+
XenAPIPlugin.dispatch({"pingtest": pingtest, "setup_iscsi":setup_iscsi,
15061496
"getgateway": getgateway, "preparemigration": preparemigration,
15071497
"setIptables": setIptables, "pingdomr": pingdomr, "pingxenserver": pingxenserver,
15081498
"routerProxy": routerProxy,

‎scripts/vm/hypervisor/xenserver/xcposs/patch‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ vmops=..,0755,/usr/lib/xcp/plugins
3131
ovsgre=..,0755,/usr/lib/xcp/plugins
3232
ovstunnel=..,0755,/usr/lib/xcp/plugins
3333
vmopsSnapshot=..,0755,/usr/lib/xcp/plugins
34-
hostvmstats.py=..,0755,/usr/lib/xcp/sm
3534
systemvm.iso=../../../../../vms,0644,/usr/share/xcp/packages/iso/
3635
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
3736
network_info.sh=..,0755,/opt/cloud/bin

‎scripts/vm/hypervisor/xenserver/xcpserver/patch‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ NFSSR.py=/opt/xensource/sm
3131
vmops=..,0755,/etc/xapi.d/plugins
3232
ovstunnel=..,0755,/etc/xapi.d/plugins
3333
vmopsSnapshot=..,0755,/etc/xapi.d/plugins
34-
hostvmstats.py=..,0755,/opt/xensource/sm
3534
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
3635
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
3736
network_info.sh=..,0755,/opt/cloud/bin

‎scripts/vm/hypervisor/xenserver/xenserver56/patch‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ NFSSR.py=/opt/xensource/sm
3030
vmops=..,0755,/etc/xapi.d/plugins
3131
vmopsSnapshot=..,0755,/etc/xapi.d/plugins
3232
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
33-
hostvmstats.py=..,0755,/opt/xensource/sm
3433
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
3534
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
3635
network_info.sh=..,0755,/opt/cloud/bin

‎scripts/vm/hypervisor/xenserver/xenserver56fp1/patch‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ NFSSR.py=/opt/xensource/sm
3030
vmops=..,0755,/etc/xapi.d/plugins
3131
vmopsSnapshot=..,0755,/etc/xapi.d/plugins
3232
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
33-
hostvmstats.py=..,0755,/opt/xensource/sm
3433
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
3534
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
3635
network_info.sh=..,0755,/opt/cloud/bin

‎scripts/vm/hypervisor/xenserver/xenserver60/patch‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ cloudstack_plugins.conf=..,0644,/etc/xensource
3434
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
3535
ovstunnel=..,0755,/etc/xapi.d/plugins
3636
vmopsSnapshot=..,0755,/etc/xapi.d/plugins
37-
hostvmstats.py=..,0755,/opt/xensource/sm
3837
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
3938
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
4039
network_info.sh=..,0755,/opt/cloud/bin

‎scripts/vm/hypervisor/xenserver/xenserver62/patch‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ cloudstack_plugins.conf=..,0644,/etc/xensource
3434
cloudstack_pluginlib.py=..,0755,/etc/xapi.d/plugins
3535
ovstunnel=..,0755,/etc/xapi.d/plugins
3636
cloud-plugin-storage=,0755,/etc/xapi.d/plugins
37-
hostvmstats.py=..,0755,/opt/xensource/sm
3837
systemvm.iso=../../../../../vms,0644,/opt/xensource/packages/iso
3938
id_rsa.cloud=../../../systemvm,0600,/root/.ssh
4039
network_info.sh=..,0755,/opt/cloud/bin

0 commit comments

Comments
 (0)