<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Prometheus Go Client Library on Grafana Labs</title><link>https://grafana.com/oss/prometheus/exporters/go-exporter/</link><description>Recent content in Prometheus Go Client Library on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/oss/prometheus/exporters/go-exporter/index.xml" rel="self" type="application/rss+xml"/><item><title>Cloud integration</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>
&lt;div class="bg-solitude p-1 mb-1" style="">
&lt;p>Grafana Cloud comes with an ever-expanding set of integrations to quickly get an observability stack up and running in minutes. The Go Integration, built-in to the Grafana Cloud Agent, scrapes essential Go metrics and pushes them to Grafana Cloud. The agent will scrape metrics exposed by the &lt;code>client_golang&lt;/code> library, and Grafana Cloud will automatically provision a tailored Grafana dashboard for visualizing and acting on this data.&lt;/p>
&lt;div>
&lt;a class="btn btn--primary br-5 " href="/auth/sign-up/create-user?pg=oss-prom-go-exporter-exporter&amp;amp;plcmt=body-txt-overview" rel="noopener noreferrer">Sign up for a free account to get started&lt;/a>
&lt;/div>
&lt;/div>
&lt;p>To learn more, check out the &lt;a href="/docs/grafana-cloud/integrations/">Grafana Cloud docs&lt;/a>.&lt;/p>
&lt;h4 id="how-it-works">How it works&lt;/h4>
&lt;p>Configuring, installing, connecting, and maintaining Prometheus monitoring components typically involves significant domain knowledge. It can take quite a while to go from setup to dashboard and alerts. As the creators of Grafana - and core contributors to Prometheus and Cortex - we build simple integrations to abstract some of this work away in order to quickly get started. How it works:&lt;/p>
&lt;ol>
&lt;li>Sign up (or log in) for a &lt;a href="/auth/sign-up/create-user?pg=oss-prom-go-exporter-exporter&amp;amp;plcmt=body-txt-overview">free Grafana Cloud account&lt;/a>.&lt;/li>
&lt;li>Select the target you’d like to observe (an ever-expanding catalogue).&lt;/li>
&lt;li>Run a one-line command to install the Grafana Agent. The agent embeds and preconfigures Exporters to expose default metrics, and pushes them to the Grafana Cloud metrics backend.&lt;/li>
&lt;li>Voila! You’ll see tailored Grafana dashboards and will benefit from sane alerting defaults.&lt;/li>
&lt;/ol>
&lt;p>Looking for a different Exporter or integration? Check out our &lt;a href="/docs/grafana-cloud/integrations/">growing library of integrations for popular components&lt;/a> like MySQL, Postgres, Redis, Memcached and more.&lt;/p></description></item><item><title>Dashboards</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>&lt;h3 id="go-runtime-metrics-dashboard">Go runtime metrics Dashboard&lt;/h3>
&lt;p>&lt;img
class="lazyload d-inline-block"
src="/api/dashboards/14061/images/10053/image"
alt="Go runtime metrics Dashboard"/>&lt;/p>
&lt;p>This dashboard includes panels for the following metrics:&lt;/p>
&lt;ul>
&lt;li>Total Reserved Memory&lt;/li>
&lt;li>Stack Memory Use&lt;/li>
&lt;li>Other Memory Reservations&lt;/li>
&lt;li>Heap Memory&lt;/li>
&lt;li>Allocation Rate, Bytes&lt;/li>
&lt;li>Heap Object Allocation Rate&lt;/li>
&lt;li>Number of Live Objects&lt;/li>
&lt;li>Goroutines&lt;/li>
&lt;li>GC min &amp;amp; max duration&lt;/li>
&lt;li>Next GC, Bytes&lt;/li>
&lt;/ul>
&lt;p>You can import the dashboard directly using the following dashboard ID: &lt;strong>&lt;code>14061&lt;/code>&lt;/strong>.&lt;/p>
&lt;p>You can fetch the dashboard JSON &lt;a href="/api/dashboards/14061/revisions/1/download">&lt;strong>here&lt;/strong>&lt;/a>.&lt;/p>
&lt;p>This dashboard was generated using the Prometheus Go client library &lt;a href="https://github.com/grafana/jsonnet-libs/tree/master/go-runtime-mixin" target="_blank" rel="noopener noreferrer">mixin&lt;/a>.&lt;/p></description></item><item><title>Install</title><link>https://grafana.com</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://grafana.com</guid><description>&lt;h2 id="prometheus-go-client-library-quickstart">Prometheus Go Client Library Quickstart&lt;/h2>
&lt;p>In this guide you&amp;rsquo;ll learn how to set up and configure the Prometheus Go client library to collect Go metrics like Total Reserved Memory and Stack Memory Use, and expose them as Prometheus-style metrics. You&amp;rsquo;ll then configure &lt;a href="https://prometheus.io/" target="_blank" rel="noopener noreferrer">Prometheus&lt;/a> to scrape Go metrics and optionally ship them to Grafana Cloud. Finally, you&amp;rsquo;ll set up a preconfigured Grafana &lt;a href="/grafana/dashboards">dashboard&lt;/a>. At the end of this guide you&amp;rsquo;ll have a dashboard that you can use to visualize your Go metrics.&lt;/p>
&lt;p>If you&amp;rsquo;re using &lt;a href="/products/cloud/">Grafana Cloud&lt;/a>, the &lt;a href="/docs/grafana-cloud/integrations/integration-golang/">Go&lt;/a> Integration can help you get up and running quickly. The Go Integration embeds a Prometheus metrics collector into the &lt;a href="https://github.com/grafana/agent" target="_blank" rel="noopener noreferrer">Grafana Cloud Agent&lt;/a> and automatically provisions a dashboard, so you don&amp;rsquo;t have to run through the steps in this guide. To learn how to set up the Go Integration, please see &lt;a href="/docs/grafana-cloud/integrations/integration-golang/">Go Integration&lt;/a> from the Grafana Cloud docs.&lt;/p>
&lt;h2 id="prerequisites">Prerequisites&lt;/h2>
&lt;p>Before you get started, you should have the following available to you:&lt;/p>
&lt;ul>
&lt;li>Go installed on your machine. To learn more, please see &lt;a href="https://golang.org/doc/install" target="_blank" rel="noopener noreferrer">Download and install&lt;/a> from the Go docs.&lt;/li>
&lt;li>Prometheus running in your environment or directly on the machine. To learn how to install Prometheus, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/installation/" target="_blank" rel="noopener noreferrer">Installation&lt;/a> from the Prometheus docs.&lt;/li>
&lt;li>Grafana running in your environment or directly on the machine. To learn how to install Grafana, please see &lt;a href="/docs/grafana/latest/installation/">Install Grafana&lt;/a> from the Grafana docs.&lt;/li>
&lt;li>(Optional) A Grafana Cloud account. Grafana Cloud hosts Grafana and a &lt;a href="/oss/mimir/">Mimir&lt;/a>-based Prometheus metrics endpoint. You will still need to scrape metrics, using either Prometheus installed in your environment, or the &lt;a href="https://github.com/grafana/agent" target="_blank" rel="noopener noreferrer">Grafana Cloud Agent&lt;/a>. To learn more about Grafana Cloud, please see &lt;a href="/products/cloud/">Grafana Cloud&lt;/a>.&lt;/li>
&lt;/ul>
&lt;h2 id="step-1-setting-up-the-prometheus-go-client-library">Step 1: Setting up the Prometheus Go Client Library&lt;/h2>
&lt;p>In this step you&amp;rsquo;ll set up the Go client library to collect and expose Go metrics in Prometheus format. This guide uses an Ubuntu 20.04 system with Go 1.16.2. Steps may vary slightly depending on your operating system and Go version.&lt;/p>
&lt;p>This guide will set up a minimal application to expose default Go metrics. To instrument an existing application, please see the client_golang &lt;a href="https://github.com/prometheus/client_golang/" target="_blank" rel="noopener noreferrer">GitHub Repository&lt;/a>.&lt;/p>
&lt;p>Begin by creating a directory for your minimal Go app called &lt;code>metrics_test&lt;/code>, and &lt;code>cd&lt;/code> into it:&lt;/p>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">Bash&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-bash">mkdir metrics_test
cd metrics_test&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Next, initialize a Go module using &lt;code>go mod init&lt;/code>:&lt;/p>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">Bash&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-bash">go mod init test_metrics&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">go: creating new go.mod: module test_metrics
go: to add module requirements and sums:
go mod tidy&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Download and install any necessary &lt;code>client_golang&lt;/code> libraries using &lt;code>go get&lt;/code>:&lt;/p>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">Bash&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-bash">go get github.com/prometheus/client_golang/prometheus/promhttp&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">go get: added github.com/prometheus/client_golang v1.9.0&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Next, open a file called &lt;code>main.go&lt;/code> using your favorite editor, and paste in the following Go code:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">package main
import (
&amp;#34;net/http&amp;#34;
&amp;#34;github.com/prometheus/client_golang/prometheus/promhttp&amp;#34;
)
func main() {
http.Handle(&amp;#34;/metrics&amp;#34;, promhttp.Handler())
http.ListenAndServe(&amp;#34;:2112&amp;#34;, nil)
}&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>This minimal piece of code sets up a &lt;code>/metrics&lt;/code> HTTP endpoint that exposes a default set of Go metrics. It listen for HTTP requests on &lt;code>localhost:2112&lt;/code>.&lt;/p>
&lt;p>When you&amp;rsquo;re done, save and close the file.&lt;/p>
&lt;p>Compile and test the code using &lt;code>go run&lt;/code>:&lt;/p>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">Bash&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-bash">go run main.go&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>At this point your shell should hang. Open up another session or background the process to curl the metrics endpoint:&lt;/p>
&lt;div class="code-snippet ">&lt;div class="lang-toolbar">
&lt;span class="lang-toolbar__item lang-toolbar__item-active">Bash&lt;/span>
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;div class="lang-toolbar__border">&lt;/div>
&lt;/div>&lt;div class="code-snippet ">
&lt;pre data-expanded="false">&lt;code class="language-bash">curl http://localhost:2112/metrics&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">. . .
process_start_time_seconds 1.61559003439e&amp;#43;09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 1.106751488e&amp;#43;09
# HELP process_virtual_memory_max_bytes Maximum amount of virtual memory available in bytes.
# TYPE process_virtual_memory_max_bytes gauge
process_virtual_memory_max_bytes -1
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.
# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code=&amp;#34;200&amp;#34;} 0
promhttp_metric_handler_requests_total{code=&amp;#34;500&amp;#34;} 0
promhttp_metric_handler_requests_total{code=&amp;#34;503&amp;#34;} 0&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>If you see the above output, you&amp;rsquo;re ready to begin scraping Go metrics using Prometheus.&lt;/p>
&lt;p>Using &lt;code>client_golang&lt;/code>, you can also instrument your existing Go apps to emit custom metrics. To learn more about these features, please see the &lt;a href="https://github.com/prometheus/client_golang/" target="_blank" rel="noopener noreferrer">Go Client Library GitHub repository&lt;/a>.&lt;/p>
&lt;h2 id="step-2-scraping-prometheus-go-client-library-using-prometheus">Step 2: Scraping Prometheus Go client library using Prometheus&lt;/h2>
&lt;p>Now that the Prometheus Go client library is up and running on your machine, you can configure a Prometheus scrape job to collect and store Prometheus Go client library metrics.&lt;/p>
&lt;p>Add the following scrape job config to the &lt;code>scrape_configs&lt;/code> section of your &lt;code>prometheus.yml&lt;/code> configuration file:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">- job_name: go
static_configs:
- targets: [&amp;#39;localhost:2112&amp;#39;]&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>Replace &lt;code>localhost&lt;/code> with the IP address of the machine running your Go app. To learn more about configuring Prometheus, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/" target="_blank" rel="noopener noreferrer">Configuration&lt;/a> from the Prometheus docs.&lt;/p>
&lt;p>If you don&amp;rsquo;t have a &lt;code>prometheus.yml&lt;/code> configuration file, create a simple one using your favorite text editor. Open your preferred text editor and paste in the following Prometheus configuration:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">global:
scrape_interval: 15s
scrape_configs:
- job_name: go
static_configs:
- targets: [&amp;#39;localhost:2112&amp;#39;]&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;p>This configuration tells Prometheus to scrape all jobs every 15 seconds. The only configured scrape job is called &lt;code>go&lt;/code> and defines a &lt;code>localhost:2112&lt;/code> target. By default, Prometheus will scrape the &lt;code>/metrics&lt;/code> endpoint using HTTP.&lt;/p>
&lt;p>Save and close the file. You can then run Prometheus with the file using the following command:&lt;/p>
&lt;div class="code-snippet code-snippet__mini">&lt;div class="lang-toolbar__mini">
&lt;span class="code-clipboard">
&lt;button x-data="app_code_snippet()" x-init="init()" @click="copy()">
&lt;img class="code-clipboard__icon" src="/media/images/icons/icon-copy-small-2.svg" alt="Copy code to clipboard" width="14" height="13">
&lt;span>Copy&lt;/span>
&lt;/button>
&lt;/span>
&lt;/div>&lt;div class="code-snippet code-snippet__border">
&lt;pre data-expanded="false">&lt;code class="language-none">./prometheus --config.file=./prometheus.yml&lt;/code>&lt;/pre>
&lt;/div>
&lt;/div>
&lt;h3 id="shipping-metrics-to-grafana-cloud">Shipping metrics to Grafana Cloud&lt;/h3>
&lt;p>To ship Go metrics to Grafana Cloud from Prometheus, configure the &lt;code>remote_write&lt;/code> parameter in your &lt;code>prometheus.yml&lt;/code> configuration file. To learn more, please see &lt;a href="/docs/grafana-cloud/metrics/prometheus/">Metrics — Prometheus&lt;/a> from the Grafana Cloud docs. To learn more about the &lt;code>remote_write&lt;/code> parameter, please see &lt;a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write" target="_blank" rel="noopener noreferrer">&lt;code>remote_write&lt;/code>&lt;/a> from the Prometheus docs.&lt;/p>
&lt;h2 id="step-3-configuring-dashboards">Step 3: Configuring dashboards&lt;/h2>
&lt;p>This quickstart includes one dashboard:&lt;/p>
&lt;ul>
&lt;li>Go runtime metrics&lt;/li>
&lt;/ul>
&lt;p>To learn how to import this dashboard into Grafana, please see &lt;a href="/docs/grafana/latest/dashboards/export-import/#importing-a-dashboard">Importing a dashboard&lt;/a> from the Grafana docs.&lt;/p>
&lt;p>You can fetch the dashboard &lt;a href="?tab=dashboards">here&lt;/a>.&lt;/p>
&lt;h2 id="conclusion">Conclusion&lt;/h2>
&lt;p>In this quickstart you installed and ran a minimal Go app on your Linux machine that exposes Prometheus metrics using &lt;code>client_golang&lt;/code>. You then configured Prometheus to scrape the Go metrics exposed by &lt;code>client_golang&lt;/code>. Finally, you imported a Grafana dashboard to visualize your Go metrics.&lt;/p>
&lt;p>If you&amp;rsquo;re using Grafana Cloud, you can skip all of the steps in this guide by installing the Go Integration with the Grafana Cloud Agent. To learn how to set up the Go integration, please see &lt;a href="/docs/grafana-cloud/integrations/">Grafana Cloud Integrations&lt;/a>.&lt;/p>
&lt;p>The dashboard was generated using the Go Prometheus Mixin. Mixins are reusable templates for dasboards, recording rules, and alerts curated and designed by subject matter experts. To learn more, please see the &lt;a href="https://github.com/grafana/jsonnet-libs/tree/master/go-runtime-mixin" target="_blank" rel="noopener noreferrer">Go Mixin&lt;/a> repository.&lt;/p></description></item></channel></rss>