long time; SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss.S"); long cpu = SysJMX.getCurrentThreadCPUnano(); for (int i = 0; i < 10000; i++) { date = sdf.format(new Date(System.currentTimeMillis() + i)); cpu = SysJMX.getCurrentThreadCPUnano() - cpu; System.out.println("SimpleDateFormat.format " + cpu / 1000000L + " ms"); cpu = SysJMX.getCurrentThreadCPUnano(); for (int i = 0; i < 10000; i++) { date = DateUtil.timestamp(System.currentTimeMillis() + i); cpu = SysJMX.getCurrentThreadCPUnano() - cpu; System.out.println("DateUtil.format " + cpu / 1000000L + " ms"); cpu = SysJMX.getCurrentThreadCPUnano(); for (int i = 0; i < 10000; i++) { time = sdf.parse("20101123").getTime(); cpu = SysJMX.getCurrentThreadCPUnano() - cpu; System.out.println("SimpleDateFormat.parse " + cpu / 1000000L + " ms"); cpu = SysJMX.getCurrentThreadCPUnano(); for (int i = 0; i < 10000; i++) { time = DateUtil.yyyymmdd("20101123"); cpu = SysJMX.getCurrentThreadCPUnano() - cpu; System.out.println("DateUtil.parse " + cpu / 1000000L + " ms");
this.obj_host_name = getValue("obj_host_name", SysJMX.getHostName()); this.objHostName = "/" + this.obj_host_name; this.objHostHash = HashUtil.hash(objHostName); String defaultName; if (this.obj_name_auto_pid_enabled == true) { defaultName = "" + SysJMX.getProcessPID(); } else { defaultName = this.obj_type + "1";
public void caculateResource(){ this.endCpu = SysJMX.getProcessCPU(); long [] gcInfo = SysJMX.getCurrentProcGcInfo(); this.gcCount = gcInfo[0]; this.gcTime = gcInfo[1]; }
private TraceContext() { startTime = ManagementFactory.getRuntimeMXBean().getStartTime(); readBatchId(); sqlMaxCount = Configure.getInstance().sql_max_count; pID = SysJMX.getProcessPID(); startCpu = SysJMX.getProcessCPU(); }
private static void waitOnExit(Server server) throws Exception { File exit = new File(SysJMX.getProcessPID() + ".scouter"); try { exit.createNewFile(); } catch (Exception e) { String tmp = System.getProperty("user.home", "/tmp"); exit = new File(tmp, SysJMX.getProcessPID() + ".scouter.run"); try { exit.createNewFile(); } catch (Exception k) { System.exit(1); } } exit.deleteOnExit(); System.out.println("System JRE version : " + System.getProperty("java.version")); while (true) { if (exit.exists() == false) { server.setStopTimeout(3000); server.stop(); System.exit(0); } ThreadUtil.sleep(1000); } }
flushErrorSummary(ctx); TraceContextManager.end(ctx.threadId); ctx.latestCpu = SysJMX.getCurrentThreadCPU(); ctx.latestBytes = SysJMX.getCurrentThreadAllocBytes(conf.profile_thread_memory_usage_enabled); TraceContextManager.toDeferred(ctx);
public synchronized void resetObjInfo() { this.obj_type = getValue("obj_type", CounterConstants.BATCH); String detected = CounterConstants.HOST; if (SystemUtil.IS_LINUX) { detected = CounterConstants.LINUX; } else if (SystemUtil.IS_WINDOWS) { detected = CounterConstants.WINDOWS; } else if (SystemUtil.IS_MAC_OSX) { detected = CounterConstants.OSX; } else if (SystemUtil.IS_AIX) { detected = CounterConstants.AIX; } else if (SystemUtil.IS_HP_UX) { detected = CounterConstants.HPUX; } this.obj_host_type = getValue("obj_host_type", detected); this.obj_host_name = getValue("obj_host_name", SysJMX.getHostName()); this.objHostName = "/" + this.obj_host_name; this.objHostHash = HashUtil.hash(this.objHostName); this.obj_name_auto_pid_enabled = getBoolean("obj_name_auto_pid_enabled", false); this.obj_name = getValue("obj_name", "batch"); this.objName = this.objHostName + "/" + this.obj_name; // make hash value try { this.objHash = HashUtil.hash( objName.getBytes("UTF-8")); }catch(Throwable ex){} System.setProperty("scouter.objname", this.objName); System.setProperty("scouter.objtype", this.obj_type); System.setProperty("scouter.dir", agent_dir_path); }
public void profile(String msg) { MessageStep p = new MessageStep(); p.message = msg; p.start_time = (int) (System.currentTimeMillis() - ctx.startTime); if (ctx.profile_thread_cputime) { p.start_cpu = (int) (SysJMX.getCurrentThreadCPU() - ctx.startCpu); } ctx.profile.add(p); }
@Counter public void cpuTime(CounterBasket pw) { if(SysJMX.isProcessCPU()==false) return; long cpu = SysJMX.getProcessCPU(); if (oldCpu<=0) { oldCpu = cpu; return; } long dTime = cpu - oldCpu; oldCpu = cpu; cpuTimeInfo.add(dTime); PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME); p.put(CounterConstants.JAVA_CPU_TIME, new DecimalValue(dTime)); p = pw.getPack(TimeTypeEnum.FIVE_MIN); p.put(CounterConstants.JAVA_CPU_TIME, new DecimalValue((long) cpuTimeInfo.getSum(300))); }
out.print(ctx.thread.getName() + ":"); out.println(ctx.thread.getState().name()); out.println("cpu " + SysJMX.getThreadCpuTime(ctx.thread)); out.println(Hexa32.toString32(ctx.txid)); out.print(ctx.serviceName + ":"); msg.append(ctx.thread.getName() + ":"); msg.append(ctx.thread.getState().name() + ":"); msg.append("cpu " + SysJMX.getThreadCpuTime(ctx.thread) + System.getProperty("line.separator")); msg.append(Hexa32.toString32(ctx.txid) + System.getProperty("line.separator")); msg.append(System.getProperty("line.separator"));
@Counter public void getGCInfo(CounterBasket pw) { long[] gcInfo = SysJMX.getCurrentProcGcInfo(); if (oldGc == null) { oldGc = gcInfo; return; } long dCount = gcInfo[0] - oldGc[0]; long dTime = gcInfo[1] - oldGc[1]; oldGc = gcInfo; gcCountInfo.add(dCount); gcTimeInfo.add(dTime); PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME); p.put(CounterConstants.JAVA_GC_COUNT, new DecimalValue(dCount)); p.put(CounterConstants.JAVA_GC_TIME, new DecimalValue(dTime)); p = pw.getPack(TimeTypeEnum.FIVE_MIN); p.put(CounterConstants.JAVA_GC_COUNT, new DecimalValue((long) gcCountInfo.getSum(300))); p.put(CounterConstants.JAVA_GC_TIME, new DecimalValue((long) gcTimeInfo.getSum(300))); } @Counter
private static synchronized void openFile(String prefix) throws IOException { if (pw == null && StringUtil.isEmpty(conf.log_dir) == false) { File root = new File(conf.log_dir); if (root.canWrite() == false) { root.mkdirs(); } if (root.canWrite() == false) { return; } String name = prefix + ((conf.batch_id == null)?"batch":conf.batch_id + "_" + SysJMX.getProcessPID()); if (conf.log_rotation_enabled) { File file = new File(conf.log_dir, "scouter-" + name + "-" + DateUtil.yyyymmdd() + ".log"); FileWriter fw = new FileWriter(file, true); pw = new PrintWriter(fw); logfile = file; } else { File file = new File(conf.log_dir, "scouter-" + name + ".log"); pw = new PrintWriter(new FileWriter(file, true)); logfile = file; } } }
ctx.txid = KeyGen.next(); ctx.startTime = System.currentTimeMillis(); ctx.startCpu = SysJMX.getCurrentThreadCPU(); ctx.bytes = SysJMX.getCurrentThreadAllocBytes(conf.profile_thread_memory_usage_enabled); ctx.profile_thread_cputime = conf.profile_thread_cputime_enabled;
public synchronized void resetObjInfo() { String detected = CounterConstants.HOST; if (SystemUtil.IS_LINUX) { detected = CounterConstants.LINUX; } else if (SystemUtil.IS_WINDOWS) { detected = CounterConstants.WINDOWS; } else if (SystemUtil.IS_MAC_OSX) { detected = CounterConstants.OSX; } else if (SystemUtil.IS_AIX) { detected = CounterConstants.AIX; } else if (SystemUtil.IS_HP_UX) { detected = CounterConstants.HPUX; } this.objDetectedType = detected; this.monitoring_group_type = getValue("monitoring_group_type"); this.obj_type = StringUtil.isEmpty(this.monitoring_group_type) ? getValue("obj_type", detected) : this.monitoring_group_type; this.obj_name = getValue("obj_name", SysJMX.getHostName()); this.objName = "/" + this.obj_name; this.objHash = HashUtil.hash(objName); }
public void profile(String msg) { MessageStep p = new MessageStep(); p.message = msg; p.start_time = (int) (System.currentTimeMillis() - ctx.startTime); if (ctx.profile_thread_cputime) { p.start_cpu = (int) (SysJMX.getCurrentThreadCPU() - ctx.startCpu); } ctx.profile.add(p); }
@Counter public void cpuTime(CounterBasket pw) { if(SysJMX.isProcessCPU()==false) return; long cpu = SysJMX.getProcessCPU(); if (oldCpu<=0) { oldCpu = cpu; return; } long dTime = cpu - oldCpu; oldCpu = cpu; cpuTimeInfo.add(dTime); PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME); p.put(CounterConstants.JAVA_CPU_TIME, new DecimalValue(dTime)); p = pw.getPack(TimeTypeEnum.FIVE_MIN); p.put(CounterConstants.JAVA_CPU_TIME, new DecimalValue((long) cpuTimeInfo.getSum(300))); }
out.print(ctx.thread.getName() + ":"); out.println(ctx.thread.getState().name()); out.println("cpu " + SysJMX.getThreadCpuTime(ctx.thread)); out.println(Hexa32.toString32(ctx.txid)); out.print(ctx.serviceName + ":"); msg.append(ctx.thread.getName() + ":"); msg.append(ctx.thread.getState().name() + ":"); msg.append("cpu " + SysJMX.getThreadCpuTime(ctx.thread) + System.getProperty("line.separator")); msg.append(Hexa32.toString32(ctx.txid) + System.getProperty("line.separator")); msg.append(System.getProperty("line.separator"));
@Counter public void getGCInfo(CounterBasket pw) { long[] gcInfo = SysJMX.getCurrentProcGcInfo(); if (oldGc == null) { oldGc = gcInfo; return; } long dCount = gcInfo[0] - oldGc[0]; long dTime = gcInfo[1] - oldGc[1]; oldGc = gcInfo; gcCountInfo.add(dCount); gcTimeInfo.add(dTime); PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME); p.put(CounterConstants.JAVA_GC_COUNT, new DecimalValue(dCount)); p.put(CounterConstants.JAVA_GC_TIME, new DecimalValue(dTime)); p = pw.getPack(TimeTypeEnum.FIVE_MIN); p.put(CounterConstants.JAVA_GC_COUNT, new DecimalValue((long) gcCountInfo.getSum(300))); p.put(CounterConstants.JAVA_GC_TIME, new DecimalValue((long) gcTimeInfo.getSum(300))); } @Counter
@Counter public void regist(CounterBasket pw) { Configure conf = Configure.getInstance(); try { int pid = SysJMX.getProcessPID(); File dir = new File(conf.counter_object_registry_path); File file = new File(dir, pid + ".scouter"); if (dir.canWrite()) { FileUtil.save(file, conf.getObjName().getBytes()); } } catch (Exception e) { e.printStackTrace(); } } }
this.obj_host_name = getValue("obj_host_name", SysJMX.getHostName()); this.objHostName = "/" + this.obj_host_name; this.objHostHash = HashUtil.hash(objHostName); String defaultName; if (this.obj_name_auto_pid_enabled == true) { defaultName = "" + SysJMX.getProcessPID(); } else { defaultName = this.obj_type + "1";