下面列出了com.codahale.metrics.jmx.JmxReporter#start ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void setupJMXReporter(Bus b, MetricRegistry reg) {
InstrumentationManager im = b.getExtension(InstrumentationManager.class);
if (im != null) {
JmxReporter reporter = JmxReporter.forRegistry(reg).registerWith(im.getMBeanServer())
.inDomain("org.apache.cxf")
.createsObjectNamesWith(new ObjectNameFactory() {
public ObjectName createName(String type, String domain, String name) {
try {
return new ObjectName(name);
} catch (MalformedObjectNameException e) {
throw new RuntimeException(e);
}
}
})
.build();
reporter.start();
}
}
public static void main(String args[]) throws Exception {
VerifiableProperties verifiableProperties = ToolUtils.getVerifiableProperties(args);
MetricRegistry registry = new MetricRegistry();
StoreToolsMetrics metrics = new StoreToolsMetrics(registry);
JmxReporter reporter = null;
try {
reporter = JmxReporter.forRegistry(registry).build();
reporter.start();
DumpDataTool dumpDataTool = new DumpDataTool(verifiableProperties, metrics);
dumpDataTool.doOperation();
} finally {
if (reporter != null) {
reporter.stop();
}
}
}
public static void main(String args[]) throws Exception {
VerifiableProperties verifiableProperties = ToolUtils.getVerifiableProperties(args);
MetricRegistry registry = new MetricRegistry();
StoreToolsMetrics metrics = new StoreToolsMetrics(registry);
JmxReporter reporter = null;
try {
reporter = JmxReporter.forRegistry(registry).build();
reporter.start();
DumpLogTool dumpLogTool = new DumpLogTool(verifiableProperties, metrics);
dumpLogTool.doOperation();
} finally {
if (reporter != null) {
reporter.stop();
}
}
}
private static JmxReporter getJmxReporter() {
if (METRICS_JMX_OUTPUT_ENABLED) {
JmxReporter reporter = JmxReporter.forRegistry(REGISTRY).build();
reporter.start();
return reporter;
}
return null;
}
public InjectionModule(ServiceProperties serviceProperties) {
this.serviceProperties = serviceProperties;
metricRegistry = new MetricRegistry();
JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).build();
reporter.start();
httpClient = createHttpClient();
}
@Override
protected JmxReporter getReporter(Map<String, Object> configuration, MetricRegistry registry) {
JmxReporter reporter = JmxReporter.forRegistry(registry).build();
reporter.start();
return reporter;
}
public ApplicationState(ApplicationConfig config, XioTracing tracing) {
this.config = config;
this.tracing = tracing;
this.metricRegistry = new MetricRegistry();
JmxReporter jmxReporter = JmxReporter.forRegistry(metricRegistry).build();
jmxReporter.start();
this.channelConfiguration = config.serverChannelConfig();
this.ipFilterConfig = new AtomicReference<>(new IpFilterConfig());
this.http1FilterConfig = new AtomicReference<>(new Http1FilterConfig());
}
private void start(String[] args) throws Exception {
this.initialize();
applicationContext = SpringApplication.run(SpringConfig.class, args);
ApplicationHolder.applicationContext = applicationContext;
int port = Integer.parseInt(Configuration.getProperty(Dict.PROPERTY_SERVER_PORT));
//TODO: Server custom configuration
int processors = Runtime.getRuntime().availableProcessors();
Integer corePoolSize = Configuration.getPropertyInt("serving.core.pool.size", processors);
Integer maxPoolSize = Configuration.getPropertyInt("serving.max.pool.size", processors * 2);
Integer aliveTime = Configuration.getPropertyInt("serving.pool.alive.time", 1000);
Integer queueSize = Configuration.getPropertyInt("serving.pool.queue.size", 10);
Executor executor = new ThreadPoolExecutor(corePoolSize, maxPoolSize, aliveTime.longValue(), TimeUnit.MILLISECONDS,
new SynchronousQueue(), new NamedThreadFactory("ServingServer", true));
FateServerBuilder serverBuilder = (FateServerBuilder) ServerBuilder.forPort(port);
serverBuilder.keepAliveTime(100,TimeUnit.MILLISECONDS);
serverBuilder.executor(executor);
//new ServiceOverloadProtectionHandle()
serverBuilder.addService(ServerInterceptors.intercept(applicationContext.getBean(InferenceService.class), new ServiceExceptionHandler(), new ServiceOverloadProtectionHandle()), InferenceService.class);
serverBuilder.addService(ServerInterceptors.intercept(applicationContext.getBean(ModelService.class), new ServiceExceptionHandler(), new ServiceOverloadProtectionHandle()), ModelService.class);
serverBuilder.addService(ServerInterceptors.intercept(applicationContext.getBean(ProxyService.class), new ServiceExceptionHandler(), new ServiceOverloadProtectionHandle()), ProxyService.class);
server = serverBuilder.build();
logger.info("server started listening on port: {}, use configuration: {}", port, this.confPath);
server.start();
String userRegisterString = Configuration.getProperty(Dict.USE_REGISTER,"true");
useRegister = Boolean.valueOf(userRegisterString);
if(useRegister) {
logger.info("serving-server is using register center");
}
else{
logger.warn("serving-server not use register center");
}
if (useRegister) {
ZookeeperRegistry zookeeperRegistry = applicationContext.getBean(ZookeeperRegistry.class);
zookeeperRegistry.subProject(Dict.PROPERTY_PROXY_ADDRESS);
zookeeperRegistry.subProject(Dict.PROPERTY_FLOW_ADDRESS);
BaseModel.routerService = applicationContext.getBean(RouterService.class);
FateServer.serviceSets.forEach(servie -> {
try {
String serviceName = servie.serviceName();
String weightKey = serviceName + ".weight";
HashMap properties = Configuration.getProperties();
if (properties.get(weightKey) != null) {
int weight = Integer.valueOf(properties.get(weightKey).toString());
if (weight > 0) {
zookeeperRegistry.getServieWeightMap().put(weightKey, weight);
}
}
} catch (Throwable e) {
logger.error("parse interface weight error", e);
}
});
zookeeperRegistry.register(FateServer.serviceSets);
}
ModelService modelService = applicationContext.getBean(ModelService.class);
modelService.restore();
ConsoleReporter reporter = applicationContext.getBean(ConsoleReporter.class);
reporter.start(1, TimeUnit.MINUTES);
JmxReporter jmxReporter = applicationContext.getBean(JmxReporter.class);
jmxReporter.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
logger.info("*** shutting down gRPC server since JVM is shutting down");
ServingServer.this.stop();
logger.info("*** server shut down");
}
});
}
@Bean(destroyMethod = "stop")
public JmxReporter jmxReporter() {
JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).build();
reporter.start();
return reporter;
}
private void startJmxReporter() {
JmxReporter reporter = JmxReporter.forRegistry(registry).build();
reporter.start();
}
private void startJmxReporter() {
JmxReporter reporter = JmxReporter.forRegistry(registry).build();
reporter.start();
}