How to Add PubSub Dashboard in Grafana

Programming Equipment in Dark
Reading Time: 2 minutes

PubSub is an event-driven messaging, Streaming analytics Data integration to ingest data & distribute data. It works upon the Publishers & subscribers model where the publisher publishes the message & subscriber subscribes to topics of publishers & receive those data or messages.

For monitoring & observability, DevOps creates a dashboard to monitor the services. You can create PubSub dashboard in Grafana if you are using Grafana as the single source for monitoring all resources & services running on on-prem & on the cloud.

Ways to create a dashboard in Grafana

  • Import pre-built JSON of the dashboard
  • Create panels & rows & make a dashboard from scratch
  • Import JSON from Terraform scripts

Prerequisites

  • Stackdriver Datasource Added in Grafana
  • Grafana endpoint URL & Port number. (default is 3000)
  • Username & Password for admin access.
  • Pubsub Topic & subscriptions setup.
  • Terraform installed & basic knowledge.

Import JSON directly into existing Grafana UI

Download the dashboard JSON by running this command.

wget https://raw.githubusercontent.com/knoldus/pubsub-grafana-dashboard/master/pubsub-dashboard.json

Now you can directly import this JSON into Grafana UI if you have admin privileges to create dashboards. Else you will need help or terraform if using gitops approach to manage Grafana.

Follow below steps to create this dashboard in Grafana by using terraform.

Setup Authentication

1. export environment variable for authentication

Run this command in your terminal. This will set up an environment variable in your current terminal session. If you are using multiple sessions then place this line in your .bashrc file.

export GRAFANA_AUTH="admin_username:admin_password"

Terraform will look for admin user & password in this environment variable. So it is important to add at beginning.

2. Add Grafana URL & port in main.tf file

Now create a main.tf file and add the below code. This is a provider plugin of grafana that downloads grafana libraries for terraform. Add your grafana URL and the port number to access grafana instance.

provider "grafana" {
  url  = "http://your-grafana-url:port"
}

Add Users & Team

Step-1 Clone the dashboard Repo

git clone https://github.com/knoldus/pubsub-grafana-dashboard.git
cd pubsub-grafana-dashboard

Step-2 Create terraform.auto.tfvars file

  1. Open terraform.auto.tfvars file.
  2. Add users’ emails to give them access to edit the dashboard
  3. Add Team name for users
users = ["rahul.soni@knoldus.com","rahul989741@gmail.com"]
team = "DevOps"

Step-3 Run the terraform scripts

  1. Install provider plugins
terraform init
  1. Check Terraform plan
terraform plan
  1. Apply the terraform configurations
terraform apply

PubSub Dashboard

This is how pubsub dashboard will look like.

Conclusion

This repo is used to create pubsub dashboard in the grafana in very simple steps. Just pull the code in repo. Setup authentication & run the code.

Written by 

Rahul Soni is a Software Consultant at Knoldus Software. He is always charged up for new things & learnings. He is dedicated to his work and believes in quality output. He loves to take deep dives into cloud technologies & different tools.