package otcoteam.tahiti.performance.example;

import otcoteam.tahiti.performance.PerformanceMonitor;
import otcoteam.tahiti.performance.recorder.CountingRecorder;
import otcoteam.tahiti.performance.reporter.LogReporter;
import otcoteam.tahiti.performance.reporter.RollingFileReporter;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class PerMiniuteCountingExample {

    public static void main(String args[]) {
        // Ҫһ, ˴ǽ RollingFileReporter, 
        // ɱ浽һļ. ʱʽ yyyy-MM-dd_HH-mm, 
        // ˽ÿһļ.
        LogReporter reporter = new RollingFileReporter("bar-%d{yyyy-MM-dd_HH-mm}.log");

        // ܼʵ
        final PerformanceMonitor monitor = new PerformanceMonitor(reporter);

        // ҪͳƵָ, Ҫгʼ. ˴ʹ CountingRecorder, 
        // ָ. ڼָ, ʱۼʱڵļ¼.
        monitor.addRecorder("request", new CountingRecorder("Request times"));
        monitor.addRecorder("login", new CountingRecorder("User login times"));

        // ʼʱ, ˴ÿ 1 ͳһ.
        monitor.start(1, TimeUnit.MINUTES);

        // ģÿ 5 һ request
        ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(1);
        executorService.scheduleAtFixedRate(new Runnable() {
            public void run() {
                monitor.record("request");
            }
        }, 5, 5, TimeUnit.SECONDS);

        // ģÿ 10 һ login
        executorService.scheduleAtFixedRate(new Runnable() {
            public void run() {
                monitor.record("login");
            }
        }, 10, 10, TimeUnit.SECONDS);
    }

}

add example