|
6 | 6 | * 2015-5-5 |
7 | 7 | */ |
8 | 8 |
|
9 | | -const vmstat_path = '/usr/bin/vmstat'; //vmstat命令绝对路径 |
10 | | -const vmstat_params = array(1,1000000000); //vmstat 命令参数。格式vmstat part1 part2 |
11 | | -const host = "0.0.0.0"; //代表监听全部地址 |
12 | | -const port = 8888; //监听端口号 |
| 9 | +$vmstat_path = '/usr/bin/vmstat'; //vmstat命令绝对路径 |
| 10 | +$interval = 1; //vmstat 命令参数。指定每个报告之间的时间量 |
| 11 | +$count = 1000000000; //vmstat 命令参数。决定生成的报告数目和相互间隔的秒数 |
| 12 | +$host = "0.0.0.0"; //代表监听全部地址 |
| 13 | +$port = 8888; //监听端口号 |
13 | 14 |
|
14 | 15 | /** |
15 | 16 | * MasterPid命令时格式化输出 |
|
27 | 28 | * 创建一个websocket服务器 |
28 | 29 | * 端口8888 |
29 | 30 | */ |
30 | | -$server = new swoole_websocket_server(host, port); |
| 31 | +$table = new swoole_table(1024); |
| 32 | +$table->column('cmd', swoole_table::TYPE_STRING, 32); |
| 33 | +$table->column('interval', swoole_table::TYPE_INT, 2); |
| 34 | +$table->column('count', swoole_table::TYPE_STRING, 10); |
| 35 | +$table->create(); |
| 36 | +$table->set('vmstat', array('cmd' => $vmstat_path,'interval' => $interval, 'count' => $count)); |
| 37 | + |
| 38 | +$server = new swoole_websocket_server($host, $port); |
| 39 | +$server->table = $table; //将table保存在serv对象上 |
31 | 40 |
|
32 | 41 | /** |
33 | 42 | * 创建一个子进程 |
|
77 | 86 | * @param swoole_process $worker |
78 | 87 | */ |
79 | 88 | function callback_vmstat(swoole_process $worker) { |
80 | | - $worker->exec(vmstat_path, vmstat_params); |
| 89 | + global $table; |
| 90 | + $vmstat = $table->get('vmstat'); |
| 91 | + $cmd = $vmstat['cmd']; |
| 92 | + $interval = $vmstat['interval']; |
| 93 | + $count = $vmstat['count']; |
| 94 | + $worker->exec($cmd, array($interval, $count)); |
81 | 95 | } |
82 | 96 |
|
83 | 97 | /** |
|
0 commit comments