use of io.temporal.samples.metrics.activities.MetricsActivitiesImpl in project samples-java by temporalio.
the class MetricsWorker method main.
public static void main(String[] args) {
// Set up prometheus registry and stats reported
PrometheusMeterRegistry registry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
// Set up a new scope, report every 1 second
Scope scope = new RootScopeBuilder().tags(ImmutableMap.of("workerCustomTag1", "workerCustomTag1Value", "workerCustomTag2", "workerCustomTag2Value")).reporter(new MicrometerClientStatsReporter(registry)).reportEvery(com.uber.m3.util.Duration.ofSeconds(1));
// Start the prometheus scrape endpoint
HttpServer scrapeEndpoint = MetricsUtils.startPrometheusScrapeEndpoint(registry, 8080);
// Stopping the worker will stop the http server that exposes the
// scrape endpoint.
Runtime.getRuntime().addShutdownHook(new Thread(() -> scrapeEndpoint.stop(1)));
// Add metrics scope to workflow service stub options
WorkflowServiceStubsOptions stubOptions = WorkflowServiceStubsOptions.newBuilder().setMetricsScope(scope).build();
WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(stubOptions);
WorkflowClient client = WorkflowClient.newInstance(service);
WorkerFactory factory = WorkerFactory.newInstance(client);
Worker worker = factory.newWorker(DEFAULT_TASK_QUEUE_NAME);
worker.registerWorkflowImplementationTypes(MetricsWorkflowImpl.class);
worker.registerActivitiesImplementations(new MetricsActivitiesImpl());
factory.start();
System.out.println("Workers metrics are available at http://localhost:8080/prometheus");
}
Aggregations