Skip to content

Commit

Permalink
rename metrics package
Browse files Browse the repository at this point in the history
  • Loading branch information
Calvin committed Jun 16, 2014
1 parent 1152471 commit c0c9734
Show file tree
Hide file tree
Showing 8 changed files with 498 additions and 498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import javax.annotation.PreDestroy;

import org.springside.modules.metrics.MetricRegistry;
import org.springside.modules.metrics.report.GraphiteReporter;
import org.springside.modules.metrics.report.ReportScheduler;
import org.springside.modules.metrics.report.Slf4jReporter;
import org.springside.modules.metrics.reporter.GraphiteReporter;
import org.springside.modules.metrics.reporter.ReportScheduler;
import org.springside.modules.metrics.reporter.Slf4jReporter;

/**
* 控制多个Reporter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* 1. 使用timer
*
* <pre>
* TimerContext timerContext = execution.start();
* TimerContext timerContext = timer.start();
* ...
* timerContext.stop();
* </pre>
Expand All @@ -24,7 +24,7 @@
* <pre>
* long start = System.currentTimeMillis();
* ....
* execution.update(start);
* timer.update(start);
* </pre>
*
*
Expand Down Expand Up @@ -74,8 +74,8 @@ public static class TimerContext {
private final Timer timer;
private final long startTime;

private TimerContext(Timer execution, long startTime) {
this.timer = execution;
private TimerContext(Timer timer, long startTime) {
this.timer = timer;
this.startTime = startTime;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
/*******************************************************************************
* Copyright (c) 2005, 2014 springside.github.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
*******************************************************************************/
package org.springside.modules.metrics.report;

import java.io.PrintStream;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;

import org.springside.modules.metrics.CounterMetric;
import org.springside.modules.metrics.HistogramMetric;
import org.springside.modules.metrics.TimerMetric;

public class ConsoleReporter implements Reporter {

private static final int CONSOLE_WIDTH = 80;
private PrintStream output = System.out;

@Override
public void report(Map<String, CounterMetric> counters, Map<String, HistogramMetric> histograms,
Map<String, TimerMetric> timers) {

printWithBanner(new Date().toString(), '=');
output.println();

if (!counters.isEmpty()) {
printWithBanner("-- Counters", '-');
for (Map.Entry<String, CounterMetric> entry : counters.entrySet()) {
output.println(entry.getKey());
printCounter(entry.getValue());
}
output.println();
}

if (!histograms.isEmpty()) {
printWithBanner("-- Histograms", '-');
for (Map.Entry<String, HistogramMetric> entry : histograms.entrySet()) {
output.println(entry.getKey());
printHistogram(entry.getValue());
}
output.println();
}

if (!timers.isEmpty()) {
printWithBanner("-- Timers", '-');
for (Map.Entry<String, TimerMetric> entry : timers.entrySet()) {
output.println(entry.getKey());
printTimer(entry.getValue());
}
output.println();
}
}

private void printWithBanner(String s, char c) {
output.print(s);
output.print(' ');
for (int i = 0; i < (CONSOLE_WIDTH - s.length() - 1); i++) {
output.print(c);
}
output.println();
}

private void printCounter(CounterMetric counter) {
output.printf(" count = %d%n", counter.totalCount);
output.printf(" last rate = %2.2f/s%n", counter.lastRate);
output.printf(" mean rate = %2.2f/s%n", counter.meanRate);
}

private void printHistogram(HistogramMetric histogram) {
output.printf(" min = %d%n", histogram.min);
output.printf(" max = %d%n", histogram.max);
output.printf(" mean = %2.2f%n", histogram.mean);
for (Entry<Double, Long> pct : histogram.pcts.entrySet()) {
output.printf(" %2.2f%% <= %d %n", pct.getKey(), pct.getValue());
}
}

private void printTimer(TimerMetric timer) {
output.printf(" count = %d%n", timer.counterMetric.totalCount);
output.printf(" last rate = %2.2f/s%n", timer.counterMetric.lastRate);
output.printf(" mean rate = %2.2f/s%n", timer.counterMetric.meanRate);
output.printf(" min = %d ms%n", timer.histogramMetric.min);
output.printf(" max = %d ms%n", timer.histogramMetric.max);
output.printf(" mean = %2.2f ms%n", timer.histogramMetric.mean);
for (Entry<Double, Long> pct : timer.histogramMetric.pcts.entrySet()) {
output.printf(" %2.2f%% <= %d ms%n", pct.getKey(), pct.getValue());
}
}
}
/*******************************************************************************
* Copyright (c) 2005, 2014 springside.github.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
*******************************************************************************/
package org.springside.modules.metrics.reporter;

import java.io.PrintStream;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;

import org.springside.modules.metrics.CounterMetric;
import org.springside.modules.metrics.HistogramMetric;
import org.springside.modules.metrics.TimerMetric;

public class ConsoleReporter implements Reporter {

private static final int CONSOLE_WIDTH = 80;
private PrintStream output = System.out;

@Override
public void report(Map<String, CounterMetric> counters, Map<String, HistogramMetric> histograms,
Map<String, TimerMetric> timers) {

printWithBanner(new Date().toString(), '=');
output.println();

if (!counters.isEmpty()) {
printWithBanner("-- Counters", '-');
for (Map.Entry<String, CounterMetric> entry : counters.entrySet()) {
output.println(entry.getKey());
printCounter(entry.getValue());
}
output.println();
}

if (!histograms.isEmpty()) {
printWithBanner("-- Histograms", '-');
for (Map.Entry<String, HistogramMetric> entry : histograms.entrySet()) {
output.println(entry.getKey());
printHistogram(entry.getValue());
}
output.println();
}

if (!timers.isEmpty()) {
printWithBanner("-- Timers", '-');
for (Map.Entry<String, TimerMetric> entry : timers.entrySet()) {
output.println(entry.getKey());
printTimer(entry.getValue());
}
output.println();
}
}

private void printWithBanner(String s, char c) {
output.print(s);
output.print(' ');
for (int i = 0; i < (CONSOLE_WIDTH - s.length() - 1); i++) {
output.print(c);
}
output.println();
}

private void printCounter(CounterMetric counter) {
output.printf(" count = %d%n", counter.totalCount);
output.printf(" last rate = %2.2f/s%n", counter.lastRate);
output.printf(" mean rate = %2.2f/s%n", counter.meanRate);
}

private void printHistogram(HistogramMetric histogram) {
output.printf(" min = %d%n", histogram.min);
output.printf(" max = %d%n", histogram.max);
output.printf(" mean = %2.2f%n", histogram.mean);
for (Entry<Double, Long> pct : histogram.pcts.entrySet()) {
output.printf(" %2.2f%% <= %d %n", pct.getKey(), pct.getValue());
}
}

private void printTimer(TimerMetric timer) {
output.printf(" count = %d%n", timer.counterMetric.totalCount);
output.printf(" last rate = %2.2f/s%n", timer.counterMetric.lastRate);
output.printf(" mean rate = %2.2f/s%n", timer.counterMetric.meanRate);
output.printf(" min = %d ms%n", timer.histogramMetric.min);
output.printf(" max = %d ms%n", timer.histogramMetric.max);
output.printf(" mean = %2.2f ms%n", timer.histogramMetric.mean);
for (Entry<Double, Long> pct : timer.histogramMetric.pcts.entrySet()) {
output.printf(" %2.2f%% <= %d ms%n", pct.getKey(), pct.getValue());
}
}
}
Loading

0 comments on commit c0c9734

Please sign in to comment.