# Not able to parse prometheus metrics to json format

**URL:** <https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447>\
**Category:** Logstash\
**Created:** [February 12, 2025, 5:56pm UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447 "2025-02-12T17:56:57Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![Bhanu\_Praveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhanu_praveen/32/60395_2.png) [@Bhanu\_Praveen](https://discuss.elastic.co/u/Bhanu_Praveen)\
**Post date:** [February 13, 2025, 5:15am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/21 "2025-02-13T05:15:51Z")

</div>

Same 401 unauthorised issue after below config:

```auto
metricbeat.modules:
- module: prometheus
  period: 10s
  hosts: ["http://testserver.dev.com:42115"]
  metrics_path: "/rpsservice/actuator/prometheus?tId=e5bf6fc7-457a-406f-b2df-1a38be998f51"
  headers:
    Authorization: "Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjViOWM3N2FiLTY4OTktNDlhNC1hYzA5LWMxYzE2OWNjMGQ0NCJ9.eyJzdWIiOiJiZTUwYmZkMS1hOGQ4LTRmZjItOGQ0YS0wNTQzZDY0OWJmMjUiLCJncmFudF90eXBlIjoiY2xpZW50X2NyZWRlbnRpYWxzIiwidG9rZW5fdXNlIjpudWxsLCJzY29wZSI6IkNVU1RPTS1TQ09QRVMiLCJpc3MiOiJFVEYiLCJleHAiOjE3Mzk0MjYwMTEsImlhdCI6MTczOTQyMjQxMSwiY2xpZW50X2lkIjoiYmU1MGJmZDEtYThkOC00ZmYyLThkNGEtMDU0M2Q2NDliZjI1IiwidElkIjoiZTViZjZmYzctNDU3YS00MDZmLWIyZGYtMWEzOGJlOTk4ZjUxIiwianRpIjoiYWE0MGY5ZjYtYWMxNy00ZjMyLWFlZTAtOTk5ZjA1ZDZlN2NhIn0.NPsNP31m4x6E4FQxaPHVgvGvKlWvE671WBP2txTlUVH4X1NGBAUn7y1Po4YNa63751--"
 

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 13, 2025, 5:30am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/22 "2025-02-13T05:30:14Z")

</div>

Not sure what to tell you....

Did you run metricbeat with the -e -d "\*" and carefully inspect the output...

Is there any other meaningful output . You are not actually sharing error logs...

What version of metricbeat?

I have not encountered same issue I just set up and exporter and connected first time.. I don't have it secured.. but these are common connections options ..

Ohh try these

```auto
metricbeat test config
metricbeat test prometheus 
metricbeat test output 

```

---

<div class="post-metadata">

**Author:** ![Bhanu\_Praveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhanu_praveen/32/60395_2.png) [@Bhanu\_Praveen](https://discuss.elastic.co/u/Bhanu_Praveen)\
**Post date:** [February 13, 2025, 5:33am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/23 "2025-02-13T05:33:20Z")

</div>

> [@stephenb](#):
>
> ./metricbeat -e -d "\*"

Error Logs:

```auto
{"log.level":"debug","@timestamp":"2025-02-13T06:06:06.081+0530","log.logger":"logstash","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/outputs/logstash.(*asyncClient).Publish","file.name":"logstash/async.go","file.line":172},"message":"33 events out of 33 events sent to logstash host localhost:5044. Continue sending","service.name":"metricbeat","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2025-02-13T06:06:06.088+0530","log.logger":"publisher","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue.(*ackLoop).handleBatchSig","file.name":"memqueue/ackloop.go","file.line":80},"message":"ackloop: return ack to broker loop:33","service.name":"metricbeat","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2025-02-13T06:06:06.089+0530","log.logger":"publisher","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue.(*ackLoop).handleBatchSig","file.name":"memqueue/ackloop.go","file.line":82},"message":"ackloop: done send ack","service.name":"metricbeat","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2025-02-13T06:06:12.022+0530","log.logger":"prometheus.collector","log.origin":{"function":"github.com/elastic/beats/v7/metricbeat/helper/prometheus.(*prometheus).GetFamilies","file.name":"prometheus/prometheus.go","file.line":105},"message":"error received from prometheus endpoint: ","service.name":"metricbeat","ecs.version":"1.6.0"}
{"log.level":"error","@timestamp":"2025-02-13T06:06:12.023+0530","log.origin":{"function":"github.com/elastic/beats/v7/metricbeat/mb/module.(*metricSetWrapper).handleFetchError","file.name":"module/wrapper.go","file.line":333},"message":"Error fetching data for metricset prometheus.collector: unable to decode response from prometheus endpoint: unexpected status code 401 from server","service.name":"metricbeat","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2025-02-13T06:06:16.082+0530","log.logger":"logstash","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/outputs/logstash.(*asyncClient).Publish","file.name":"logstash/async.go","file.line":172},"message":"32 events out of 32 events sent to logstash host localhost:5044. Continue sending","service.name":"metricbeat","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2025-02-13T06:06:16.091+0530","log.logger":"publisher","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue.(*ackLoop).handleBatchSig","file.name":"memqueue/ackloop.go","file.line":80},"message":"ackloop: return ack to broker loop:32","service.name":"metricbeat","ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2025-02-13T06:06:16.092+0530","log.logger":"publisher","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/publisher/queue/memqueue.(*ackLoop).handleBatchSig","file.name":"memqueue/ackloop.go","file.line":82},"message":"ackloop: done send ack","service.name":"metricbeat","ecs.version":"1.6.0"}

```

Version:

> metricbeat-8.17.2-linux-x86\_64

---

<div class="post-metadata">

**Author:** ![Bhanu\_Praveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhanu_praveen/32/60395_2.png) [@Bhanu\_Praveen](https://discuss.elastic.co/u/Bhanu_Praveen)\
**Post date:** [February 13, 2025, 5:36am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/24 "2025-02-13T05:36:52Z")

</div>

> [@stephenb](#):
>
> `metricbeat test output`

```auto
[root@Testserver metricbeat-8.17.2-linux-x86_64]# ./metricbeat test config
Config OK

```

```auto
[root@Testserver metricbeat-8.17.2-linux-x86_64]# ./metricbeat test output
logstash: localhost:5044...
  connection...
    parse host... OK
    dns lookup... OK
    addresses: ::1, 127.0.0.1
    dial up... OK
  TLS... WARN secure connection disabled
  talk to server... OK

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 13, 2025, 5:38am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/25 "2025-02-13T05:38:44Z")

</div>

> [@stephenb](#):
>
> `./metricbeat test prometheus `

And this one

---

<div class="post-metadata">

**Author:** ![Bhanu\_Praveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhanu_praveen/32/60395_2.png) [@Bhanu\_Praveen](https://discuss.elastic.co/u/Bhanu_Praveen)\
**Post date:** [February 13, 2025, 5:40am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/26 "2025-02-13T05:40:14Z")

</div>

> [@stephenb](#):
>
> ./metricbeat test prometheus

```auto
[root@Testserver metricbeat-8.17.2-linux-x86_64]# ./metricbeat test prometheus
Test config

Usage:
  metricbeat test [command]

Available Commands:
  config Test configuration settings
  modules Test modules settings
  output Test metricbeat can connect to the output by using the current settings

Flags:
  -h, --help help for test

Global Flags:
  -E, --E setting=value Configuration overwrite
  -c, --c string Configuration file, relative to path.config (default "metricbeat.yml")
  -d, --d string Enable certain debug selectors
  -e, --e Log to stderr and disable syslog/file output
      --environment environmentVar set environment being ran in (default default)
      --path.config string Configuration path
      --path.data string Data path
      --path.home string Home path
      --path.logs string Logs path
      --plugin pluginList Load additional plugins
      --strict.perms Strict permission checking on config files (default true)
  -v, --v Log at INFO level

Use "metricbeat test [command] --help" for more information about a command.

```

---

<div class="post-metadata">

**Author:** ![Bhanu\_Praveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhanu_praveen/32/60395_2.png) [@Bhanu\_Praveen](https://discuss.elastic.co/u/Bhanu_Praveen)\
**Post date:** [February 13, 2025, 5:41am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/27 "2025-02-13T05:41:49Z")

</div>

Ignore

---

<div class="post-metadata">

**Author:** ![Bhanu\_Praveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhanu_praveen/32/60395_2.png) [@Bhanu\_Praveen](https://discuss.elastic.co/u/Bhanu_Praveen)\
**Post date:** [February 13, 2025, 5:45am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/28 "2025-02-13T05:45:03Z")

</div>

> [@Bhanu\_Praveen](#):
>
> ```auto
> "address": "http://testserver.dev.com:42115/rpsservice/actuator/prometheus%3FtId=e5bf6fc7-457a-406f-b2df-1a38be998f51",
> 
> ```

```auto
prometheus...
  collector...OK
    result:
    {
     "@timestamp": "2025-02-13T00:55:41.402Z",
     "event": {
      "dataset": "prometheus.collector",
      "duration": 10621946,
      "module": "prometheus"
     },
     "metricset": {
      "name": "collector",
      "period": 10000
     },
     "prometheus": {
      "labels": {
       "instance": "Testserver.dev.com:42115",
       "job": "prometheus"
      },
      "metrics": {
       "up": 0
      }
     },
     "service": {
      "address": "http://Testserver.dev.com:42115/rpsservice/actuator/prometheus%3FtId=e5bf6fc7-457a-406f-b2df-1a38be998f51",
      "type": "prometheus"
     }
    }

```

If we observe service address, http url is different than what i had put in there. "?" in path is converting to %3F. Might be causing issue?

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 13, 2025, 5:52am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/29 "2025-02-13T05:52:34Z")

</div>

`./metricbeat test modules prometheus`

I think that is the same.

`%3F` is URL encode of `?` so in don't think that is the issue

Looks like is connected to the base path fine / authenticated so I don't think it is having problem with authentication

So I think your endpoint is not returning prometheus metrics as expected format.. Because that looks like it connected to the base path fine..

---

<div class="post-metadata">

**Author:** ![Bhanu\_Praveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhanu_praveen/32/60395_2.png) [@Bhanu\_Praveen](https://discuss.elastic.co/u/Bhanu_Praveen)\
**Post date:** [February 13, 2025, 5:54am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/30 "2025-02-13T05:54:09Z")

</div>

If you see the error log, it says 401 status returned which is unauthorized, right

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 13, 2025, 5:55am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/31 "2025-02-13T05:55:24Z")

</div>

Yup ..

Also says

`unable to decode response` so perhaps 401 is misleading

Not sure what to tell you never ran into this.. I don't think what is being returned is metrics format ... We have literally 1000s of users that use prometheus module

I think your actuator endpoint does not provide in /metrics format

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 13, 2025, 6:11am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/32 "2025-02-13T06:11:13Z")

</div>

> **[Spring Boot integration | Elastic integrations | Elastic](https://www.elastic.co/guide/en/integrations/current/spring_boot.html)**

EDIT : Took out wont work...

Question are these micrometer metrics?

Apologies I couldn't solve this

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 13, 2025, 7:00am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/33 "2025-02-13T07:00:04Z")

</div>

> [@Bhanu\_Praveen](#):
>
> ```auto
> # TYPE http_requests_total counter 
> http_requests_total{code="200",method="GET"} 28 
> http_requests_total{code="200",method="POST"} 3`
> 
> ```

Yeah those looks like prometheus

Mine

```auto
node_cpu_seconds_total{cpu="13",mode="idle"} 261376.83
node_cpu_seconds_total{cpu="13",mode="nice"} 0
node_cpu_seconds_total{cpu="13",mode="system"} 656.75
node_cpu_seconds_total{cpu="13",mode="user"} 921.48
node_cpu_seconds_total{cpu="14",mode="idle"} 245167.35
....
node_filesystem_avail_bytes{device="/dev/disk1s1s1",device_error="",fstype="apfs",mountpoint="/"} 6.5457954816e+11
node_filesystem_avail_bytes{device="/dev/disk1s2",device_error="",fstype="apfs",mountpoint="/System/Volumes/Data"} 6.5457954816e+11
node_filesystem_avail_bytes{device="/dev/disk1s3",device_error="",fstype="apfs",mountpoint="/System/Volumes/Preboot"} 6.54579499008e+11
node_filesystem_avail_bytes{device="/dev/disk1s5",device_error="",fstype="apfs",mountpoint="/System/Volumes/VM"} 6.54585479168e+11
node_filesystem_avail_bytes{device="/dev/disk1s6",device_error="",fstype="apfs",mountpoint="/System/Volumes/Update"} 6.54585479168e+11
node_filesystem_avail_bytes{device="/dev/disk3s1",device_error="",fstype="apfs",mountpoint="/private/tmp/dmg.opkzUX"} 8.4058112e+07
node_filesystem_avail_bytes{device="map auto_home",device_error="",fstype="autofs",mountpoint="/System/Volumes/Data/home"} 0

```

not sure what to tell ya ... I am baffled...

---

<div class="post-metadata">

**Author:** ![Bhanu\_Praveen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhanu_praveen/32/60395_2.png) [@Bhanu\_Praveen](https://discuss.elastic.co/u/Bhanu_Praveen)\
**Post date:** [February 13, 2025, 8:04am UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/34 "2025-02-13T08:04:44Z")

</div>

Below are mine, @stephenb No worries, thanks for your time and patience. Will keep trying and let you know if solved

```auto
 HELP cache_puts_total The number of entries added to the cache
# TYPE cache_puts_total counter
cache_puts_total{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="APPCONFIG_CACHE",cache_manager="cacheManager",host="in7lin059",name="APPCONFIG_CACHE"} 0.0
cache_puts_total{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="RPSConfiguration",cache_manager="cacheManager",host="in7lin059",name="RPSConfiguration"} 37.0
cache_puts_total{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="RPSConfigurationV2",cache_manager="cacheManager",host="in7lin059",name="RPSConfigurationV2"} 739.0
cache_puts_total{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="ftaCodeCache",cache_manager="cacheManager",host="in7lin059",name="ftaCodeCache"} 0.0
cache_puts_total{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="ivaOperatorCache",cache_manager="cacheManager",host="in7lin059",name="ivaOperatorCache"} 0.0
cache_puts_total{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="tenantInfoCache",cache_manager="cacheManager",host="in7lin059",name="tenantInfoCache"} 0.0
# HELP cache_removals Cache removals
# TYPE cache_removals gauge
cache_removals{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="APPCONFIG_CACHE",cache_manager="cacheManager",host="in7lin059",name="APPCONFIG_CACHE"} 0.0
cache_removals{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="RPSConfiguration",cache_manager="cacheManager",host="in7lin059",name="RPSConfiguration"} 24.0
cache_removals{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="RPSConfigurationV2",cache_manager="cacheManager",host="in7lin059",name="RPSConfigurationV2"} 336.0
cache_removals{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="ftaCodeCache",cache_manager="cacheManager",host="in7lin059",name="ftaCodeCache"} 0.0
cache_removals{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="ivaOperatorCache",cache_manager="cacheManager",host="in7lin059",name="ivaOperatorCache"} 0.0
cache_removals{CUST="RPS",ENV="DEV",PRODUCT="GTM",cache="tenantInfoCache",cache_manager="cacheManager",host="in7lin059",name="tenantInfoCache"} 0.0

```

---

<div class="post-metadata">

**Author:** ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)\
**Post date:** [February 23, 2025, 7:18pm UTC](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447/35 "2025-02-23T19:18:38Z")

</div>

Heya @Bhanu_Praveen

Not sure this will help much, but I remembered this thread...

It turns out I had another user who was doing Spring Boot, Micrometer + Actuator.

I got it to work.

I used this as a sample app.

> **[GitHub - rkurniawati/prometheus-histogram](https://github.com/rkurniawati/prometheus-histogram/tree/main)**
>
> main

Here is my metricbeat / agent config.

```auto
- module: prometheus
  period: 10s
  hosts: ["localhost:8080"]
  metrics_path: /actuator/prometheus
  use_types: true
  rate_counters: true

```

 ![Screenshot 2025-02-23 at 11.15.39 AM](https://us1.discourse-cdn.com/elastic/original/3X/0/7/077170784599c13cc3b924d983c85cb144e4f647.png)

Percentiles... no authorization... but this definitely works... I think your issue is probably around that extra parameters but I don't know why

 ![Screenshot 2025-02-23 at 11.17.15 AM](https://us1.discourse-cdn.com/elastic/original/3X/d/f/dff79d577ab273ac713526f7f87ef89b2e72c80d.png)

I also got it to work with the Java APM Agent Directly

[Previous page](https://discuss.elastic.co/t/not-able-to-parse-prometheus-metrics-to-json-format/374447.md?page=1)
