@ServiceHandler(RequestCmd.REMOTE_CONTROL) public void remoteControl(DataInputX din, DataOutputX dout, boolean login) throws IOException { MapPack param = (MapPack) din.readPack(); long session = param.getLong("toSession"); RemoteControl control = new RemoteControl( // param.getText("command"), // System.currentTimeMillis(), // param, param.getLong("fromSession")); boolean result = RemoteControlManager.add(session, control); Logger.println( "[" + RequestCmd.REMOTE_CONTROL + "]" + control.commnad() + " from " + LoginManager.getUser(control.commander()).ip() + " to " + LoginManager.getUser(session).ip() + " " + result); MapPack m = new MapPack(); if (result) { m.put("success", new BooleanValue(true)); dout.writeByte(TcpFlag.HasNEXT); dout.writePack(m); } else { m.put("success", new BooleanValue(false)); dout.writeByte(TcpFlag.HasNEXT); dout.writePack(m); } }
@RequestHandler(RequestCmd.LIST_CONFIGURE_WAS) public Pack listConfigure(Pack param) { MapValue m = Configure.getInstance().getKeyValueInfo(); MapPack pack = new MapPack(); pack.put("key", m.getList("key")); pack.put("value", m.getList("value")); pack.put("default", m.getList("default")); return pack; }
private void load() { final ArrayList<Pack> values = new ArrayList<Pack>(); TcpProxy tcp = TcpProxy.getTcpProxy(serverId); try { MapPack param = new MapPack(); param.put("sDate", sDate); param.put("eDate", eDate); param.put("objType", objType); param.put("counter", counter); tcp.process( RequestCmd.COUNTER_PAST_LONGDATE_ALL, param, new INetReader() { public void process(DataInputX in) throws IOException { Pack pack = in.readPack(); values.add(pack); }; }); } catch (Throwable t) { ConsoleProxy.errorSafe(t.toString()); } finally { TcpProxy.putTcpProxy(tcp); } final Map<Long, Double> valueMap = ScouterUtil.getLoadTotalMap(counter, values, mode, TimeTypeEnum.FIVE_MIN); ExUtil.exec( this.canvas, new Runnable() { public void run() { try { traceDataProvider.clearTrace(); Set<Long> timeSet = valueMap.keySet(); for (long time : timeSet) { traceDataProvider.addSample( new Sample(CastUtil.cdouble(time), CastUtil.cdouble(valueMap.get(time)))); } } catch (Throwable t) { ConsoleProxy.error(t.toString()); } if (CounterUtil.isPercentValue(objType, counter)) { xyGraph.primaryYAxis.setRange(0, 100); } else { double max = ChartUtil.getMax(traceDataProvider.iterator()); xyGraph.primaryYAxis.setRange(0, max); } redraw(); applyBtn.setEnabled(true); } }); }
public void load() { TcpProxy tcp = TcpProxy.getTcpProxy(serverId); MapPack out = null; try { MapPack param = new MapPack(); param.put("date", date); param.put("objHash", objHash); param.put("objType", objType); param.put("counter", counter); param.put("stime", startTime); param.put("etime", endTime); out = (MapPack) tcp.getSingle(RequestCmd.COUNTER_PAST_TIME, param); if (out == null) { return; } } catch (Throwable t) { ConsoleProxy.errorSafe(t.toString()); } finally { TcpProxy.putTcpProxy(tcp); } final ListValue time = out.getList("time"); final ListValue value = out.getList("value"); ExUtil.exec( this.canvas, new Runnable() { public void run() { provider.clearTrace(); for (int i = 0; time != null && i < time.size(); i++) { long tm = CastUtil.clong(time.get(i)); double va = CastUtil.cdouble(value.get(i)); provider.addSample(new Sample(tm, va)); } xyGraph.primaryXAxis.setRange(startTime, endTime); if (CounterUtil.isPercentValue(objType, counter)) { xyGraph.primaryYAxis.setRange(0, 100); } else { xyGraph.primaryYAxis.setRange(0, ChartUtil.getMax(provider.iterator())); } canvas.redraw(); xyGraph.repaint(); } }); }
@RequestHandler(RequestCmd.GET_CONFIGURE_WAS) public Pack getAgentConfigure(Pack param) { MapPack p = new MapPack(); p.put("configKey", Configure.getInstance().getKeyValueInfo().getList("key")); String config = Configure.getInstance().loadText(); if (config == null) { // config = getEmptyConfiguration(); config = ""; } p.put("agentConfig", config); return p; }
public MapPack fetch() { TcpProxy tcp = TcpProxy.getTcpProxy(serverId); Pack pack = null; try { MapPack param = new MapPack(); ListValue objLv = param.newList("objHash"); Map<Integer, AgentObject> agentMap = AgentModelThread.getInstance().getAgentObjectMap(); for (AgentObject p : agentMap.values()) { if (p.getObjType().equals(objType)) { objLv.add(p.getObjHash()); } } pack = tcp.getSingle(RequestCmd.REALTIME_SERVICE_GROUP, param); } catch (Throwable th) { th.printStackTrace(); } finally { TcpProxy.putTcpProxy(tcp); } MapPack m = null; if (pack != null) { m = (MapPack) pack; long time = TimeUtil.getCurrentTime(serverId); m.put("time", time); fiveMinMap.put(time, m); } return m; }
protected IStatus run(IProgressMonitor monitor) { monitor.beginTask("Find " + Hexa32.toString32(xlogData.p.txid), IProgressMonitor.UNKNOWN); final LongKeyLinkedMap<XLogData> xlogMap = new LongKeyLinkedMap<XLogData>(); xlogMap.put(xlogData.p.txid, xlogData); long callerId = xlogData.p.caller; boolean found = true; while (found && callerId != 0) { found = false; Iterator<Integer> itr = ServerManager.getInstance().getOpenServerList().iterator(); while (itr.hasNext()) { final int serverId = itr.next(); monitor.subTask(ServerManager.getInstance().getServer(serverId).getName()); TcpProxy tcp = TcpProxy.getTcpProxy(serverId); try { MapPack param = new MapPack(); param.put("date", date); param.put("txid", callerId); Pack p = tcp.getSingle(RequestCmd.XLOG_READ_BY_TXID, param); if (p != null) { XLogPack xlog = XLogUtil.toXLogPack(p); XLogData d = new XLogData(xlog, serverId); d.objName = TextProxy.object.getLoadText(date, d.p.objHash, serverId); xlogMap.put(xlog.txid, d); callerId = xlog.caller; found = true; break; } } catch (Throwable th) { ConsoleProxy.errorSafe(th.toString()); callerId = 0; } finally { TcpProxy.putTcpProxy(tcp); } } } ExUtil.exec( viewer.getGraphControl(), new Runnable() { public void run() { viewer.setInput(xlogMap); } }); return Status.OK_STATUS; }
private void getYesterdayData(String date) { final ArrayList<Pack> values = new ArrayList<Pack>(); TcpProxy tcp = TcpProxy.getTcpProxy(serverId); try { MapPack param = new MapPack(); param.put("date", date); param.put("objType", objType); param.put("counter", counter); tcp.process( RequestCmd.COUNTER_PAST_DATE_ALL, param, new INetReader() { public void process(DataInputX in) throws IOException { Pack p = in.readPack(); values.add(p); }; }); } catch (Throwable t) { t.printStackTrace(); } finally { TcpProxy.putTcpProxy(tcp); } final Map<Long, Double> valueMap = ScouterUtil.getLoadTotalMap(counter, values, mode, TimeTypeEnum.FIVE_MIN); ExUtil.exec( this.canvas, new Runnable() { public void run() { yesterdayDataProvider.clearTrace(); Set<Long> timeSet = valueMap.keySet(); for (long time : timeSet) { yesterdayDataProvider.addSample( new Sample( CastUtil.cdouble(time + DateUtil.MILLIS_PER_DAY), CastUtil.cdouble(valueMap.get(time)))); } yesterdayMax = ChartUtil.getMax(yesterdayDataProvider.iterator()); } }); }
@RequestHandler(RequestCmd.SET_CONFIGURE_WAS) public Pack setAgentConfigure(Pack param) { final String setConfig = ((MapPack) param).getText("setConfig"); boolean success = Configure.getInstance().saveText(setConfig); if (success) { Configure.getInstance().reload(true); } MapPack p = new MapPack(); p.put("result", String.valueOf(success)); return p; }
@RequestHandler(RequestCmd.REDEFINE_CLASSES) public Pack redefineClasses(Pack param) { final MapPack p = new MapPack(); ListValue classLv = ((MapPack) param).getList("class"); HashSet<String> paramSet = new HashSet<String>(); for (int i = 0; i < classLv.size(); i++) { String className = classLv.getString(i); paramSet.add(className); } Class[] classes = JavaAgent.getInstrumentation().getAllLoadedClasses(); ArrayList<ClassDefinition> definitionList = new ArrayList<ClassDefinition>(); boolean allSuccess = true; for (int i = 0; paramSet.size() > 0 && i < classes.length; i++) { if (paramSet.contains(classes[i].getName())) { try { byte[] buff = LazyAgentBoot.getByteCode(classes[i]); if (buff == null) { continue; } definitionList.add(new ClassDefinition(classes[i], buff)); paramSet.remove(classes[i].getName()); } catch (Exception e) { p.put("success", new BooleanValue(false)); p.put("error", e.toString()); allSuccess = false; break; } } } if (definitionList.size() > 0 && allSuccess) { try { JavaAgent.getInstrumentation() .redefineClasses(definitionList.toArray(new ClassDefinition[definitionList.size()])); p.put("success", new BooleanValue(true)); } catch (Throwable th) { p.put("success", new BooleanValue(false)); p.put("error", th.toString()); } } return p; }
@ServiceHandler(RequestCmd.SERVER_DB_LIST) public void listDbFiles(DataInputX din, DataOutputX dout, boolean login) throws IOException { String rootPath = DBCtr.getRootPath(); MapPack m = new MapPack(); ListValue nameLv = m.newList("name"); ListValue sizeLv = m.newList("size"); ListValue lastModifiedLv = m.newList("lastModified"); File dbDir = new File(rootPath); long totalLength = 0; if (dbDir.exists() && dbDir.isDirectory()) { totalLength = collectDirectory(dbDir, nameLv, sizeLv, lastModifiedLv, dbDir.getAbsolutePath()); } if (SystemUtil.IS_JAVA_1_5 == false) { m.put("free", dbDir.getUsableSpace()); } m.put("total", totalLength); dout.writeByte(TcpFlag.HasNEXT); dout.writePack(m); dout.flush(); }
@ServiceHandler(RequestCmd.SERVER_DB_DELETE) public void deleteDbFiles(DataInputX din, DataOutputX dout, boolean login) throws IOException { String rootPath = DBCtr.getRootPath(); MapPack param = (MapPack) din.readPack(); ListValue fileLv = param.getList("file"); MapPack m = new MapPack(); if (fileLv != null) { for (int i = 0; i < fileLv.size(); i++) { String filename = fileLv.getString(i); File file = new File(rootPath + filename); deleteFiles(file); } m.put("size", fileLv.size()); } dout.writeByte(TcpFlag.HasNEXT); dout.writePack(m); dout.flush(); }
protected IStatus run(IProgressMonitor monitor) { monitor.beginTask("Find " + Hexa32.toString32(gxid), IProgressMonitor.UNKNOWN); final LongKeyLinkedMap<Object> xlogMap = new LongKeyLinkedMap<Object>(); Iterator<Integer> itr = ServerManager.getInstance().getOpenServerList().iterator(); while (itr.hasNext()) { final int serverId = itr.next(); monitor.subTask(ServerManager.getInstance().getServer(serverId).getName()); TcpProxy tcp = TcpProxy.getTcpProxy(serverId); try { MapPack param = new MapPack(); param.put("date", date); param.put("gxid", gxid); tcp.process( RequestCmd.XLOG_READ_BY_GXID, param, new INetReader() { public void process(DataInputX in) throws IOException { Pack p = in.readPack(); XLogPack xlog = XLogUtil.toXLogPack(p); XLogData d = new XLogData(xlog, serverId); d.objName = TextProxy.object.getLoadText(date, d.p.objHash, d.serverId); xlogMap.putFirst(xlog.txid, d); } }); } catch (Throwable th) { ConsoleProxy.errorSafe(th.toString()); } finally { TcpProxy.putTcpProxy(tcp); } } ExUtil.exec( viewer.getGraphControl(), new Runnable() { public void run() { viewer.setInput(xlogMap); } }); return Status.OK_STATUS; }
public void refresh() { String date = DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId) - DateUtil.MILLIS_PER_DAY); if (date.equals(yesterday) == false) { yesterday = date; getYesterdayData(date); } final ArrayList<Pack> packs = new ArrayList<Pack>(); TcpProxy tcp = TcpProxy.getTcpProxy(serverId); try { MapPack param = new MapPack(); param.put("objType", objType); param.put("counter", counter); param.put("mode", CounterUtil.getTotalMode(objType, counter)); isActive = false; tcp.process( RequestCmd.COUNTER_TODAY_ALL, param, new INetReader() { public void process(DataInputX in) throws IOException { packs.add(in.readPack()); } }); } catch (Throwable t) { ConsoleProxy.errorSafe(t.toString()); } finally { TcpProxy.putTcpProxy(tcp); } final Map<Long, Double> valueMap = ScouterUtil.getLoadTotalMap(counter, packs, mode, TimeTypeEnum.FIVE_MIN); if (valueMap.size() > 0) { isActive = true; } ExUtil.exec( this.canvas, new Runnable() { public void run() { if (isActive) { setActive(); } else { setInactive(); } String date = DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId)); try { long stime = DateUtil.getTime(date, "yyyyMMdd"); long etime = stime + DateUtil.MILLIS_PER_DAY; xyGraph.primaryXAxis.setRange(stime, etime); traceDataProvider.clearTrace(); Set<Long> timeSet = valueMap.keySet(); for (long time : timeSet) { traceDataProvider.addSample( new Sample(CastUtil.cdouble(time), CastUtil.cdouble(valueMap.get(time)))); } if (CounterUtil.isPercentValue(objType, counter)) { xyGraph.primaryYAxis.setRange(0, 100); } else { double max = ChartUtil.getMax(traceDataProvider.iterator()); max = Math.max(max, yesterdayMax); xyGraph.primaryYAxis.setRange(0, max); } } catch (Exception e) { e.printStackTrace(); } canvas.redraw(); xyGraph.repaint(); } }); }
public void refresh() { TcpProxy tcp = TcpProxy.getTcpProxy(serverId); Pack p = null; final String date = DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId)); try { MapPack param = new MapPack(); param.put( "objHash", agentDailyProxy.getObjHashLv(date, serverId, CounterConstants.MARIA_PLUGIN)); param.put("sdate", date); param.put("edate", date); p = tcp.getSingle(RequestCmd.DB_DAILY_ACTIVITY, param); } catch (Exception e) { ConsoleProxy.errorSafe(e.toString()); } finally { TcpProxy.putTcpProxy(tcp); } if (p == null) { ExUtil.exec( canvas, new Runnable() { public void run() { setTitleImage(Images.inactive); if (fixRange == false) { DbTodayTotalActivityView.this.setContentDescription( date.substring(0, 4) + "-" + date.substring(5, 6) + "-" + date.substring(7, 8)); long stime = DateUtil.yyyymmdd(date); long etime = stime + DateUtil.MILLIS_PER_DAY - 1; xyGraph.primaryXAxis.setRange(stime, etime); } } }); } else { MapPack m = (MapPack) p; final ListValue timeLv = m.getList("time"); final ListValue callLv = m.getList("call"); final ListValue selectLv = m.getList("select"); final ListValue insertLv = m.getList("insert"); final ListValue updateLv = m.getList("update"); final ListValue deleteLv = m.getList("delete"); ExUtil.exec( canvas, new Runnable() { public void run() { setTitleImage(Images.active); CircularBufferDataProvider callProvider = (CircularBufferDataProvider) callTrace.getDataProvider(); CircularBufferDataProvider selectProvider = (CircularBufferDataProvider) selectTrace.getDataProvider(); CircularBufferDataProvider insertProvider = (CircularBufferDataProvider) insertTrace.getDataProvider(); CircularBufferDataProvider updateProvider = (CircularBufferDataProvider) updateTrace.getDataProvider(); CircularBufferDataProvider deleteProvider = (CircularBufferDataProvider) deleteTrace.getDataProvider(); callProvider.clearTrace(); selectProvider.clearTrace(); insertProvider.clearTrace(); updateProvider.clearTrace(); deleteProvider.clearTrace(); for (int i = 0; i < timeLv.size(); i++) { long time = timeLv.getLong(i); double value = deleteLv.getDouble(i); deleteProvider.addSample(new Sample(time, value)); value += updateLv.getDouble(i); updateProvider.addSample(new Sample(time, value)); value += insertLv.getDouble(i); insertProvider.addSample(new Sample(time, value)); value += selectLv.getDouble(i); selectProvider.addSample(new Sample(time, value)); value += callLv.getDouble(i); callProvider.addSample(new Sample(time, value)); } if (fixRange == false) { DbTodayTotalActivityView.this.setContentDescription( date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8)); long stime = DateUtil.yyyymmdd(date); long etime = stime + DateUtil.MILLIS_PER_DAY - 1; xyGraph.primaryXAxis.setRange(stime, etime); double max = ChartUtil.getMax(callProvider.iterator()); xyGraph.primaryYAxis.setRange(0, max); } } }); } }
public void refresh() { ScouterUtil.collectGroupObjcts(grpName, serverObjMap); isActive = false; Iterator<Integer> serverIds = serverObjMap.keySet().iterator(); final List<Pack> result = new ArrayList<Pack>(); while (serverIds.hasNext()) { int serverId = serverIds.next(); TcpProxy tcp = TcpProxy.getTcpProxy(serverId); try { MapPack param = new MapPack(); param.put("counter", counter); param.put("objHash", serverObjMap.get(serverId)); tcp.process( RequestCmd.COUNTER_TODAY_GROUP, param, new INetReader() { public void process(DataInputX in) throws IOException { Pack p = in.readPack(); if (p != null) { result.add(p); } } }); } catch (Exception e) { e.printStackTrace(); } finally { TcpProxy.putTcpProxy(tcp); } } final long[] values = new long[(int) (DateUtil.MILLIS_PER_DAY / DateUtil.MILLIS_PER_HOUR)]; if (result.size() > 0) { Map<Long, Double> valueMap = ScouterUtil.getLoadTotalMap(counter, result, mode, TimeTypeEnum.FIVE_MIN); Iterator<Long> itr = valueMap.keySet().iterator(); while (itr.hasNext()) { long time = itr.next(); int index = (int) (DateUtil.getDateMillis(time) / DateUtil.MILLIS_PER_HOUR); values[index] += valueMap.get(time); } isActive = true; } ExUtil.exec( this.canvas, new Runnable() { public void run() { if (isActive == true) { setActive(); } else { setInactive(); return; } double max = 0; traceDataProvider.clearTrace(); for (int i = 0; i < values.length; i++) { traceDataProvider.addSample( new Sample(CastUtil.cdouble(i) + 0.5d, CastUtil.cdouble(values[i]))); } max = Math.max(ChartUtil.getMax(traceDataProvider.iterator()), max); if (CounterUtil.isPercentValue(objType, counter)) { xyGraph.primaryYAxis.setRange(0, 100); } else { xyGraph.primaryYAxis.setRange(0, max); } canvas.redraw(); xyGraph.repaint(); } }); }
public void refresh() { TcpProxy tcp = TcpProxy.getTcpProxy(serverId); Value v = null; try { MapPack param = new MapPack(); ListValue objHashLv = AgentModelThread.getInstance().getLiveObjHashLV(serverId, CounterConstants.MARIA_PLUGIN); if (objHashLv.size() > 0) { param.put("objHash", objHashLv); v = tcp.getSingleValue(RequestCmd.DB_REALTIME_ACTIVITY, param); } } catch (Exception e) { ConsoleProxy.errorSafe(e.toString()); } finally { TcpProxy.putTcpProxy(tcp); } if (v == null) { ExUtil.exec( canvas, new Runnable() { public void run() { setTitleImage(Images.inactive); long now = TimeUtil.getCurrentTime(serverId); long stime = now - TIME_RANGE; xyGraph.primaryXAxis.setRange(stime, now + 1); } }); } else { MapValue mv = (MapValue) v; final DecimalValue callValue = new DecimalValue(mv.getLong("call")); final DecimalValue selectValue = new DecimalValue(mv.getLong("select")); final DecimalValue insertValue = new DecimalValue(mv.getLong("insert")); final DecimalValue updateValue = new DecimalValue(mv.getLong("update")); final DecimalValue deleteValue = new DecimalValue(mv.getLong("delete")); ExUtil.exec( canvas, new Runnable() { public void run() { setTitleImage(Images.active); long now = TimeUtil.getCurrentTime(serverId) / REFRESH_INTERVAL * REFRESH_INTERVAL; long stime = now - TIME_RANGE; xyGraph.primaryXAxis.setRange(stime, now + 1); ValueLog valueLog = new ValueLog(); valueLog.time = now; valueLog.delete = deleteValue.value; valueLog.update = updateValue.value; valueLog.insert = insertValue.value; valueLog.select = selectValue.value; valueLog.call = callValue.value; valueLogs.add(valueLog); if (valueLogs.size() > BUFFER_SIZE) { valueLogs.removeFirst(); } if (isStackView) { updateValue.value += deleteValue.value; insertValue.value += updateValue.value; selectValue.value += insertValue.value; callValue.value += selectValue.value; } ((CircularBufferDataProvider) callTrace.getDataProvider()) .addSample(new Sample(now, callValue.value)); ((CircularBufferDataProvider) selectTrace.getDataProvider()) .addSample(new Sample(now, selectValue.value)); ((CircularBufferDataProvider) insertTrace.getDataProvider()) .addSample(new Sample(now, insertValue.value)); ((CircularBufferDataProvider) updateTrace.getDataProvider()) .addSample(new Sample(now, updateValue.value)); ((CircularBufferDataProvider) deleteTrace.getDataProvider()) .addSample(new Sample(now, deleteValue.value)); xyGraph.primaryYAxis.setRange(0, getMaxYValue()); } private double getMaxYValue() { if (isStackView) { return ChartUtil.getMax( ((CircularBufferDataProvider) callTrace.getDataProvider()).iterator()); } double value = ChartUtil.getMax( ((CircularBufferDataProvider) callTrace.getDataProvider()).iterator()); value = Math.max( value, ChartUtil.getMax( ((CircularBufferDataProvider) selectTrace.getDataProvider()).iterator())); value = Math.max( value, ChartUtil.getMax( ((CircularBufferDataProvider) insertTrace.getDataProvider()).iterator())); value = Math.max( value, ChartUtil.getMax( ((CircularBufferDataProvider) updateTrace.getDataProvider()).iterator())); value = Math.max( value, ChartUtil.getMax( ((CircularBufferDataProvider) deleteTrace.getDataProvider()).iterator())); return value; } }); } }