I have written some Java code through which I fetch metrics from Hyperic Server for some operations. I have not been able to fetch the value of these metrics.
for eq I have metric CPU Idle but when i use List<Data Point> dp= m1.getDataPoint()
where m1
is the metric data object of metric CPU Idle. In the output the size of list dp
is 0
.
I'm having this problem with all metrics except "availability". What should I do?
I have also checked the time interval in the graphical interface; it is showing the corresponding values.
the code is
// m_rrc is resource ( Process Server) on agent
for (int z = 0; z < m_rrrc.size(); z++) {
System.out.println(m_rrrc.get(z).getName())
MetricsResponse m_mr= m_a.getMetrics(m_rrrc.get(z));
// m_m is metric like CPU idle CPU utilization, System CPU
List<Metric> m_m = m_mr.getMetric();
for (int a = 0; a < m_m.size(); a++) {
MetricDataResponse m_mdr = m_m开发者_运维问答dapi.getData(m_m.get(a), 1309147200,1309147800);
MetricData m_md = m_mdr.getMetricData();
System.out.println(m_md.getMetricName());
List<DataPoint> m_dp = m_md.getDataPoint();
System.out.println(m_dp.size());
for (int b = 0; b < m_dp.size(); b++) {
System.out.println("abc");
System.out.println(m_dp.get(b).getValue());
System.out.println("i am Prannoy Mittal");
}
}
}
here size of data point list in output for all metrics is zero
Here is sample source code from Hyperic (http://svn.hyperic.org/projects/hqapi/trunk/src/org/hyperic/hq/hqapi1/test/MetricData_test.java), if you can put right 'assertEquals' in your code I am sure you will see where the problem is. Good luck
public void testGetEnabledMetricData() throws Exception {
MetricApi api = getApi().getMetricApi();
Resource r = getLocalPlatformResource(false, false);
MetricsResponse resp = api.getEnabledMetrics(r);
hqAssertSuccess(resp);
assertTrue("No enabled metrics found for " + r.getName(),
resp.getMetric().size() > 0);
Metric m = resp.getMetric().get(0);
long end = System.currentTimeMillis();
long start = end - (8 * 60 * 60 * 1000);
MetricDataResponse dataResponse = api.getMetricData(m.getId(),
start, end);
hqAssertSuccess(dataResponse);
assertTrue("No metric data found for " + m.getName(),
dataResponse.getMetricData().getDataPoint().size() > 0);
for (DataPoint d : dataResponse.getMetricData().getDataPoint()) {
assertTrue("Metric point timestamp greater than end time. ts=" +
d.getTimestamp() + " end=" + end,
d.getTimestamp() <= end);
assertTrue("Metric point timestamp less than start time ts=" +
d.getTimestamp() + " start=" + start,
d.getTimestamp() >= start);
assertTrue("Metric value less than zero",
d.getValue() >= 0);
}
}
精彩评论