Java Code Examples for com.netflix.spectator.api.Spectator#globalRegistry()

The following examples show how to use com.netflix.spectator.api.Spectator#globalRegistry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpectatorAppender.java    From spectator with Apache License 2.0 6 votes vote down vote up
/** Create a new instance of the appender using the global spectator registry. */
@PluginFactory
public static SpectatorAppender createAppender(
    @PluginAttribute("name") String name,
    @PluginAttribute("ignoreExceptions") boolean ignoreExceptions,
    @PluginElement("Layout") Layout<? extends Serializable> layout,
    @PluginElement("Filters") Filter filter) {

  if (name == null) {
    LOGGER.error("no name provided for SpectatorAppender");
    return null;
  }

  return new SpectatorAppender(
      Spectator.globalRegistry(),
      name, filter, layout, ignoreExceptions,
      Property.EMPTY_ARRAY);
}
 
Example 2
Source File: SpectatorRegistryFactory.java    From mantis with Apache License 2.0 5 votes vote down vote up
public static Registry getRegistry() {
    if (registryRef.get() == null) {
        return Spectator.globalRegistry();
    } else {
        return registryRef.get();
    }
}
 
Example 3
Source File: SpectatorReporter.java    From spectator with Apache License 2.0 5 votes vote down vote up
/** Create a new instance of the reporter. */
public SpectatorReporter build() {
  if (spectatorRegistry == null) {
    spectatorRegistry = Spectator.globalRegistry();
  }
  return new SpectatorReporter(
      registry, spectatorRegistry, nameFunction, valueFunction, gaugeCounters);
}
 
Example 4
Source File: ServoRegistryTest.java    From spectator with Apache License 2.0 5 votes vote down vote up
public void globalIterator(Function<Registry, Meter> createMeter) {
  Registry dflt = Servo.newRegistry();
  CompositeRegistry global = Spectator.globalRegistry();
  global.removeAll();
  global.add(dflt);

  boolean found = false;
  Id expected = createMeter.apply(dflt).id();
  for (Meter m : global) {
    found |= m.id().equals(expected);
  }
  Assertions.assertTrue(found, "id for sub-registry could not be found in global iterator");
}
 
Example 5
Source File: EVCacheMetricsFactory.java    From EVCache with Apache License 2.0 5 votes vote down vote up
public DistributionSummary getDistributionSummary(String name, Collection<Tag> tags) {
    final String metricName = (tags != null ) ? name + tags.toString() : name;
    final DistributionSummary _ds = distributionSummaryMap.get(metricName);
    if(_ds != null) return _ds;
    final Registry registry = Spectator.globalRegistry(); 
    if (registry != null) {
        Id id = getId(name, tags);
        final DistributionSummary ds = registry.distributionSummary(id);
        distributionSummaryMap.put(metricName, ds);
        return ds;
    }
    return null;
}
 
Example 6
Source File: ErrorStatsData.java    From zuul with Apache License 2.0 5 votes vote down vote up
/**
 * create a counter by route and cause of error
 * @param route
 * @param cause
 */
public ErrorStatsData(String route, String cause) {
    if(null == route || "".equals(route)){
        route = "UNKNOWN";
    }
    id = route + "_" + cause;

    this.errorCause = cause;
    Registry registry = Spectator.globalRegistry();
    PolledMeter.using(registry)
            .withId(registry.createId("zuul.ErrorStatsData", "ID", id))
            .monitorValue(this, ErrorStatsData::getCount);
}
 
Example 7
Source File: NamedCountingMonitor.java    From zuul with Apache License 2.0 5 votes vote down vote up
public NamedCountingMonitor(String name) {
    this.name = name;
    Registry registry = Spectator.globalRegistry();
    PolledMeter.using(registry)
            .withId(registry.createId("zuul.ErrorStatsData", "ID", name))
            .monitorValue(this, NamedCountingMonitor::getCount);
}
 
Example 8
Source File: RouteStatusCodeMonitor.java    From zuul with Apache License 2.0 5 votes vote down vote up
public RouteStatusCodeMonitor(@Nullable String route, int statusCode) {
    if (route == null) {
        route = "";
    }
    this.route = route;
    this.statusCode = statusCode;
    this.routeCode = route + "_" + statusCode;
    Registry registry = Spectator.globalRegistry();
    PolledMeter.using(registry)
            .withId(registry.createId("zuul.RouteStatusCodeMonitor", "ID", routeCode))
            .monitorValue(this, RouteStatusCodeMonitor::getCount);
}
 
Example 9
Source File: SpectatorExecutionInterceptor.java    From spectator with Apache License 2.0 4 votes vote down vote up
/**
 * Create a new instance using {@link Spectator#globalRegistry()}.
 */
public SpectatorExecutionInterceptor() {
  this(Spectator.globalRegistry());
}
 
Example 10
Source File: SpectatorAppender.java    From spectator with Apache License 2.0 4 votes vote down vote up
/** Create a new instance of the appender. */
public SpectatorAppender() {
  this(Spectator.globalRegistry());
}
 
Example 11
Source File: EVCacheMetricsFactory.java    From EVCache with Apache License 2.0 4 votes vote down vote up
public Registry getRegistry() {
    return Spectator.globalRegistry();
}
 
Example 12
Source File: SpectatorUtils.java    From zuul with Apache License 2.0 4 votes vote down vote up
public static <T extends Number> T newGauge(String name, String id, T number) {
    final CompositeRegistry registry = Spectator.globalRegistry();
    Id gaugeId = registry.createId(name, "id", id);
    return registry.gauge(gaugeId, number);
}
 
Example 13
Source File: SpectatorUtils.java    From zuul with Apache License 2.0 4 votes vote down vote up
public static <T extends Number> T newGauge(String name, String id, T number, String... tags) {
    final CompositeRegistry registry = Spectator.globalRegistry();
    Id gaugeId = registry.createId(name, getTagsWithId(id, tags));
    return registry.gauge(gaugeId, number);
}
 
Example 14
Source File: BaseZuulChannelInitializer.java    From zuul with Apache License 2.0 4 votes vote down vote up
private BaseZuulChannelInitializer(
        int port,
        String metricId,
        ChannelConfig channelConfig,
        ChannelConfig channelDependencies,
        ChannelGroup channels) {
    this.port = port;
    checkNotNull(metricId, "metricId");
    this.channelConfig = channelConfig;
    this.channelDependencies = channelDependencies;
    this.channels = channels;

    this.accessLogPublisher = channelDependencies.get(ZuulDependencyKeys.accessLogPublisher);

    this.withProxyProtocol = channelConfig.get(CommonChannelConfigKeys.withProxyProtocol);

    this.idleTimeout = channelConfig.get(CommonChannelConfigKeys.idleTimeout);
    this.httpRequestReadTimeout = channelConfig.get(CommonChannelConfigKeys.httpRequestReadTimeout);
    this.channelMetrics = new ServerChannelMetrics("http-" + metricId, Spectator.globalRegistry());
    this.registry = channelDependencies.get(ZuulDependencyKeys.registry);
    this.httpMetricsHandler = new HttpMetricsChannelHandler(registry, "server", "http-" + metricId);

    EventLoopGroupMetrics eventLoopGroupMetrics = channelDependencies.get(ZuulDependencyKeys.eventLoopGroupMetrics);
    PerEventLoopMetricsChannelHandler perEventLoopMetricsHandler = new PerEventLoopMetricsChannelHandler(eventLoopGroupMetrics);
    this.perEventLoopConnectionMetricsHandler = perEventLoopMetricsHandler.new Connections();
    this.perEventLoopRequestsMetricsHandler = perEventLoopMetricsHandler.new HttpRequests();

    this.maxConnections = channelConfig.get(CommonChannelConfigKeys.maxConnections);
    this.maxConnectionsHandler = new MaxInboundConnectionsHandler(maxConnections);
    this.maxRequestsPerConnection = channelConfig.get(CommonChannelConfigKeys.maxRequestsPerConnection);
    this.maxRequestsPerConnectionInBrownout = channelConfig.get(CommonChannelConfigKeys.maxRequestsPerConnectionInBrownout);
    this.connectionExpiry = channelConfig.get(CommonChannelConfigKeys.connectionExpiry);
    this.connCloseDelay = channelConfig.get(CommonChannelConfigKeys.connCloseDelay);

    StripUntrustedProxyHeadersHandler.AllowWhen allowProxyHeadersWhen = channelConfig.get(CommonChannelConfigKeys.allowProxyHeadersWhen);
    this.stripInboundProxyHeadersHandler = new StripUntrustedProxyHeadersHandler(allowProxyHeadersWhen);

    this.rateLimitingChannelHandler = channelDependencies.get(ZuulDependencyKeys.rateLimitingChannelHandlerProvider).get();

    this.sslClientCertCheckChannelHandler = channelDependencies.get(ZuulDependencyKeys.sslClientCertCheckChannelHandlerProvider).get();

    this.passportLoggingHandler = new PassportLoggingHandler(registry);

    this.sessionContextDecorator = channelDependencies.get(ZuulDependencyKeys.sessionCtxDecorator);
    this.requestCompleteHandler = channelDependencies.get(ZuulDependencyKeys.requestCompleteHandler);
    this.httpRequestReadTimeoutCounter = channelDependencies.get(ZuulDependencyKeys.httpRequestReadTimeoutCounter);

    this.filterLoader = channelDependencies.get(ZuulDependencyKeys.filterLoader);
    this.filterUsageNotifier = channelDependencies.get(ZuulDependencyKeys.filterUsageNotifier);

    this.sourceAddressChannelHandler = new SourceAddressChannelHandler();
}
 
Example 15
Source File: ServerTest.java    From zuul with Apache License 2.0 4 votes vote down vote up
@Test
public void getListeningSockets() throws Exception {
    ServerStatusManager ssm = mock(ServerStatusManager.class);
    Map<SocketAddress, ChannelInitializer<?>> initializers = new HashMap<>();
    ChannelInitializer<Channel> init = new ChannelInitializer<Channel>() {
        @Override
        protected void initChannel(Channel ch) {}
    };
    initializers.put(new InetSocketAddress(0), init);
    // Pick an InetAddress likely different than the above.  The port to channel map has a unique Key; this
    // prevents the key being a duplicate.
    initializers.put(new InetSocketAddress(InetAddress.getLocalHost(), 0), init);
    ClientConnectionsShutdown ccs =
            new ClientConnectionsShutdown(
                    new DefaultChannelGroup(GlobalEventExecutor.INSTANCE),
                    GlobalEventExecutor.INSTANCE,
                    /* discoveryClient= */ null);
    EventLoopGroupMetrics elgm = new EventLoopGroupMetrics(Spectator.globalRegistry());
    EventLoopConfig elc = new EventLoopConfig() {
        @Override
        public int eventLoopCount() {
            return 1;
        }

        @Override
        public int acceptorCount() {
            return 1;
        }
    };
    Server s = new Server(ssm, initializers, ccs, elgm, elc);
    s.start(/* sync= */ false);

    List<SocketAddress> addrs = s.getListeningAddresses();
    assertEquals(2, addrs.size());
    assertTrue(addrs.get(0) instanceof InetSocketAddress);
    assertNotEquals(((InetSocketAddress) addrs.get(0)).getPort(), 0);
    assertTrue(addrs.get(1) instanceof InetSocketAddress);
    assertNotEquals(((InetSocketAddress) addrs.get(1)).getPort(), 0);

    s.stop();
}
 
Example 16
Source File: IpcServletFilter.java    From spectator with Apache License 2.0 2 votes vote down vote up
/**
 * Create a new instance using the global registry. This is typically used when defining
 * the filter in the {@code web.xml} file and it is created by the container.
 */
public IpcServletFilter() {
  this(Spectator.globalRegistry());
}