@Override public void register(NamedCount monitorObj) { Monitors.registerObject(monitorObj); } }
private void setupMonitoring() { try { final ObjectName mBeanName = ObjectName.getInstance("com.netflix.evcache:Group=" + _appName + ",SubGroup=pool"); final MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); if (mbeanServer.isRegistered(mBeanName)) { if (log.isDebugEnabled()) log.debug("MBEAN with name " + mBeanName + " has been registered. Will unregister the previous instance and register a new one."); mbeanServer.unregisterMBean(mBeanName); } if (!_shutdown) { mbeanServer.registerMBean(this, mBeanName); Monitors.registerObject(this); } else { Monitors.unregisterObject(this); } } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Exception", e); } }
void initMonitors(String name) { Preconditions.checkNotNull(name); freeEntryCounter = Monitors.newCounter(name + "_Reuse"); createEntryCounter = Monitors.newCounter(name + "_CreateNew"); requestCounter = Monitors.newCounter(name + "_Request"); releaseCounter = Monitors.newCounter(name + "_Release"); deleteCounter = Monitors.newCounter(name + "_Delete"); requestTimer = Monitors.newTimer(name + "_RequestConnectionTimer", TimeUnit.MILLISECONDS); creationTimer = Monitors.newTimer(name + "_CreateConnectionTimer", TimeUnit.MILLISECONDS); this.name = name; Monitors.registerObject(name, this); }
@Override public void shutdown() { super.shutdown(); if(Monitors.isObjectRegistered(name, this)) { Monitors.unregisterObject(name, this); } } }
public TimedSupervisorTask(String name, ScheduledExecutorService scheduler, ThreadPoolExecutor executor, int timeout, TimeUnit timeUnit, int expBackOffBound, Runnable task) { this.scheduler = scheduler; this.executor = executor; this.timeoutMillis = timeUnit.toMillis(timeout); this.task = task; this.delay = new AtomicLong(timeoutMillis); this.maxDelay = timeoutMillis * expBackOffBound; // Initialize the counters and register. successCounter = Monitors.newCounter("success"); timeoutCounter = Monitors.newCounter("timeouts"); rejectedCounter = Monitors.newCounter("rejectedExecutions"); throwableCounter = Monitors.newCounter("throwables"); threadPoolLevelGauge = new LongGauge(MonitorConfig.builder("threadPoolUsed").build()); Monitors.registerObject(name, this); }
protected HttpClientListener(String monitorId) { super(monitorId); requestBacklog = newLongGauge("requestBacklog"); inflightRequests = newLongGauge("inflightRequests"); requestWriteTimes = newTimer("requestWriteTimes"); responseReadTimes = newTimer("responseReadTimes"); processedRequests = newCounter("processedRequests"); requestWriteFailed = newCounter("requestWriteFailed"); failedResponses = newCounter("failedResponses"); failedContentSource = newCounter("failedContentSource"); requestProcessingTimes = newTimer("requestProcessingTimes"); }
@Test public void testIsRegistered() throws Exception { ClassWithMonitors obj = new ClassWithMonitors(); assertFalse(Monitors.isObjectRegistered("id", obj)); Monitors.registerObject("id", obj); assertTrue(Monitors.isObjectRegistered("id", obj)); }
/** * Unregister an object from the default registry. Equivalent to * {@code DefaultMonitorRegistry.getInstance().unregister(Monitors.newObjectMonitor(obj))}. * * @param obj Previously registered using {@code Monitors.registerObject(obj)} */ public static void unregisterObject(Object obj) { unregisterObject(null, obj); }
/** * Helper function to easily create a composite for all monitor fields and * annotated attributes of a given object. */ public static CompositeMonitor<?> newObjectMonitor(Object obj) { return newObjectMonitor(null, obj); }
static Counter newCounter(String name) { Counter c = Monitors.newCounter(name); DefaultMonitorRegistry.getInstance().register(c); return c; }
/** * Create a new timer with a name and context. The returned timer will maintain separate * sub-monitors for each distinct set of tags returned from the context on an update operation. */ public static Timer newTimer(String name, TaggingContext context) { return newTimer(name, TimeUnit.MILLISECONDS, context); }
@Test public void testAddMonitorsAnon() throws Exception { List<Monitor<?>> monitors = new ArrayList<>(); ClassWithMonitors obj = new ClassWithMonitors() { final Counter c1 = Monitors.newCounter("publicCounter"); @com.netflix.servo.annotations.Monitor( name = "primitiveGauge", type = DataSourceType.GAUGE) static final long A1 = 0L; }; TagList tags = BasicTagList.of("abc", "def"); Monitors.addMonitors(monitors, null, tags, obj); assertEquals(monitors.size(), 10); for (Monitor m : monitors) { assertEquals(m.getConfig().getTags().getValue("class"), "MonitorsTest", String.format("%s should have class MonitorsTest", m.getConfig().getName())); } }
/** * Check whether an object is currently registered with the default registry. */ public static boolean isObjectRegistered(Object obj) { return isObjectRegistered(null, obj); }
public ZoneStats(String name, String zone, LoadBalancerStats loadBalancerStats) { this.zone = zone; this.loadBalancerStats = loadBalancerStats; monitorId = name + ":" + zone; counter = Monitors.newCounter(PREFIX + name + "_" + zone + "_Counter"); Monitors.registerObject(monitorId, this); }
protected HttpClientListener(String monitorId) { super(monitorId); requestBacklog = newLongGauge("requestBacklog"); inflightRequests = newLongGauge("inflightRequests"); requestWriteTimes = newTimer("requestWriteTimes"); responseReadTimes = newTimer("responseReadTimes"); processedRequests = newCounter("processedRequests"); requestWriteFailed = newCounter("requestWriteFailed"); failedResponses = newCounter("failedResponses"); failedContentSource = newCounter("failedContentSource"); requestProcessingTimes = newTimer("requestProcessingTimes"); }
public static DistributionSummary getDistributionSummary(String name, String appName, String serverGroup) { final String metricName = getMetricName(appName, serverGroup, name); final DistributionSummary _ds = distributionSummaryMap.get(metricName); if(_ds != null) return _ds; final Registry registry = Spectator.globalRegistry(); //_poolManager.getRegistry(); if (registry != null) { Id id = registry.createId(name); id = id.withTag("owner", "evcache"); id = id.withTag("APP", appName); if(serverGroup != null) id = id.withTag("ServerGroup", serverGroup); final DistributionSummary ds = registry.distributionSummary(id); if (!Monitors.isObjectRegistered(ds)) Monitors.registerObject(ds); distributionSummaryMap.put(metricName, ds); return ds; } return null; }
@Override public void shutdown() { if(Monitors.isObjectRegistered(name, this)) { Monitors.unregisterObject(name, this); } TransportUtils.shutdown(eurekaHttpClientRef.getAndSet(null)); }
/** * Unregister an object from the default registry. Equivalent to * {@code DefaultMonitorRegistry.getInstance().unregister(Monitors.newObjectMonitor(obj))}. * * @param obj Previously registered using {@code Monitors.registerObject(obj)} */ public static void unregisterObject(Object obj) { unregisterObject(null, obj); }
/** * Creates a new monitor for a cache with standard metrics for the hits, misses, and loads. * * @param id id to differentiate metrics for this cache from others. * @param cache cache instance to monitor. * @return composite monitor based on stats provided for the cache */ public static CompositeMonitor<?> newCacheMonitor(String id, Cache<?, ?> cache) { return newObjectMonitor(id, new MonitoredCache(cache)); }
@Test public void testBasic() throws Exception { MonitorRegistry registry = new BasicMonitorRegistry(); registry.register(Monitors.newCounter("test")); MetricPoller poller = new MonitorRegistryMetricPoller(registry); Metric metric = poller.poll(MATCH_ALL).get(0); MonitorConfig expected = MonitorConfig.builder("test") .withTag(DataSourceType.COUNTER) .build(); assertEquals(metric.getConfig(), expected); }