Package me.shimi.metrics.dashboard

Source Code of me.shimi.metrics.dashboard.MetricsDashboard

package me.shimi.metrics.dashboard;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;

import com.yammer.metrics.Metrics;
import com.yammer.metrics.core.MetricsRegistry;

public class MetricsDashboard {
  private final int port;
  private final int maxItems;

  public MetricsDashboard(int port, int maxItems) {
    this.port = port;
    this.maxItems = maxItems;
  }

  public void run() {

    MetricsRegistry registry = Metrics.defaultRegistry();

    ServerBootstrap bootstrap = new ServerBootstrap(
        new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(),
            Executors.newCachedThreadPool()));

    HtmlReporter reporter = new HtmlReporter(registry, maxItems);
    ResourceProvider resourceProvider = new ResourceProvider(registry);
    DashBoardProvider dashboardProvider = new DashBoardProvider(registry, reporter);
    HttpServerHandler serverHandler = new HttpServerHandler(
        resourceProvider, dashboardProvider);
    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(new HttpServerPipelineFactory(
        serverHandler));

    // Bind and start to accept incoming connections.
    bootstrap.bind(new InetSocketAddress(port));
  }

  public static void main(String[] args) {
    int port;
    if (args.length > 0) {
      port = Integer.parseInt(args[0]);
    } else {
      port = 9091;
    }
    new MetricsDashboard(port, 20).run();
  }
}
TOP

Related Classes of me.shimi.metrics.dashboard.MetricsDashboard

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.