Rick

Rick
Rick

Thursday, June 11, 2015

Curlable stats and health checks... for QBit

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("qbitAdminBuilder", AdminBuilder.class);
        final HealthServiceAsync healthServiceAsync = 
               qbitAdminBuilder.getHealthServiceBuilder().buildHealthSystemReporter();

        serviceBuilder.registerHealthChecksWithTTLInSeconds(qbitAdminBuilder.getHealthService(), 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("qbitStatsCollector", StatsCollector.class);

        serviceBuilder.registerStatsCollections(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"
]
[
    "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.serviceBundleBuilder().getRequestQueueBuilder();

        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

Kafka and Cassandra support, training for AWS EC2 Cassandra 3.0 Training