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 output of the "/usr/bin/vmstat"
21: * command, which summarizes the system performance.
22: *
23: * @see ProfilerCoordinator required coordinator component
24: */
25: public class VmStat extends ProfilerBase {
26: // procs memory swap io system cpu
27: // r b w swpd free buff cache si so bi bo in cs us sy id
28: // 0 0 0 0 374080 132504 1481500 0 0 0 5 3 12 1 0 4
29: private static final String[] FIELDS = new String[] {
30: "proc_runnable", "proc_blocked", "proc_waiting",
31: "mem_swapped_kB", "mem_free_kB", "mem_buff_kB",
32: "mem_cache_kB", "swapped_in_kB_per_sec",
33: "swapped_out_kB_per_sec", "io_blocks_in_per_sec",
34: "io_blocks_out_per_sec", "interrupts_per_sec",
35: "context_switches_per_sec", "cpu_user", "cpu_system",
36: "cpu_idle", };
37: private static final String HEADER = toHeader(FIELDS);
38:
39: public void run() {
40: log("org.cougaar.core.qos.profile.vmstat", HEADER, getVmStat());
41: }
42:
43: private String getVmStat() {
44: StringBuffer buf = new StringBuffer();
45: try {
46: Process proc = Runtime.getRuntime().exec("/usr/bin/vmstat");
47: BufferedReader br = new BufferedReader(
48: new InputStreamReader(proc.getInputStream()));
49: String h1 = br.readLine();
50: String h2 = br.readLine();
51: String data = br.readLine();
52: br.close();
53: String[] sa = data.trim().split("\\s+");
54: for (int i = 0; i < sa.length; i++) {
55: for (int j = 6 - sa[i].length(); j > 0; j--) {
56: buf.append(" ");
57: }
58: buf.append(sa[i]).append(", ");
59: }
60: } catch (Exception e) {
61: }
62: return buf.toString();
63: }
64: }
|