com.alipay.lookout.api.Lookout Java Examples
The following examples show how to use
com.alipay.lookout.api.Lookout.
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: RestLookoutTest.java From sofa-rpc with Apache License 2.0 | 6 votes |
@BeforeClass public static void beforeCurrentClass() { RpcRunningState.setUnitTestMode(false); Registry registry = new DefaultRegistry(); final Registry currentRegistry = Lookout.registry(); if (currentRegistry == NoopRegistry.INSTANCE) { Lookout.setRegistry(registry); } // 只有1个线程 执行 serverConfig = new ServerConfig() .setStopTimeout(1000) .setPort(8802) .setProtocol(RpcConstants.PROTOCOL_TYPE_REST) .setContextPath("/xyz"); //.setQueues(100).setCoreThreads(1).setMaxThreads(2); }
Example #2
Source File: RpcLookoutId.java From sofa-rpc with Apache License 2.0 | 5 votes |
private Id fetchServerConfigId(String key) { Id lookoutId = serverConfigIds.get(key); if (lookoutId == null) { synchronized (RpcLookout.class) { lookoutId = serverConfigIds.get(key); if (lookoutId == null) { lookoutId = Lookout.registry().createId(key); serverConfigIds.put(key, lookoutId); } } } return lookoutId; }
Example #3
Source File: RestLookoutTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
private Metric fetchWithName(String name) { for (Metric metric : Lookout.registry()) { if (metric.id().name().equalsIgnoreCase(name)) { return metric; } } return null; }
Example #4
Source File: RpcLookoutTest.java From sofa-rpc with Apache License 2.0 | 5 votes |
private Metric fetchWithName(String name) { for (Metric metric : Lookout.registry()) { if (metric.id().name().equalsIgnoreCase(name)) { return metric; } } return null; }
Example #5
Source File: RpcLookout.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * Collect the RPC client information. * * @param consumerConfig client information model */ public void collectConsumerSubInfo(final ConsumerConfig consumerConfig) { try { Id consumerConfigId = rpcLookoutId.fetchConsumerSubId(); Lookout.registry().info(consumerConfigId, new Info<ConsumerConfig>() { @Override public ConsumerConfig value() { return consumerConfig; } }); } catch (Throwable t) { LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t); } }
Example #6
Source File: RpcLookout.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * Collect the RPC client information. * * @param providerConfig client information model */ public void collectProvderPubInfo(final ProviderConfig providerConfig) { try { Id providerConfigId = rpcLookoutId.fetchProviderPubId(); Lookout.registry().info(providerConfigId, new Info<ProviderConfig>() { @Override public ProviderConfig value() { return providerConfig; } }); } catch (Throwable t) { LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t); } }
Example #7
Source File: RpcLookout.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * remove the thread pool information * * @param serverConfig server config */ public void removeThreadPool(ServerConfig serverConfig) { Lookout.registry().removeMetric(rpcLookoutId.removeServerThreadConfigId(serverConfig)); Lookout.registry().removeMetric(rpcLookoutId.removeServerThreadPoolActiveCountId(serverConfig)); Lookout.registry().removeMetric(rpcLookoutId.removeServerThreadPoolIdleCountId(serverConfig)); Lookout.registry().removeMetric(rpcLookoutId.removeServerThreadPoolQueueSizeId(serverConfig)); }
Example #8
Source File: RpcLookout.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * Collect the RPC server information. * * @param rpcServerMetricsModel server information model */ public void collectServer(RpcServerLookoutModel rpcServerMetricsModel) { try { Id methodProviderId = createMethodProviderId(rpcServerMetricsModel); MixinMetric methodProviderMetric = Lookout.registry().mixinMetric(methodProviderId); recordCounterAndTimer(methodProviderMetric, rpcServerMetricsModel); } catch (Throwable t) { LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t); } }
Example #9
Source File: RpcLookout.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * Collect the RPC client information. * * @param rpcClientMetricsModel client information model */ public void collectClient(RpcClientLookoutModel rpcClientMetricsModel) { try { Id methodConsumerId = createMethodConsumerId(rpcClientMetricsModel); MixinMetric methodConsumerMetric = Lookout.registry().mixinMetric(methodConsumerId); recordCounterAndTimer(methodConsumerMetric, rpcClientMetricsModel); recordSize(methodConsumerMetric, rpcClientMetricsModel); } catch (Throwable t) { LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t); } }
Example #10
Source File: RpcLookoutId.java From sofa-rpc with Apache License 2.0 | 5 votes |
public Id fetchProviderPubId() { if (providerConfigId == null) { synchronized (providerConfigIdLock) { if (providerConfigId == null) { providerConfigId = Lookout.registry().createId("rpc.provider.info.stats"); } } } return providerConfigId; }
Example #11
Source File: RpcLookoutId.java From sofa-rpc with Apache License 2.0 | 5 votes |
public Id fetchConsumerSubId() { if (consumerConfigId == null) { synchronized (consumerConfigIdLock) { if (consumerConfigId == null) { consumerConfigId = Lookout.registry().createId("rpc.consumer.info.stats"); } } } return consumerConfigId; }
Example #12
Source File: RpcLookoutId.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * Create ProviderId * * @return ProviderId */ public Id fetchProviderStatId() { if (providerId == null) { synchronized (providerIdLock) { if (providerId == null) { providerId = Lookout.registry().createId("rpc.provider.service.stats"); } } } return providerId; }
Example #13
Source File: RpcLookoutId.java From sofa-rpc with Apache License 2.0 | 5 votes |
/** * create consumerId * * @return consumerId */ public Id fetchConsumerStatId() { if (consumerId == null) { synchronized (consumerIdLock) { if (consumerId == null) { consumerId = Lookout.registry().createId("rpc.consumer.service.stats"); } } } return consumerId; }
Example #14
Source File: DefaultHttpRequestProcessor.java From sofa-lookout with Apache License 2.0 | 5 votes |
@Override public boolean sendPostRequest(final HttpPost httpPost, Map<String, String> metadata) throws IOException { if (metadata != null && PRIORITY.LOW.name().equalsIgnoreCase(metadata.get(PRIORITY_NAME)) && clearIdleConnectionsTask != null) { clearIdleConnectionsTask.run(); } addCommonHeaders(httpPost, metadata); httpPost.setConfig(reqConf); try { return sendRequest(httpPost, new ResponseHandler<Boolean>() { @Override public Boolean handleResponse(HttpResponse response) throws IOException { try { if (200 != response.getStatusLine().getStatusCode()) { refreshAddressCache(); handleErrorResponse(response, httpPost); Registry r = Lookout.registry(); r.counter( r.createId(LOOKOUT_REPORT_FAIL_COUNT_ID).withTag(LOW_PRIORITY_TAG)) .inc(); return false; } else {//success logger.debug("report to lookout gateway ok.{}", httpPost.toString()); } } finally { EntityUtils.consumeQuietly(response.getEntity()); } return true; } }); } catch (IOException e) { //try with a new address refreshAddressCache(); throw e; } }
Example #15
Source File: SimpleLookoutClientTest.java From sofa-lookout with Apache License 2.0 | 5 votes |
@BeforeClass public static void init() throws NoSuchFieldException, IllegalAccessException { Field field = Lookout.class.getDeclaredField("atomicRegistryReference"); field.setAccessible(true); AtomicReference<Registry> atomicRegistryReference = (AtomicReference<Registry>) field .get(null); atomicRegistryReference.set(NoopRegistry.INSTANCE); }
Example #16
Source File: DefaultLookoutClient.java From sofa-lookout with Apache License 2.0 | 5 votes |
public DefaultLookoutClient(String appName) { super(appName); try { Lookout.setRegistry(getInnerCompositeRegistry()); } catch (IllegalStateException e) { logger.warn("global registry is already set!" + e.getMessage()); } }
Example #17
Source File: SimpleLookoutClient.java From sofa-lookout with Apache License 2.0 | 4 votes |
/** * all registries will be reset with the same lookout config * * @param appName app name * @param config lookout config, * @param registries */ public SimpleLookoutClient(String appName, LookoutConfig config, MetricRegistry... registries) { super(appName); if (!state.compareAndSet(0, 1)) { throw new IllegalStateException("support only one lookout client instance now!"); } lookoutConfig = config != null ? config : new LookoutConfig(); registries = registries.length > 0 ? registries : new MetricRegistry[] { new LookoutRegistry(lookoutConfig) }; lookoutConfig.setProperty(LookoutConfig.APP_NAME, appName); if (!lookoutConfig.getBoolean(LookoutConfig.LOOKOUT_ENABLE, true)) { return; } for (MetricRegistry registry : registries) { if (registry instanceof AbstractRegistry && ((AbstractRegistry) registry).getConfig() != lookoutConfig) { // reset with the same configuration ((AbstractRegistry) registry).setConfig(lookoutConfig); } //add jvm and other metrics registry.registerExtendedMetrics(); super.addRegistry(registry); if (registry instanceof LookoutRegistry) { if (!lookoutConfig.getBoolean(LOOKOUT_EXPORTER_ENABLE, false)) { return; } try { setMetricsHttpExporter(PollerUtils.exportHttp((LookoutRegistry) registry)); } catch (Exception e) { logger.error("fail to start MetricsHttpExporter", e); } } } logger.debug("set global registry to Lookout"); // init global registry Lookout.setRegistry(getRegistry()); }
Example #18
Source File: RpcLookout.java From sofa-rpc with Apache License 2.0 | 4 votes |
/** * Collect the thread pool information * * @param serverConfig ServerConfig * @param threadPoolExecutor ThreadPoolExecutor */ public void collectThreadPool(ServerConfig serverConfig, final ThreadPoolExecutor threadPoolExecutor) { try { int coreSize = serverConfig.getCoreThreads(); int maxSize = serverConfig.getMaxThreads(); int queueSize = serverConfig.getQueues(); final ThreadPoolConfig threadPoolConfig = new ThreadPoolConfig(coreSize, maxSize, queueSize); Lookout.registry().info(rpcLookoutId.fetchServerThreadConfigId(serverConfig), new Info<ThreadPoolConfig>() { @Override public ThreadPoolConfig value() { return threadPoolConfig; } }); Lookout.registry().gauge(rpcLookoutId.fetchServerThreadPoolActiveCountId(serverConfig), new Gauge<Integer>() { @Override public Integer value() { return threadPoolExecutor.getActiveCount(); } }); Lookout.registry().gauge(rpcLookoutId.fetchServerThreadPoolIdleCountId(serverConfig), new Gauge<Integer>() { @Override public Integer value() { return threadPoolExecutor.getPoolSize() - threadPoolExecutor.getActiveCount(); } }); Lookout.registry().gauge(rpcLookoutId.fetchServerThreadPoolQueueSizeId(serverConfig), new Gauge<Integer>() { @Override public Integer value() { return threadPoolExecutor.getQueue().size(); } }); } catch (Throwable t) { LOGGER.error(LogCodes.getLog(LogCodes.ERROR_METRIC_REPORT_ERROR), t); } }
Example #19
Source File: PromQueryController.java From sofa-lookout with Apache License 2.0 | 4 votes |
private Registry registry() { return Lookout.registry(); }
Example #20
Source File: HttpObserver.java From sofa-lookout with Apache License 2.0 | 4 votes |
private Registry registry() { return reg == null ? Lookout.registry() : reg; }