You can wire in stats and get a single "ok" end point for your services.
You can use AdminBuilder to create an admin utils.
final AdminBuilder adminBuilder = AdminBuilder.adminBuilder(); final ServiceEndpointServer adminServer = adminBuilder.build(); adminServer.startServer(); final HealthServiceAsync healthService = adminBuilder.getHealthService(); healthService.register("foo", 1, TimeUnit.DAYS); healthService.checkInOk("foo") ; healthService.register("bar", 1, TimeUnit.DAYS); healthService.checkInOk("bar") ;
You can also register for service queue health checks.
@Bean public AdminBuilder qbitAdminBuilder() { final int port = environment.getProperty("qbit.admin.server.port", Integer.class); final String host = environment.getProperty("qbit. admin.server.host", String.class); final AdminBuilder adminBuilder = AdminBuilder.adminBuilder() .setPort(port).setHost(host); return adminBuilder; } @Bean public ServiceEndpointServer adminServiceEndpointServer( final AdminBuilder adminBuilder) { final ServiceEndpointServer adminServer = adminBuilder.build(); adminServer.startServer(); return adminServer; } .... final Integer healthCheckTTL = env.getProperty("qbit.app. healthCheckTTLSeconds", Integer.class); ... final ServiceBuilder serviceBuilder = ServiceBuilder.serviceBuilder( ); final AdminBuilder qbitAdminBuilder = applicationContext.getBean("qb itAdminBuilder", AdminBuilder.class); final HealthServiceAsync healthServiceAsync = qbitAdminBuilder.getHealthServ iceBuilder().buildHealthSystem Reporter(); serviceBuilder.registerHealthC hecksWithTTLInSeconds( qbitAdminBuilder.getHealthServ ice(), longName, healthCheckTTL == null ? 5 : healthCheckTTL); ....
You can also register for stats health checks (stats system has a statsd replicator so you can replicate stats to statsD)
final ServiceBuilder serviceBuilder = ServiceBuilder.serviceBuilder(); ... final StatsCollector statsCollector = applicationContext.getBean("qb itStatsCollector", StatsCollector.class); serviceBuilder.registerStatsCo llections(longName, statsCollector, flushTimeSeconds, sampleEvery );
Once you do this, then you can query for health status.
Returns true if all internal service queues are running. Returns false if any are failing.
Returns list of nodes healthy or not:
[ "api.proxy.unpackerService", "api.proxy.healthService", "api.proxy.forwarderService", "api.proxy.bouncerService" ]
Only return healthy nodes: curl http://localhost:6001/ services/qbit-admin/healthy- nodes
[ "api.proxy.unpackerService", "api.proxy.healthService", "api.proxy.forwarderService", "api.proxy.bouncerService" ]
Return extended stats
[ { "name": "api.proxy.unpackerService", "ttlInMS": 10000, "lastCheckIn": 1434003690275, "status": "PASS" }, { "name": "api.proxy.healthService", "ttlInMS": 10000, "lastCheckIn": 1434003690275, "status": "PASS" }, { "name": "api.proxy.forwarderService", "ttlInMS": 10000, "lastCheckIn": 1434003690275, "status": "PASS" }, { "name": "api.proxy.bouncerService", "ttlInMS": 10000, "lastCheckIn": 1434003690275, "status": "PASS" } ]
Registering for health checks can be done with the service bundle builder and the service endpoint server builder as well:
final ServiceBundleBuilder.serviceBundleBuilder = ServiceBundleBuilder.serviceBu ndleBuilder().getRequestQueueB uilder(); final ServiceBundle serviceBundle = serviceBundleBuilder .setStatsCollector( statsCollector) .build(); serviceBundle.start(); serviceBundle.addService(new MyService());
Every service added to the bundle will get stats support.
No comments:
Post a Comment