Grafana is a popular technology that makes it easy to visualize metrics. The Oracle Cloud Infrastructure Data Source for Grafana is used to extend Grafana by adding OCI as a data source. The plugin enables you to visualize metrics related to a number of OCI resources: Compute, Networking, Storage, and custom metrics.
This walkthrough is intended for use by people who would like to deploy Grafana and the OCI Data Source for Grafana on a virtual machine in OCI.
Make sure you have access to the Monitoring Service and that metrics have been enabled for the resources you are trying to monitor.
Begin by installing Terraform onto your development machine. We will be using the Oracle Cloud Infrastructure Provider, a tool designed to understand API interactions and exposing resource related to a specific cloud vendor, in this case Oracle Cloud Infrastructure. Terraform requires a number of variables in order to properly create an environment for Grafana and the OCI Data Source for Grafana plugin:
variable "tenancy_ocid" {}
variable "user_ocid" {}
variable "fingerprint" {}
variable "private_key_path" {}
variable "region" {}
variable "compartment_ocid" {}
variable "ssh_public_key" {}
variable "ssh_private_key" {}
variable "subnet_id" {}
variable "availability_domain" {}
variable "dynamic_group_name" {}
Information regarding how to find each of these variables is located here. It can be useful to pass these variables into your .bashrc or .bash_profile. You will need to enter a value for the availability domain of your subnet (e.g. PKGK:US-ASHBURN-AD-1). This information can be found under Networking > Virtual Cloud Networks > [Your Network] > Subnets. It will also prompt you for the name of your dynamic group (e.g. metric-collection).
The Terraform script requires the use of an existing Virtual Cloud Network with access to the public internet. If you do not already have access to a Virtual Cloud Network with access to the public internet you can navigate to Virtual Cloud Networks under Networking and click Create Virtual Cloud Network. Choosing the CREATE VIRTUAL CLOUD NETWORK PLUS RELATED RESOURCES option will result in a VCN with an Internet Routing Gateway and Route Tables configured for access to the public internet. Three subnets will be created: one in each availability domain in the region.
After Terraform has been downloaded on your development machine, download the Terraform scripts here: wget https://objectstorage.us-ashburn-1.oraclecloud.com/n/oracle-cloudnative/b/GrafanaTerraform/o/terraform_grafana.tar && tar -xvf terraform_grafana.tar
cd /terraform_grafana
. Initialize a new Terraform configuration with terraform init
. This will result in the creation of two additional files in the directory: terraform.tfstate
and terraform.tfstate.backup
.
Next run terraform plan
to generate an execution plan. This is useful to validate your Terraform script prior to applying it to your environment. The command will output the end state of your environment.
Run terraform apply
and enter the same availability domain and dynamic group name variables used in the previous step. This will build the infrastructure specified in the execution plan. The following three actions will take place:
-
The script will first create a dynamic group used to group virtual machine or bare metal compute instances as “principals” (similar to user groups). This will be named according to the variable you passed in during the previous step.
-
Next, a policy named “grafana_policy” will be created in the root compartment of your tenancy to permit instances in the dynamic group to make API calls against Oracle Cloud Infrastructure services.
-
The script will then provision a compute instance with the name TFInstance0 in the compartment of your choice connected to the specified Virtual Cloud Network. After the instance is provisioned, the script will download and install Grafana and the Grafana OCI plugin. The plugin is stored in Oracle Object Storage.
Once the Terraform script is finished running you will receive an "Apply complete!" notification.
The next step is to configure the plugin. To find the IP address of the newly-created instance, navigate to Compute > Instances > TFInstance0. The Public IP address is listed under the Primary VNIC Information section. Using the SSH key referenced in your Terraform variables, connect to Grafana via port forward by running ssh opc@[Instance Public IP] -L 3000:localhost:3000
.
Navigate to the Grafana homepage at http://localhost:3000.
Log in with the default username admin
and the password admin
. You will be prompted to change your password. Click Skip or Save to continue.
On the Home Dashboard click the gear icon on the left side of the page.
Click Add data source.
Choose oracle-oci-datasource as your data source type.
Fill in your Tenancy OCID, Default Region, and Environment. Your Default region is the same as your home region listed in the Tenancy Details page. For Environment choose OCI Instance.
Click Save & Test to return to the home dashboard.
To remove the environment created by the Terraform script, run terraform destroy
and pass in the same availability domain and dynamic group variables passed in during the apply step.
Check out how to use the newly installed and configured plugin in our Using Grafana with Oracle Cloud Infrastructure Data Source walkthrough.