設(shè)計(jì)實(shí)現(xiàn)方式: 抽象工廠模式+xml+HTTP流響應(yīng)方式
描述:管理服務(wù)器上的進(jìn)程狀態(tài)信息,進(jìn)程關(guān)閉,開啟,日志信息等
調(diào)用代碼測(cè)試類:
200并發(fā)籬柵壓測(cè)final static String api = "http://115.29.163.148:9001/RPC2"; final static String userName = "zhubo"; final static String passWord = "123456"; final static String namespace = "supervisor"; //初始化 static XmlRpcFactory xmlRpcFactory = null; public static void main(String[] args) throws InterruptedException { xmlRpcFactory = new SimpleXMLRpcFactory(); int size = 200; CyclicBarrier cb = new CyclicBarrier(size); ExecutorService service = Executors.newFixedThreadPool(size); System.out.PRintln(new Date()); for(int i =0;i<size;i++){ service.execute(new rpcThread(cb)); } service.shutdown(); //調(diào)用API while(true){ if(!service.isTerminated()){ Thread.sleep(1000); }else{ System.out.println(new Date()); break; } } //監(jiān)控請(qǐng)求成功,失敗,異常記錄 for(SimpleXMLPRC rpc :SimpleXMLRpcFactory.getRegistries()) { Map<String, Set<XmlRpcCount>> maprpc = rpc.getCounter(); System.out.println(maprpc.get(Constants.SUCCESS).size()); //System.out.println(JSON.toJSONString(maprpc.get(Constants.SUCCESS)));//成功 System.out.println(JSON.toJSONString(maprpc.get(Constants.FAILURE)));//失敗 System.out.println(JSON.toJSONString(maprpc.get(Constants.ERROR)));//異常 AtomicInteger atomicInteger = new AtomicInteger(0); for(XmlRpcCount xmlRpcCount :maprpc.get(Constants.SUCCESS)){ atomicInteger.incrementAndGet(); System.out.println(atomicInteger.get()+"---"+JSON.toJSONString(xmlRpcCount)); } } } static class rpcThread implements Runnable{ private CyclicBarrier cb; public rpcThread( CyclicBarrier cb ){ this.cb = cb; } @Override public void run() { try { cb.await(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BrokenBarrierException e) { // TODO Auto-generated catch block e.printStackTrace(); } // TODO Auto-generated method stub SimpleXMLPRC simpleXMLPRC =(SimpleXMLPRC) xmlRpcFactory.getXmlRpc(api, userName, password, namespace); simpleXMLPRC.getAPIVersion(); com.yuntai.yw.supervisord.tools.Process process = simpleXMLPRC.getProcessInfo("dubbo:hs-med-service-queue"); } }JSON樣板數(shù)據(jù)
{"description":"pid 31164, uptime 0:00:05","exitStatus":0,"group":"dubbo","logFile":"/tmp/supervisor/hs-med-service-queue.log","name":"hs-med-service-queue","pid":31164,"start":"1484534147","stateName":"RUNNING","stdoutFile":"/tmp/supervisor/hs-med-service-queue.log","stop":"1484534146"}
進(jìn)程Process類
字段  | 類型 | 描述 | 
|---|---|---|
| name | String | 名稱 | 
| group | String | 組名 | 
| description | String | 描述信息 | 
| start | String | 啟動(dòng)時(shí)間戳 | 
| stop | String | 結(jié)束時(shí)間戳 | 
| now | String | 當(dāng)前時(shí)間戳 | 
| status | String | 狀態(tài) | 
| statusName | String | 狀態(tài)名稱 | 
| exitStatus | int | 退出狀態(tài) | 
| logFile | String | 日志文件內(nèi)容 | 
| stdoutFile | String | 日志文件內(nèi)容 | 
| pid | int | 進(jìn)程Pid | 
API:
| 方法API | 參數(shù) | 說明 | 
|---|---|---|
| public String getAPIVersion(); | 獲取api版本號(hào) | |
| public XmlRpc namespace(String namespace); | namespace 空間(默認(rèn)supervisor) | 根據(jù)namespace獲取調(diào)用實(shí)例 | 
| public XmlRpc proxy(String host, int port); | host 請(qǐng)求url 及port端口 | 根據(jù)url及端口 獲取調(diào)用實(shí)例 | 
| public XmlRpc auth(String username, String password); | 用戶名 密碼 | 鑒權(quán)實(shí)例 | 
| public String getSupervisorVersion(); | 安裝在服務(wù)器上的supervisor版本號(hào) | |
| public String getIdentification(); | 實(shí)例名一般為空間namespace名(服務(wù)器上配置) | |
| public Map<String, Object> getState(); | 服務(wù)器上的supervisor服務(wù)狀態(tài) | |
| public int getPID(); | 服務(wù)器上的supervisor服務(wù)的進(jìn)程id | |
| public String readLog(int offset, int length) ; | 日志開始位置 及長(zhǎng)度 | 日志內(nèi)容 | 
| public boolean clearLog(); | 清除supervisor服務(wù)日志文件 | |
| public boolean shutdown(); | 關(guān)閉supervisor服務(wù) | |
| public boolean restart(); | 重啟supervisor服務(wù) | |
| public Process getProcessInfo(String processName); | supervisor管理下的進(jìn)程名 | 進(jìn)程信息 | 
| public Object[] getAllProcessInfo(); | 獲取所有進(jìn)程信息 | |
| public boolean startProcess(String processName, boolean waitToStart); | 進(jìn)程名 是否等待 | 啟動(dòng)服務(wù)器上進(jìn)程名 | 
| public Object[] startAllProcesses(boolean waitToStart); | 是否等待 | 啟動(dòng)服務(wù)器上所有進(jìn)程 | 
| public boolean startProcessGroup(String groupName, boolean waitToStart); | 組名 是否等待 | 根據(jù)組名 啟動(dòng)各個(gè)進(jìn)程 | 
| public boolean stopProcess(String processName, boolean waitToStop); | 進(jìn)程名 是否等待 | 關(guān)閉服務(wù)器上進(jìn)程名 | 
| public boolean stopProcessGroup(String groupName, boolean waitToStop) ; | 組名 是否等待 | 根據(jù)組名 關(guān)閉各個(gè)進(jìn)程 | 
| public Object[] stopAllProcesses(boolean waitToStop) ; | 是否等待 | 關(guān)閉服務(wù)器上所有進(jìn)程 | 
資源地址:http://download.csdn.net/detail/pajiakuo/9756525
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注