Java Code Examples for com.alipay.lookout.api.Lookout#setRegistry()

The following examples show how to use com.alipay.lookout.api.Lookout#setRegistry() . 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 vote down vote up
@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: DefaultLookoutClient.java    From sofa-lookout with Apache License 2.0 5 votes vote down vote up
public DefaultLookoutClient(String appName) {
    super(appName);
    try {
        Lookout.setRegistry(getInnerCompositeRegistry());
    } catch (IllegalStateException e) {
        logger.warn("global registry is already set!" + e.getMessage());
    }
}
 
Example 3
Source File: SimpleLookoutClient.java    From sofa-lookout with Apache License 2.0 4 votes vote down vote up
/**
 * 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());
}