01: package org.cougaar.core.qos.profile;
02:
03: import java.lang.reflect.*;
04: import java.io.*;
05: import java.text.*;
06: import java.util.*;
07: import java.util.regex.*;
08: import org.cougaar.core.agent.*;
09: import org.cougaar.core.component.*;
10: import org.cougaar.core.mts.*;
11: import org.cougaar.core.node.*;
12: import org.cougaar.core.qos.metrics.*;
13: import org.cougaar.core.service.*;
14: import org.cougaar.core.service.wp.*;
15: import org.cougaar.core.thread.*;
16: import org.cougaar.core.wp.resolver.*;
17: import org.cougaar.util.*;
18:
19: /**
20: * This component profiles the {@link MetricsService}'s
21: * summary resource metrics (load average, tcp use, etc).
22: * <p>
23: * This is the same output as the "/metrics/resources" servlet
24: * generated by {@link org.cougaar.core.qos.metrics.NodeResourcesServlet}.
25: * <p>
26: * Example output:<pre>
27: * resources - #EffectiveMJips, LoadAverage, Count, Jips, BogoMips,
28: * Cache, TcpInUse, UdpInUse, TotalMemory, FreeMemory,
29: * MeanTimeBetweenFailure,
30: * resources - 1947, 2.67, 1, 1947156330, 5570,
31: * 512, 37, 8, 2064548, 121492,
32: * 8760,
33: * </pre>
34: *
35: * @see ProfilerCoordinator required coordinator component
36: */
37: public class Resources extends ProfilerBase {
38: private static final DecimalFormat FORMAT_DECIMAL = new DecimalFormat(
39: "#0.00");
40: private static final String[] FIELDS = new String[] {
41: "EffectiveMJips", "LoadAverage", "Count", "Jips",
42: "BogoMips", "Cache", "TcpInUse", "UdpInUse", "TotalMemory",
43: "FreeMemory", "MeanTimeBetweenFailure", };
44: private static final String HEADER = toHeader(FIELDS);
45:
46: private MetricsService ms;
47: private MessageAddress nodeId;
48:
49: public void load() {
50: super .load();
51: ms = (MetricsService) sb.getService(this , MetricsService.class,
52: null);
53: NodeIdentificationService nis = (NodeIdentificationService) sb
54: .getService(this , NodeIdentificationService.class, null);
55: nodeId = nis.getMessageAddress();
56: sb.releaseService(this , NodeIdentificationService.class, nis);
57: }
58:
59: public void run() {
60: log("org.cougaar.core.qos.profile.resources", HEADER,
61: getResources());
62: }
63:
64: private String getResources() {
65: StringBuffer buf = new StringBuffer();
66: for (int i = 0; i < FIELDS.length; i++) {
67: buf.append(getMetric(FIELDS[i])).append(", ");
68: }
69: return buf.toString();
70: }
71:
72: private String getMetric(String name) {
73: Metric metric = ms.getValue("Agent(" + nodeId + "):" + name);
74: if (metric == null) {
75: return "-1";
76: }
77: if (name.equals("LoadAverage")) {
78: return FORMAT_DECIMAL.format(metric.doubleValue());
79: }
80: return Integer.toString((int) metric.doubleValue());
81: }
82: }
|