RPC工程 supervisord系统管理服务器进程

来源:互联网 发布:超级网络编辑器 编辑:程序博客网 时间:2024/06/06 06:59

设计实现方式: 抽象工厂模式+XML+HTTP流响应方式

描述:管理服务器上的进程状态信息,进程关闭,开启,日志信息等

调用代码测试类:

200并发篱栅压测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();        //调用API        while(true){            if(!service.isTerminated()){                Thread.sleep(1000);            }else{                System.out.println(new Date());                break;            }        }      //监控请求成功,失败,异常记录     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样板数据

{"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"}

进程Process类

字段

类型描述nameString名称groupString组名descriptionString描述信息startString启动时间戳stopString结束时间戳nowString当前时间戳statusString状态statusNameString状态名称exitStatusint退出状态logFileString日志文件内容stdoutFileString日志文件内容pidint进程Pid


API:

方法API参数说明public String getAPIVersion(); 获取api版本号public XmlRpc namespace(String namespace);namespace 空间(默认supervisor)根据namespace获取调用实例public XmlRpc proxy(String host, int port);host 请求url 及port端口根据url及端口  获取调用实例public XmlRpc auth(String username, String password);用户名   密码鉴权实例public String getSupervisorVersion(); 安装在服务器上的supervisor版本号public String getIdentification(); 实例名一般为空间namespace名(服务器上配置)public Map<String, Object> getState(); 服务器上的supervisor服务状态public int getPID(); 服务器上的supervisor服务的进程idpublic String readLog(int offset, int length) ;日志开始位置 及长度日志内容public boolean clearLog(); 清除supervisor服务日志文件public boolean shutdown(); 关闭supervisor服务public boolean restart(); 重启supervisor服务public Process getProcessInfo(String processName);supervisor管理下的进程名进程信息public Object[] getAllProcessInfo(); 获取所有进程信息public boolean startProcess(String processName, boolean waitToStart);进程名  是否等待启动服务器上进程名public Object[] startAllProcesses(boolean waitToStart);是否等待启动服务器上所有进程public boolean startProcessGroup(String groupName, boolean waitToStart);组名  是否等待根据组名 启动各个进程public boolean stopProcess(String processName, boolean waitToStop);进程名  是否等待关闭服务器上进程名public boolean stopProcessGroup(String groupName, boolean waitToStop) ;组名  是否等待根据组名 关闭各个进程public Object[] stopAllProcesses(boolean waitToStop) ;是否等待关闭服务器上所有进程


资源地址:http://download.csdn.net/detail/pajiakuo/9756525

0 0
原创粉丝点击