All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netflix.spectator.api.package-info Maven / Gradle / Ivy

There is a newer version: 1.7.21
Show newest version
/**
 * Copyright 2015 Netflix, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * 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("country", req.country())
 *         .withTag("status", res.status());
 *       registry.counter(cntId).increment();
 *
 *       responseSizes.record(res.body().size());
 *
 *       return res;
 *     } catch (Exception e) {
 *       final Id cntId = requestCountId
 *         .withTag("country", req.country())
 *         .withTag("status", "exception")
 *         .withTag("error", e.getClass().getSimpleName());
 *       registry.counter(cntId).increment();
 *       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: * *
    *
  • {@link com.netflix.spectator.api.Spectator}: static entrypoint to access the registry.
  • *
  • {@link com.netflix.spectator.api.Registry}: registry class used to create meters.
  • *
  • {@link com.netflix.spectator.api.Counter}: meter type for measuring a rate of change.
  • *
  • {@link com.netflix.spectator.api.Timer}: meter type for measuring the time for many short * events.
  • *
  • {@link com.netflix.spectator.api.LongTaskTimer}: meter type for measuring the time for a * few long events.
  • *
  • {@link com.netflix.spectator.api.DistributionSummary}: meter type for measuring the sample * distribution of some type of events.
  • *
*/ package com.netflix.spectator.api;




© 2015 - 2024 Weber Informatics LLC | Privacy Policy