Skip navigation links


Primary interfaces for working with spectator.

See: Description

Package Description

Primary interfaces for working with spectator. To get started, here is a small code sample:
 Server s = new Server(new DefaultRegistry());

 class Server {
   private final Registry registry;
   private final Id requestCountId;
   private final Timer requestLatency;
   private final DistributionSummary responseSizes;

   public Server(Registry registry) {
     this.registry = registry;
     requestCountId = registry.createId("server.requestCount");
     requestLatency = registry.timer("server.requestLatency");
     responseSizes = registry.distributionSummary("server.responseSizes");
     registry.gauge("server.numConnections", this, Server::getNumConnections);

   public Response handle(Request req) {
     final long s = System.nanoTime();
     try {
       Response res = doSomething(req);

       final Id cntId = requestCountId
         .withTag("status", res.status());


       return res;
     } catch (Exception e) {
       final Id cntId = requestCountId
         .withTag("status", "exception")
         .withTag("error", e.getClass().getSimpleName());
       throw e;
     } finally {
       requestLatency.record(System.nanoTime() - s, TimeUnit.NANOSECONDS);

   public int getNumConnections() {
     // however we determine the current number of connections on the server
The main classes you will need to understand:
Skip navigation links