mathieucarbou / megatron

Megatron library sends Terracotta statistics and notifications to a management backend through REST, StatsD and other means
http://oss.carbou.me/megatron/
Apache License 2.0
0 stars 2 forks source link

Megatron plugin to export prometheus servlet #30

Open mathieucarbou opened 6 years ago

mathieucarbou commented 6 years ago

See: https://github.com/prometheus/client_java#http

Keeping latest stats and doing something like REST plugin

        Server server = new Server(1234);
        ServletContextHandler context = new ServletContextHandler();
        context.setContextPath("/");
        server.setHandler(context);

        Collector megatronBridge = new Collector() {
            @Override
            public List<MetricFamilySamples> collect() {
                return singletonList(new MetricFamilySamples(
                    "stat_name",
                    Type.GAUGE,
                    "",
                    singletonList(new MetricFamilySamples.Sample("stat_name", tagsNames, tagValues, 1234))));
            }
        };

        CollectorRegistry registry = new CollectorRegistry();
        registry.register(megatronBridge);
        webserver.addServlet(new MetricsServlet(registry), "/metrics");