1616// under the License.
1717package com .cloud .hypervisor .xen .resource ;
1818
19- import java .io .BufferedReader ;
20- import java .io .File ;
21- import java .io .FileInputStream ;
22- import java .io .IOException ;
23- import java .io .InputStream ;
24- import java .io .InputStreamReader ;
25- import java .io .StringReader ;
26- import java .net .URI ;
27- import java .net .URISyntaxException ;
28- import java .net .URL ;
29- import java .net .URLConnection ;
30- import java .util .ArrayList ;
31- import java .util .Date ;
32- import java .util .HashMap ;
33- import java .util .HashSet ;
34- import java .util .Iterator ;
35- import java .util .LinkedList ;
36- import java .util .List ;
37- import java .util .Map ;
38- import java .util .Properties ;
39- import java .util .Queue ;
40- import java .util .Random ;
41- import java .util .Set ;
42- import java .util .UUID ;
43-
44- import javax .ejb .Local ;
45- import javax .naming .ConfigurationException ;
46- import javax .xml .parsers .DocumentBuilderFactory ;
47-
48- import org .apache .cloudstack .storage .command .StorageSubSystemCommand ;
49- import org .apache .cloudstack .storage .to .TemplateObjectTO ;
50- import org .apache .cloudstack .storage .to .VolumeObjectTO ;
51- import org .apache .commons .codec .binary .Base64 ;
52- import org .apache .log4j .Logger ;
53- import org .apache .xmlrpc .XmlRpcException ;
54- import org .w3c .dom .Document ;
55- import org .w3c .dom .Node ;
56- import org .w3c .dom .NodeList ;
57- import org .xml .sax .InputSource ;
58-
5919import com .cloud .agent .IAgentControl ;
6020import com .cloud .agent .api .Answer ;
6121import com .cloud .agent .api .AttachIsoCommand ;
273233import com .xensource .xenapi .Types .VmPowerState ;
274234import com .xensource .xenapi .Types .XenAPIException ;
275235import com .xensource .xenapi .VBD ;
276- import com .xensource .xenapi .VBDMetrics ;
277236import com .xensource .xenapi .VDI ;
278237import com .xensource .xenapi .VIF ;
279238import com .xensource .xenapi .VLAN ;
280239import com .xensource .xenapi .VM ;
281240import com .xensource .xenapi .VMGuestMetrics ;
282241import com .xensource .xenapi .XenAPIObject ;
242+ import org .apache .cloudstack .storage .command .StorageSubSystemCommand ;
243+ import org .apache .cloudstack .storage .to .TemplateObjectTO ;
244+ import org .apache .cloudstack .storage .to .VolumeObjectTO ;
245+ import org .apache .commons .codec .binary .Base64 ;
246+ import org .apache .log4j .Logger ;
247+ import org .apache .xmlrpc .XmlRpcException ;
248+ import org .w3c .dom .Document ;
249+ import org .w3c .dom .Node ;
250+ import org .w3c .dom .NodeList ;
251+ import org .xml .sax .InputSource ;
252+
253+ import javax .ejb .Local ;
254+ import javax .naming .ConfigurationException ;
255+ import javax .xml .parsers .DocumentBuilderFactory ;
256+ import java .io .BufferedReader ;
257+ import java .io .File ;
258+ import java .io .FileInputStream ;
259+ import java .io .IOException ;
260+ import java .io .InputStream ;
261+ import java .io .InputStreamReader ;
262+ import java .io .StringReader ;
263+ import java .net .URI ;
264+ import java .net .URISyntaxException ;
265+ import java .net .URL ;
266+ import java .net .URLConnection ;
267+ import java .util .ArrayList ;
268+ import java .util .Date ;
269+ import java .util .HashMap ;
270+ import java .util .HashSet ;
271+ import java .util .Iterator ;
272+ import java .util .LinkedList ;
273+ import java .util .List ;
274+ import java .util .Map ;
275+ import java .util .Properties ;
276+ import java .util .Queue ;
277+ import java .util .Random ;
278+ import java .util .Set ;
279+ import java .util .UUID ;
283280
284281/**
285282 * CitrixResourceBase encapsulates the calls to the XenServer Xapi process
@@ -2703,23 +2700,15 @@ protected HostStatsEntry getHostStats(Connection conn, GetHostStatsCommand cmd,
27032700
27042701 if (type .equalsIgnoreCase ("host" )) {
27052702
2706- if (param .contains ("pif_eth0_rx" )) {
2707- hostStats .setNetworkReadKBs (getDataAverage (dataNode , col , numRows ));
2708- }
2709-
2710- if (param .contains ("pif_eth0_tx" )) {
2711- hostStats .setNetworkWriteKBs (getDataAverage (dataNode , col , numRows ));
2712- }
2713-
2714- if (param .contains ("memory_total_kib" )) {
2703+ if (param .matches ("pif_eth0_rx" )) {
2704+ hostStats .setNetworkReadKBs (getDataAverage (dataNode , col , numRows )/1000 );
2705+ } else if (param .matches ("pif_eth0_tx" )) {
2706+ hostStats .setNetworkWriteKBs (getDataAverage (dataNode , col , numRows )/1000 );
2707+ } else if (param .contains ("memory_total_kib" )) {
27152708 hostStats .setTotalMemoryKBs (getDataAverage (dataNode , col , numRows ));
2716- }
2717-
2718- if (param .contains ("memory_free_kib" )) {
2709+ } else if (param .contains ("memory_free_kib" )) {
27192710 hostStats .setFreeMemoryKBs (getDataAverage (dataNode , col , numRows ));
2720- }
2721-
2722- if (param .contains ("cpu" )) {
2711+ } else if (param .matches ("cpu_avg" )) {
27232712 // hostStats.setNumCpus(hostStats.getNumCpus() + 1);
27242713 hostStats .setCpuUtilization (hostStats .getCpuUtilization () + getDataAverage (dataNode , col , numRows ));
27252714 }
@@ -2830,13 +2819,16 @@ protected HashMap<String, VmStatsEntry> getVmStats(Connection conn, GetVmStatsCo
28302819 if (param .contains ("cpu" )) {
28312820 vmStatsAnswer .setNumCPUs (vmStatsAnswer .getNumCPUs () + 1 );
28322821 vmStatsAnswer .setCPUUtilization (((vmStatsAnswer .getCPUUtilization () + getDataAverage (dataNode , col , numRows ))));
2833- } else if (param .matches ("vif_\\ d_rx" )) {
2834- vmStatsAnswer .setNetworkReadKBs (vmStatsAnswer .getNetworkReadKBs () + (getDataAverage (dataNode , col , numRows )/(8 *2 )));
2835- } else if (param .matches ("vif_\\ d_tx" )) {
2836- vmStatsAnswer .setNetworkWriteKBs (vmStatsAnswer .getNetworkWriteKBs () + (getDataAverage (dataNode , col , numRows )/(8 *2 )));
2822+ } else if (param .matches ("vif_\\ d*_rx" )) {
2823+ vmStatsAnswer .setNetworkReadKBs (vmStatsAnswer .getNetworkReadKBs () + (getDataAverage (dataNode , col , numRows )/1000 ));
2824+ } else if (param .matches ("vif_\\ d*_tx" )) {
2825+ vmStatsAnswer .setNetworkWriteKBs (vmStatsAnswer .getNetworkWriteKBs () + (getDataAverage (dataNode , col , numRows )/1000 ));
2826+ } else if (param .matches ("vbd_.*_read" )) {
2827+ vmStatsAnswer .setDiskReadKBs (vmStatsAnswer .getDiskReadKBs () + (getDataAverage (dataNode , col , numRows )/1000 ));
2828+ } else if (param .matches ("vbd_.*_write" )) {
2829+ vmStatsAnswer .setDiskWriteKBs (vmStatsAnswer .getDiskWriteKBs () + (getDataAverage (dataNode , col , numRows )/1000 ));
28372830 }
28382831 }
2839-
28402832 }
28412833
28422834 for (String vmUUID : vmResponseMap .keySet ()) {
@@ -2851,30 +2843,6 @@ protected HashMap<String, VmStatsEntry> getVmStats(Connection conn, GetVmStatsCo
28512843 s_logger .debug ("Vm cpu utilization " + vmStatsAnswer .getCPUUtilization ());
28522844 }
28532845 }
2854-
2855- try {
2856- for (String vmUUID : vmUUIDs ) {
2857- VM vm = VM .getByUuid (conn , vmUUID );
2858- VmStatsEntry stats = vmResponseMap .get (vmUUID );
2859- double diskReadKBs = 0 ;
2860- double diskWriteKBs = 0 ;
2861- for (VBD vbd : vm .getVBDs (conn )) {
2862- VBDMetrics record = vbd .getMetrics (conn );
2863- diskReadKBs += record .getIoReadKbs (conn );
2864- diskWriteKBs += record .getIoWriteKbs (conn );
2865- }
2866- if (stats == null ) {
2867- stats = new VmStatsEntry ();
2868- }
2869- stats .setDiskReadKBs (diskReadKBs );
2870- stats .setDiskWriteKBs (diskWriteKBs );
2871- vmResponseMap .put (vmUUID , stats );
2872- }
2873- } catch (Exception e ) {
2874- s_logger .warn ("Error while collecting disk stats from : " , e );
2875- return null ;
2876- }
2877-
28782846 return vmResponseMap ;
28792847 }
28802848
0 commit comments