Monitoring and collecting data from Golang

Golang is a programming language created at Google. It is a compiled, statically typed language in the tradition of Algol and C, with garbage collection, limited structural typing, memory safety features and CSP-style concurrent programming features added. The compiler and other language tools originally developed by Google are all free and open source.

More information on:

How it works

Because Golang has no default logging or metrics endpoint we need to include one in our application. We will use the Golang prometheus library together with the CoScale Prometheus endpoint parser to retrieve metrics from the standard Golang runtime as well as provide a possibility to extend it with custom metrics.


The plugin needs to be installed together with a CoScale agent, instructions on how to install the CoScale agent can be found here. If you want to monitor Golang inside Docker containers using CoScale, check out the instructions here.


Configure your Golang application to provide a Prometheus endpoint

Add client_golang to your application using the built in golang import system. You can find an example of the integration below:

// Copyright 2015 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

// A minimal example of how to include Prometheus instrumentation.
package main

import (


var addr = flag.String("listen-address", ":8080", "The address to listen on for HTTP requests.")

func main() {
	http.Handle("/metrics", promhttp.Handler())
	log.Fatal(http.ListenAndServe(*addr, nil))

It is now possible to also add custom metrics, more information can be found on the client_golang docs. Custom metrics will be automatically detected and pushed by the CoScale agent.

Configure the CoScale Prometheus plugin to parse the information from the endpoint

CoScale uses the Prometheus plugin to parse the information from the Golang Prometheus endpoint, go to Agent configuration and enable the CoScale Prometheus plugin for your environment. Depending on the setup you will need to add the plugin to an agent or setup the CoScale in-container monitoring for a certain image.

The endpoint configured above is available on port 8080 with endpoint /metrics:


You can also add a Docker Label to your Dockerfile so that the agent will automatically pick up the Prometheus endpoint when it detects a new container:

LABEL com.coscale.monitoring='[{"PluginType":"PROMETHEUS","Configuration":{"STATS URL":[""]}}]'