Help build the future of open source observability software Open positions

Check out the open source projects we support Downloads

Grot cannot remember your choice unless you click the consent notice at the bottom.

Connecting Prometheus-Ksonnet to Grafana Cloud

Connecting Prometheus-Ksonnet to Grafana Cloud

24 Feb, 2020 3 min

In a previous post we showed how to install Prometheus and Grafana using the prometheus-ksonnet library along with Tanka. This is great for getting a well-managed monitoring install going, but sometimes it isn’t enough for monitoring larger clusters.

If you have multiple clusters that you want to monitor on a single dashboard, or need long-term storage, or need a high-availability setup for your monitoring data, then this installation won’t be sufficient on its own.

Fortunately, the Grafana Cloud Hosted Prometheus product offered by Grafana Labs solves all of these problems: It supports long-term storage, can receive metrics from multiple clusters, and is fundamentally designed to support high availability.

And it’s simple to connect Prometheus-Ksonnet to Grafana Cloud. This blog post will show you how.

Step-by-step instructions

  1. Log into or create an account on Login Login
  2. Click “Hosted Metrics.”

    Hosted Metrics
    Hosted Metrics
  3. Click “Create Hosted Metrics Instance.”

    Create Hosted Metrics Instance
    Create Hosted Metrics Instance
  4. Choose a name, select backend type Prometheus, then click “Create Hosted Metrics Instance.”

  5. You will now need to note a few configuration values that we will reuse later. Under “Grafana Data Source settings”: *Grab the URL. It will end with /api/prom. *Take note of your user ID (which will be a number). *Where it says password, click “Generate now.”

    Create an API Key
    Create an API Key
  6. Give this key a name (e.g. prometheus-ksonnet), choose a role of EditorViewer, and click “Create API Key.”

    API Key Created
    API Key Created
  7. You will be shown an API key. Make note of this. (Don’t worry; the keys shown in the screenshots are not valid.)

    Code for Prometheus Config
    Code for Prometheus Config
  8. Under the section “Sending Data to Prometheus,” you will see a snippet of YAML. Grab the URL from that YAML. It will end /api/prom/push.

  9. Now edit your environments/default/main.jsonnet.

    It should look like this, but with your own URLs, user ID, and api key in place of these samples:

local prometheus = import 'prometheus-ksonnet/prometheus-ksonnet.libsonnet';

prometheus {
  _config+:: {
    namespace: "default",
    cluster_name: "grafana",
    prometheus: {
      cluster: 'my-cluster',
      read_url: '',
      write_url: '',
      user: '10449',
      key: 'eyJrIjoiZTc2MzViYjk5MWQ4ZjgyN2Y4NDQwYTVhMGQ4OTZlZjhhNjUxZjJkOCIsIm4iOiJwcm9tZXRoZXVzLWtzb25uZXQiLCJpZCI6MTgxMDcxfQ==',
  prometheus_config+:: {
    global: { external_labels: {cluster: $._config.prometheus.cluster} },
    remote_write+: [
        url: $._config.prometheus.write_url,
        basic_auth: {
          username: $._config.prometheus.user,
          password: $._config.prometheus.key,

Here, you will see we have added values to configuration. We have added a remote write configuration to Prometheus so that it can find and write to Grafana Cloud, and we have added a data source to our Grafana instance. As well as this, we have added an external label to our Prometheus metrics that names our cluster. This means that we can distinguish metrics coming from separate clusters. We can use a template on our dashboards to allow us to change between clusters.

With this Grafana instance, we can now query our local Prometheus within our cluster, and we can also query the Grafana Cloud Hosted Prometheus instance. If this contains data regarding other clusters, we can access that data from any of our Grafana instances.

Interested in learning more?

To find out if Grafana Cloud – the highly available, fast, fully managed logging and metrics platform – is right for your organization, read more about it here.

Ready to try it now?

On this page