io.opencensus.contrib.zpages.ZPageHandlers Java Examples
The following examples show how to use
io.opencensus.contrib.zpages.ZPageHandlers.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Poller.java From spanner-event-exporter with Apache License 2.0 | 6 votes |
private void configureTracing() { try { // Installs a handler for /tracez page. ZPageHandlers.startHttpServerAndRegisterAll(8080); // Installs an exporter for stack driver traces. StackdriverExporter.createAndRegister(); Tracing.getExportComponent() .getSampledSpanStore() .registerSpanNamesForCollection(Arrays.asList(SAMPLE_SPAN)); // Installs an exporter for stack driver stats. StackdriverStatsExporter.createAndRegister(); RpcViews.registerAllCumulativeViews(); } catch (IOException e) { log.error("Could not start the tracing server", e); } }
Example #2
Source File: HelloWorldServer.java From opencensus-java with Apache License 2.0 | 5 votes |
/** Main launches the server from the command line. */ public static void main(String[] args) throws IOException, InterruptedException { // Add final keyword to pass checkStyle. final int serverPort = getPortOrDefaultFromArgs(args, 0, 50051); final String cloudProjectId = getStringOrDefaultFromArgs(args, 1, null); final int zPagePort = getPortOrDefaultFromArgs(args, 2, 3000); final int prometheusPort = getPortOrDefaultFromArgs(args, 3, 9090); // Registers all RPC views. For demonstration all views are registered. You may want to // start with registering basic views and register other views as needed for your application. RpcViews.registerAllViews(); // Registers logging trace exporter. LoggingTraceExporter.register(); // Starts a HTTP server and registers all Zpages to it. ZPageHandlers.startHttpServerAndRegisterAll(zPagePort); logger.info("ZPages server starts at localhost:" + zPagePort); // Registers Stackdriver exporters. if (cloudProjectId != null) { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder().setProjectId(cloudProjectId).build()); StackdriverStatsExporter.createAndRegister( StackdriverStatsConfiguration.builder() .setProjectId(cloudProjectId) .setExportInterval(Duration.create(60, 0)) .build()); } // Register Prometheus exporters and export metrics to a Prometheus HTTPServer. PrometheusStatsCollector.createAndRegister(); HTTPServer prometheusServer = new HTTPServer(prometheusPort, true); // Start the RPC server. You shouldn't see any output from gRPC before this. logger.info("gRPC starting."); final HelloWorldServer server = new HelloWorldServer(serverPort); server.start(); server.blockUntilShutdown(); }
Example #3
Source File: ZPagesTester.java From opencensus-java with Apache License 2.0 | 4 votes |
/** Main method. */ public static void main(String[] args) throws Exception { ZPageHandlers.startHttpServerAndRegisterAll(8080); recordExampleData(); }
Example #4
Source File: HelloWorldClient.java From opencensus-java with Apache License 2.0 | 4 votes |
/** * Greet server. If provided, the first element of {@code args} is the name to use in the * greeting. */ public static void main(String[] args) throws IOException, InterruptedException { // Add final keyword to pass checkStyle. final String user = getStringOrDefaultFromArgs(args, 0, "world"); final String host = getStringOrDefaultFromArgs(args, 1, "localhost"); final int serverPort = getPortOrDefaultFromArgs(args, 2, 50051); final String cloudProjectId = getStringOrDefaultFromArgs(args, 3, null); final int zPagePort = getPortOrDefaultFromArgs(args, 4, 3001); // Registers all RPC views. For demonstration all views are registered. You may want to // start with registering basic views and register other views as needed for your application. RpcViews.registerAllViews(); // Starts a HTTP server and registers all Zpages to it. ZPageHandlers.startHttpServerAndRegisterAll(zPagePort); logger.info("ZPages server starts at localhost:" + zPagePort); // Registers logging trace exporter. LoggingTraceExporter.register(); // Registers Stackdriver exporters. if (cloudProjectId != null) { StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder().setProjectId(cloudProjectId).build()); StackdriverStatsExporter.createAndRegister( StackdriverStatsConfiguration.builder() .setProjectId(cloudProjectId) .setExportInterval(Duration.create(60, 0)) .build()); } // Register Prometheus exporters and export metrics to a Prometheus HTTPServer. PrometheusStatsCollector.createAndRegister(); HelloWorldClient client = new HelloWorldClient(host, serverPort); try { client.greet(user); } finally { client.shutdown(); } logger.info("Client sleeping, ^C to exit. Meanwhile you can view stats and spans on zpages."); while (true) { try { Thread.sleep(10000); } catch (InterruptedException e) { logger.info("Exiting HelloWorldClient..."); } } }
Example #5
Source File: HeroicCore.java From heroic with Apache License 2.0 | 4 votes |
private void enableTracing(TracingConfig config) throws IOException { final TracingConfig.Lightstep lightstep = config.getLightstep(); if (!lightstep.getCollectorHost().isBlank()) { final Options.OptionsBuilder optionsBuilder = new Options.OptionsBuilder() .withAccessToken(lightstep.getAccessToken()) .withMaxReportingIntervalMillis(lightstep.getReportingIntervalMs()) .withMaxBufferedSpans(lightstep.getMaxBufferedSpans()) .withCollectorProtocol("http") .withResetClient(lightstep.getResetClient()) .withComponentName(lightstep.getComponentName()) .withCollectorHost(lightstep.getCollectorHost()) .withCollectorPort(lightstep.getCollectorPort()); final Options options; try { options = optionsBuilder.build(); } catch (MalformedURLException e) { throw new IllegalArgumentException("Malformed configuration for LightStep.", e); } log.info("Creating LightStep tracing exporter"); LightStepExporterHandler handler = new LightStepExporterHandler(new JRETracer(options)); log.info("Registering LightStep exporter as the SquashingTraceExporter delegate"); SquashingTraceExporter.createAndRegister( handler, config.getSquash().getThreshold(), config.getSquash().getWhitelist() ); log.info("Setting global trace probability to {}", config.getProbability()); TraceConfig traceConfig = Tracing.getTraceConfig(); traceConfig.updateActiveTraceParams( traceConfig .getActiveTraceParams() .toBuilder() .setSampler(Samplers.probabilitySampler(config.getProbability())) .build()); } if (config.getZpagesPort() > 0) { log.info("Starting zpage handlers on port {}", config.getZpagesPort()); // Start a web server for tracing data ZPageHandlers.startHttpServerAndRegisterAll(config.getZpagesPort()); } }
Example #6
Source File: TracingSample.java From java-docs-samples with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { if (args.length != 2) { System.err.println("Usage: TracingSample <instance_id> <database_id>"); return; } SpannerOptions options = SpannerOptions.newBuilder().build(); Spanner spanner = options.getService(); // Installs a handler for /tracez page. ZPageHandlers.startHttpServerAndRegisterAll(8080); // Installs an exporter for stack driver traces. StackdriverExporter.createAndRegister(); Tracing.getExportComponent() .getSampledSpanStore() .registerSpanNamesForCollection(Arrays.asList(SAMPLE_SPAN)); // Installs an exporter for stack driver stats. StackdriverStatsExporter.createAndRegister(); RpcViews.registerAllCumulativeViews(); // Name of your instance & database. String instanceId = args[0]; String databaseId = args[1]; try { // Creates a database client DatabaseClient dbClient = spanner.getDatabaseClient(DatabaseId.of(options.getProjectId(), instanceId, databaseId)); // Queries the database try (Scope ss = Tracing.getTracer() .spanBuilderWithExplicitParent(SAMPLE_SPAN, null) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) { ResultSet resultSet = dbClient.singleUse().executeQuery(Statement.of("SELECT 1")); System.out.println("\n\nResults:"); // Prints the results while (resultSet.next()) { System.out.printf("%d\n\n", resultSet.getLong(0)); } } } finally { // Closes the client which will free up the resources used spanner.close(); } }
Example #7
Source File: HelloWorld.java From cloud-bigtable-examples with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws IOException, InterruptedException { // Consult system properties to get project/instance String projectId = requiredProperty("bigtable.projectID"); String instanceId = requiredProperty("bigtable.instanceID"); try { // Force tracing for every request for demo purposes. Use the default settings // in most cases. Tracing.getTraceConfig().updateActiveTraceParams( TraceParams.DEFAULT.toBuilder().setSampler(Samplers.probabilitySampler(1)).build()); StackdriverTraceExporter.createAndRegister( StackdriverTraceConfiguration.builder() .setProjectId(projectId) .build()); // Enable stats exporter to Stackdriver with a 5 second export time. // Production settings may vary. StackdriverStatsExporter.createAndRegister( StackdriverStatsConfiguration.builder() .setProjectId(projectId) .setExportInterval(Duration.create(5, 0)) .build()); RpcViews.registerAllGrpcViews(); // HBase Bigtable specific setup for zpages HBaseTracingUtilities.setupTracingConfig(); // Start a web server on port 8080 for tracing data ZPageHandlers.startHttpServerAndRegisterAll(8080); doHelloWorld(projectId, instanceId); } finally { System.out.println("Sleeping for 1 minute so that you can view http://localhost:8080/tracez"); // Sleep for 1 minute. TimeUnit.MINUTES.sleep(1); // Terminating this program manually as Http-server prevents it from auto shutdown System.exit(0); } }