use of com.uber.m3.tally.RootScopeBuilder in project samples-java by temporalio.
the class MetricsStarter 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("starterCustomTag1", "starterCustomTag1Value", "starterCustomTag2", "starterCustomTag2Value")).reporter(new MicrometerClientStatsReporter(registry)).reportEvery(com.uber.m3.util.Duration.ofSeconds(1));
// Start the prometheus scrape endpoint for starter metrics
HttpServer scrapeEndpoint = MetricsUtils.startPrometheusScrapeEndpoint(registry, 8081);
// Stopping the starter 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);
WorkflowOptions workflowOptions = WorkflowOptions.newBuilder().setWorkflowId("metricsWorkflow").setTaskQueue(MetricsWorker.DEFAULT_TASK_QUEUE_NAME).build();
MetricsWorkflow workflow = client.newWorkflowStub(MetricsWorkflow.class, workflowOptions);
String result = workflow.exec("hello metrics");
System.out.println("Result: " + result);
System.out.println("Starter metrics are available at http://localhost:8081/prometheus");
// We don't shut down the process here so metrics can be viewed.
}
use of com.uber.m3.tally.RootScopeBuilder 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