Skip to content

Commit

Permalink
Merge pull request #26 from scouter-project/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
bill23-kim committed Aug 10, 2015
2 parents 94901a1 + 6bad440 commit 9c152d4
Show file tree
Hide file tree
Showing 67 changed files with 372 additions and 260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ public static MeterService getInstance() {
return inst;
}

static class Bucket {
final static int PCT_MAX_TIME = 10000;
final static int PCT_UNIT_TIME = 200;
final static int PCT_BUCKET = PCT_MAX_TIME / PCT_UNIT_TIME;

final static class Bucket {
final short[] pct90 = new short[PCT_BUCKET];
int count;
int error;
long time;

int error;
}

private MeteringUtil<Bucket> meter = new MeteringUtil<Bucket>() {
Expand All @@ -43,15 +49,24 @@ protected void clear(Bucket o) {
o.count = 0;
o.error = 0;
o.time = 0L;
for (int i = 0; i < PCT_BUCKET; i++) {
o.pct90[i] = 0;
}
}
};

public synchronized void add(long elapsed, boolean err) {
public synchronized void add(int elapsed, boolean err) {
Bucket b = meter.getCurrentBucket();
b.count++;
b.time += elapsed;
if (err)
if (err) {
b.error++;
}
if (elapsed < PCT_MAX_TIME) {
int x = (int) (elapsed / PCT_UNIT_TIME);
b.pct90[x]++;
}

}

public float getTPS(int period) {
Expand All @@ -77,6 +92,31 @@ public void process(Bucket b) {
return (int) ((cnt.value == 0) ? 0 : sum.value / cnt.value);
}

public int getElapsed90Pct(int period) {
final LONG sum = new LONG();
final INT cnt = new INT();
meter.search(period, new Handler<MeterService.Bucket>() {
public void process(Bucket b) {
int total = (int) (b.count * 0.9);
if (total == 0)
return;

for (int timeInx = 0; timeInx < PCT_BUCKET; timeInx++) {
if (total >= b.pct90[timeInx]) {
total -= b.pct90[timeInx];
} else {
sum.value += timeInx * PCT_UNIT_TIME;
cnt.value++;
return;
}
}
sum.value += PCT_MAX_TIME;
cnt.value++;
}
});
return (int) ((cnt.value == 0) ? 0 : sum.value / cnt.value);
}

public float getError(int period) {

final INT cnt = new INT();
Expand Down
21 changes: 12 additions & 9 deletions scouter.agent.java/src/scouter/agent/counter/task/ServicePerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,29 @@ public class ServicePerf {
public void getServicePerf(CounterBasket pw) {
Configure conf = Configure.getInstance();
MeterService service = MeterService.getInstance();
float elapsed = service.getElapsedTime(30);
int elapsed = service.getElapsedTime(30);
float tps = service.getTPS(30);
float err = service.getError(30);
int count = service.getServiceCount(60);

int resp90pct = service.getElapsed90Pct(30);

int[] act = TraceContextManager.getActiveCount();
int active = act[0] + act[1] + act[2];
if (conf.auto_dump_trigger <= active) {
DumpUtil.autoDump();
}

}
activeCounter.add(active);

// active service 30초 평균으로 변경
active = (int) Math.round(activeCounter.getAvg(30));

PerfCounterPack p = pw.getPack(TimeTypeEnum.REALTIME);
p.put(CounterConstants.WAS_ELAPSED_TIME, new FloatValue(elapsed));
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));
p.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(active));
p.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(active));
p.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(resp90pct));

ListValue activeSpeed = new ListValue();
activeSpeed.add(act[0]);
Expand All @@ -75,13 +76,15 @@ public void getServicePerf(CounterBasket pw) {
elapsed = service.getElapsedTime(300);
err = service.getError(300);
int activeSErvice = (int) activeCounter.getAvg(300);

resp90pct = service.getElapsed90Pct(300);

p = pw.getPack(TimeTypeEnum.FIVE_MIN);
p.put(CounterConstants.WAS_ELAPSED_TIME, new FloatValue(elapsed));
p.put(CounterConstants.WAS_ELAPSED_TIME, new DecimalValue(elapsed));
p.put(CounterConstants.WAS_SERVICE_COUNT, new DecimalValue(count));
p.put(CounterConstants.WAS_TPS, new FloatValue(tps));
p.put(CounterConstants.WAS_ERROR_RATE, new FloatValue(err));
p.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(activeSErvice));
p.put(CounterConstants.WAS_ACTIVE_SERVICE, new DecimalValue(activeSErvice));
p.put(CounterConstants.WAS_ELAPSED_90PCT, new DecimalValue(resp90pct));
}

}
Loading

0 comments on commit 9c152d4

Please sign in to comment.