@Override public boolean doMonitor(ServiceEmitter emitter) { // process CPU try { ProcCpu procCpu = sigar.getProcCpu(currentProcessId); final ServiceMetricEvent.Builder builder = builder(); MonitorUtils.addDimensionsToBuilder(builder, dimensions); // delta for total, sys, user Map<String, Long> procDiff = diff.to( "proc/cpu", ImmutableMap.of( "jvm/cpu/total", procCpu.getTotal(), "jvm/cpu/sys", procCpu.getSys(), "jvm/cpu/user", procCpu.getUser() ) ); if (procDiff != null) { for (Map.Entry<String, Long> entry : procDiff.entrySet()) { emitter.emit(builder.build(entry.getKey(), entry.getValue())); } } emitter.emit(builder.build("jvm/cpu/percent", procCpu.getPercent())); } catch (SigarException e) { log.error(e, "Failed to get ProcCpu"); } return true; } }
procCpu.getSys(), procCpu.getUser(), procCpu.getTotal()); } catch (SigarException e) { cpu = null;
@Override public Long getValue() { return context.get().getTotal(); } };
@Override public long computeValue() throws SigarException { return sigar.getProcCpu(pid).getTotal(); } });
@Override public Double getValue() { final ProcCpu procCpu = context.get(); final double cpuTime = procCpu.getTotal() - prevTotal; final long elapsedTime = procCpu.getLastTime() - prevTime; final double result = cpuTime / elapsedTime * 100 / processors; prevTotal = procCpu.getTotal(); prevTime = procCpu.getLastTime(); return result; } };
cpuTotal = procCpu.getTotal(); cpuTime = System.currentTimeMillis();
long getProcessCpuTimeRunningTotal( long pid ) { try { if( !isFaultyProcess( pid ) ) { return sigar.getProcCpu( pid ).getTotal(); } } catch( SigarException se ) { updateFaultyProcessesList( pid ); } return -1; }
public AggregateProcCpu(List<ProcCpu> cpus) { for (ProcCpu cpu : cpus) { if (cpu != null) { sys += cpu.getSys(); user += cpu.getUser(); total += cpu.getTotal(); percent += cpu.getPercent(); // TODO: this looks the same as ProcTime - what's the diff? // TODO: what about percent and the others? } } } }
public AggregateProcCpu(List<ProcCpu> cpus) { for (ProcCpu cpu : cpus) { if (cpu != null) { sys += cpu.getSys(); user += cpu.getUser(); total += cpu.getTotal(); percent += cpu.getPercent(); // TODO: this looks the same as ProcTime - what's the diff? // TODO: what about percent and the others? } } } }
public Gauge<Double> createProcessCpuLoadGauge() { return new InternalGauge<Double>(context) { private long prevTotal = context.get().getTotal(); private long prevTime = context.get().getStartTime(); @Override public Double getValue() { final ProcCpu procCpu = context.get(); final double cpuTime = procCpu.getTotal() - prevTotal; final long elapsedTime = procCpu.getLastTime() - prevTime; final double result = cpuTime / elapsedTime * 100 / processors; prevTotal = procCpu.getTotal(); prevTime = procCpu.getLastTime(); return result; } }; }
break; case TOTAL: cur = cpu.getTotal(); val = prev > 0 ? cur - prev : 0; prev = cur;
break; case TOTAL: cur = cpu.getTotal(); val = prev > 0 ? cur - prev : 0; prev = cur;
@Override public boolean doMonitor(ServiceEmitter emitter) { // process CPU try { ProcCpu procCpu = sigar.getProcCpu(currentProcessId); final ServiceMetricEvent.Builder builder = builder(); MonitorUtils.addDimensionsToBuilder(builder, dimensions); // delta for total, sys, user Map<String, Long> procDiff = diff.to( "proc/cpu", ImmutableMap.of( "jvm/cpu/total", procCpu.getTotal(), "jvm/cpu/sys", procCpu.getSys(), "jvm/cpu/user", procCpu.getUser() ) ); if (procDiff != null) { for (Map.Entry<String, Long> entry : procDiff.entrySet()) { emitter.emit(builder.build(entry.getKey(), entry.getValue())); } } emitter.emit(builder.build("jvm/cpu/percent", procCpu.getPercent())); } catch (SigarException e) { log.error(e, "Failed to get ProcCpu"); } return true; } }
@Override public boolean doMonitor(ServiceEmitter emitter) { // process CPU try { ProcCpu procCpu = sigar.getProcCpu(currentProcessId); final ServiceMetricEvent.Builder builder = builder(); MonitorUtils.addDimensionsToBuilder(builder, dimensions); // delta for total, sys, user Map<String, Long> procDiff = diff.to( "proc/cpu", ImmutableMap.of( "jvm/cpu/total", procCpu.getTotal(), "jvm/cpu/sys", procCpu.getSys(), "jvm/cpu/user", procCpu.getUser() ) ); if (procDiff != null) { for (Map.Entry<String, Long> entry : procDiff.entrySet()) { emitter.emit(builder.build(entry.getKey(), entry.getValue())); } } emitter.emit(builder.build("jvm/cpu/percent", procCpu.getPercent())); } catch (SigarException e) { log.error(e, "Failed to get ProcCpu"); } return true; } }
@Override public boolean doMonitor(ServiceEmitter emitter) { // process CPU try { ProcCpu procCpu = sigar.getProcCpu(currentProcessId); final ServiceMetricEvent.Builder builder = builder(); MonitorUtils.addDimensionsToBuilder(builder, dimensions); // delta for total, sys, user Map<String, Long> procDiff = diff.to( "proc/cpu", ImmutableMap.of( "jvm/cpu/total", procCpu.getTotal(), "jvm/cpu/sys", procCpu.getSys(), "jvm/cpu/user", procCpu.getUser() ) ); if (procDiff != null) { for (Map.Entry<String, Long> entry : procDiff.entrySet()) { emitter.emit(builder.build(entry.getKey(), entry.getValue())); } } emitter.emit(builder.build("jvm/cpu/percent", procCpu.getPercent())); } catch (SigarException e) { log.error(e, "Failed to get ProcCpu"); } return true; } }
@Override public boolean doMonitor(ServiceEmitter emitter) { // process CPU try { ProcCpu procCpu = sigar.getProcCpu(currentProcessId); final ServiceMetricEvent.Builder builder = builder(); MonitorUtils.addDimensionsToBuilder(builder, dimensions); // delta for total, sys, user Map<String, Long> procDiff = diff.to( "proc/cpu", ImmutableMap.of( "jvm/cpu/total", procCpu.getTotal(), "jvm/cpu/sys", procCpu.getSys(), "jvm/cpu/user", procCpu.getUser() ) ); if (procDiff != null) { for (Map.Entry<String, Long> entry : procDiff.entrySet()) { emitter.emit(builder.build(entry.getKey(), entry.getValue())); } } emitter.emit(builder.build("jvm/cpu/percent", procCpu.getPercent())); } catch (SigarException e) { log.error(e, "Failed to get ProcCpu"); } return true; } }
@Override public boolean doMonitor(ServiceEmitter emitter) { // process CPU try { ProcCpu procCpu = sigar.getProcCpu(currentProcessId); final ServiceMetricEvent.Builder builder = builder(); MonitorUtils.addDimensionsToBuilder(builder, dimensions); // delta for total, sys, user Map<String, Long> procDiff = diff.to( "proc/cpu", ImmutableMap.of( "jvm/cpu/total", procCpu.getTotal(), "jvm/cpu/sys", procCpu.getSys(), "jvm/cpu/user", procCpu.getUser() ) ); if (procDiff != null) { for (Map.Entry<String, Long> entry : procDiff.entrySet()) { emitter.emit(builder.build(entry.getKey(), entry.getValue())); } } emitter.emit(builder.build("jvm/cpu/percent", procCpu.getPercent())); } catch (SigarException e) { log.error(e, "Failed to get ProcCpu"); } return true; } }
procCpu.getSys(), procCpu.getUser(), procCpu.getTotal()); } catch (SigarException e) { cpu = null;
procCpu.getSys(), procCpu.getUser(), procCpu.getTotal()); } catch (SigarException e) { cpu = null;