/**
* 父进程,用来调用子进程,打印子进程的输出到控制台,这里的输出可以写入一个文件等方式。
*
*/
public class Tcollector {
public static void main(String[] args) throws IOException {
Runtime run = Runtime.getRuntime();//获得运行的环境
Process ps = run.exec("java sysstat");//调用子进程
BufferedInputStream in = new BufferedInputStream(ps.getInputStream());
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String metric;
while((metric=br.readLine())!=null){
System.out.println(metric);
}
}
}
/**
* 模拟探针来采集数据
*
*/
public class SysStat {
public static void main(String[] args) {
int value = (int) Math.random()*100;
//模拟探针来采集系统底层的数据
System.out.println("sys.cpu.user"+System.currentTimeMillis()+""+value+"host = master");
System.out.println("sys.memory.user"+System.currentTimeMillis()+""+value*1024*1024+"host = slaver");
}
}