Java Code Examples for io.prometheus.client.exporter.common.TextFormat#CONTENT_TYPE_004
The following examples show how to use
io.prometheus.client.exporter.common.TextFormat#CONTENT_TYPE_004 .
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: PrometheusScrapeEndpointController.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
@RequestMapping( value = "/metrics", method = RequestMethod.GET, produces = TextFormat.CONTENT_TYPE_004 ) @ResponseBody public String scrape() { try { Writer writer = new StringWriter(); TextFormat.write004( writer, this.collectorRegistry.metricFamilySamples() ); return writer.toString(); } catch ( IOException ex ) { // This never happens since StringWriter::write() doesn't throw IOException throw new UncheckedIOException( "Writing metrics failed", ex ); } }
Example 2
Source File: SingleTargetMetricsEndpoint.java From promregator with Apache License 2.0 | 5 votes |
@GetMapping(produces=TextFormat.CONTENT_TYPE_004) public ResponseEntity<String> getMetrics( @PathVariable String applicationId, @PathVariable String instanceNumber ) { if (this.isLoopbackRequest()) { throw new LoopbackScrapingDetectedException("Erroneous Loopback Scraping request detected"); } String instanceId = String.format("%s:%s", applicationId, instanceNumber); String response = null; try { response = this.handleRequest( discoveredApplicationId -> applicationId.equals(discoveredApplicationId) , requestInstance -> { if (requestInstance.getInstanceId().equals(instanceId)) { this.instance = requestInstance; return true; } return false; }); } catch (ScrapingException e) { return new ResponseEntity<>(e.toString(), HttpStatus.NOT_FOUND); } return new ResponseEntity<>(response, HttpStatus.OK); }
Example 3
Source File: PromregatorMetricsEndpoint.java From promregator with Apache License 2.0 | 5 votes |
@GetMapping(produces=TextFormat.CONTENT_TYPE_004) public String getMetrics() { HashMap<String, MetricFamilySamples> mfsMap = this.gmfspr.determineEnumerationOfMetricFamilySamples(this.collectorRegistry); MergableMetricFamilySamples mmfs = new MergableMetricFamilySamples(); mmfs.merge(mfsMap); return mmfs.toType004String(); }
Example 4
Source File: MetricsEndpoint.java From promregator with Apache License 2.0 | 5 votes |
@GetMapping(produces=TextFormat.CONTENT_TYPE_004) public ResponseEntity<String> getMetrics() { if (this.isLoopbackRequest()) { throw new LoopbackScrapingDetectedException("Erroneous Loopback Scraping request detected"); } try { String result = this.handleRequest(null, null /* no filtering intended */); return new ResponseEntity<>(result, HttpStatus.OK); } catch (ScrapingException e) { return new ResponseEntity<>(e.toString(), HttpStatus.SERVICE_UNAVAILABLE); } }
Example 5
Source File: MetricsController.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@GetMapping(value = "metrics", produces = TextFormat.CONTENT_TYPE_004) public ResponseEntity<String> metrics(@RequestParam(name = "name[]", required = false) String[] includedParam) throws IOException { Set<String> params = includedParam == null ? Collections.emptySet() : new HashSet<>(Arrays.asList(includedParam)); try (Writer writer = new StringWriter()) { TextFormat.write004(writer, this.registry.filteredMetricFamilySamples(params)); writer.flush(); return new ResponseEntity<>(writer.toString(), HttpStatus.OK); } }
Example 6
Source File: MetricsResource.java From graylog-plugin-metrics-reporter with GNU General Public License v3.0 | 5 votes |
@GET @Produces(TextFormat.CONTENT_TYPE_004) @ApiOperation("Provide internal Graylog metrics in Prometheus metrics format") public Response prometheusMetrics() { final StreamingOutput stream = os -> { try (final OutputStreamWriter outputStreamWriter = new OutputStreamWriter(os); final Writer writer = new BufferedWriter(outputStreamWriter)) { TextFormat.write004(writer, collectorRegistry.metricFamilySamples()); writer.flush(); } }; return Response.ok(stream) .type(TextFormat.CONTENT_TYPE_004) .build(); }
Example 7
Source File: PrometheusMetricsController.java From Lavalink with MIT License | 4 votes |
@GetMapping(produces = TextFormat.CONTENT_TYPE_004) public ResponseEntity<String> getMetrics(@Nullable @RequestParam(name = "name[]", required = false) String[] includedParam) throws IOException { return buildAnswer(includedParam); }