<p>I deployed Prometheus Node Exporter pod on k8s. It worked fine.</p>

<p>But when I try to get system metrics by calling Node Exporter metric API in my custom Go application</p>

<pre><code>curl -X GET "http://[my Host]:9100/metrics"
</code></pre>

<p>The result format was like this</p>

<pre><code># TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.7636e-05
go_gc_duration_seconds{quantile="0.25"} 2.466e-05
go_gc_duration_seconds{quantile="0.5"} 5.7992e-05
go_gc_duration_seconds{quantile="0.75"} 9.1109e-05
go_gc_duration_seconds{quantile="1"} 0.004852894
go_gc_duration_seconds_sum 1.291217651
go_gc_duration_seconds_count 11338
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 8
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.12.5"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 2.577128e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 2.0073577064e+10
.
.
.
something like this
</code></pre>

<p>Those long texts are hard to parse and I want to get the results in JSON format to parse them easily.</p>

<p><a href="https://github.com/prometheus/node_exporter/issues/1062" rel="nofollow noreferrer">https://github.com/prometheus/node_exporter/issues/1062</a></p>

<p>I checked Prometheus Node Exporter GitHub Issues and someone recommended <a href="https://github.com/prometheus/prom2json" rel="nofollow noreferrer">prom2json</a>.
But this is not I'm looking for. Because I have to run extra process to execute prom2json to get results. I want to get Node Exporter's system metric by simply calling HTTP request or some kind of Go native packages in my code.</p>

<p>How can I get those Node Exporter metrics in JSON format?</p>

<p>You already mentioned <code>prom2json</code> and you can pull the package into your Go file by importing <code>github.com/prometheus/prom2json</code>.</p>

<p>The <a href="https://github.com/prometheus/prom2json/blob/62ab84336b66a85df0fb29289f71f54454159337/cmd/prom2json/main.go" rel="nofollow noreferrer">sample executable in the repo</a> has the all building blocks you need. <a href="https://github.com/prometheus/prom2json/blob/62ab84336b66a85df0fb29289f71f54454159337/cmd/prom2json/main.go#L56-L58" rel="nofollow noreferrer">First, open the URL</a> and then <a href="https://github.com/prometheus/prom2json/blob/62ab84336b66a85df0fb29289f71f54454159337/cmd/prom2json/main.go#L71-L73" rel="nofollow noreferrer">use the <code>prom2json</code> package to read the data</a> and <a href="https://github.com/prometheus/prom2json/blob/62ab84336b66a85df0fb29289f71f54454159337/cmd/prom2json/main.go#L88-L91" rel="nofollow noreferrer">store the result</a>.</p>

<p>However, you should also have a look at <a href="https://godoc.org/github.com/prometheus/common/expfmt#TextParser" rel="nofollow noreferrer">expfmt.TextParser</a> as that is the native way to ingest Prometheus formatted metrics. </p>

<hr>
