Working with New Relic (newrelic dashboard) and Terraform in Unix/Linux

New Relic is a web application, aimed primarily at developers. Its main objective is to track the ways users interact with designed products. This tool analysts.

Key features of New Relic:

  • Monitoring of the availability.
  • Warning and notification.
  • Performance profiles.
  • Plugins.
  • Histograms and percentiles.
  • The API access.
  • Response time in real-time.
  • The performance analyzer of the Java virtual machine.
  • Error detection, analysis.
  • The database call response time and throughput.
  • Diagnostics, transaction tracing and the stack trace.
  • Analysis of response time, throughput and breakdown by components.
  • Details on SQL performance.
  • Analysis of the user in real-time when browsing web pages.
  • Custom dashbord.
  • Track individual business transactions.
  • X-Ray session for business transactions.
  • Cross-application tracing for distributed applications.
  • Reports on availability, scalability, deployment.

Install terraform in Unix/Linux

The installation is very primitive and I described how to do this here:

Install terraform in Unix/Linux

So, in this article, I created a script to automatically install the software. It has been tested on CentOS 6/7, Debian 8, and on Mac OS X. Everything is working properly!

To get help on commands, run:

$ terraform --help
Usage: terraform [-version] [-help] <command> [args]

The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.

Common commands:
 apply Builds or changes infrastructure
 console Interactive console for Terraform interpolations
 destroy Destroy Terraform-managed infrastructure
 env Workspace management
 fmt Rewrites config files to canonical format
 get Download and install modules for the configuration
 graph Create a visual graph of Terraform resources
 import Import existing infrastructure into Terraform
 init Initialize a Terraform working directory
 output Read an output from a state file
 plan Generate and show an execution plan
 providers Prints a tree of the providers used in the configuration
 push Upload this Terraform module to Atlas to run
 refresh Update local state file against real resources
 show Inspect Terraform state or plan
 taint Manually mark a resource for recreation
 untaint Manually unmark a resource as tainted
 validate Validates the Terraform files
 version Prints the Terraform version
 workspace management Workspace

All other commands:
 debug Debug output management (experimental)
 force-unlock Manually unlock the terraform state
 state Advanced state management

Start using!

Working with New Relic (newrelic dashboard) and Terraform in Unix/Linux

I have the terraform folder, in it I will lay providers with whom I work. Because in this example I will use newrelic, it will create the folder and move into it. Further, in this folder, you should create:

$ mkdir examples modules

In the examples folder, I keep so called “playbook” to razvarivaya various services, for example — zabbix-server, grafana, web servers, and so on. In modules directory I will store all the necessary modules.

Can start writing the module, but for this task, I will create a folder:

$ mkdir modules/newrelic_dashboard

Go to it:

$ cd modules/newrelic_dashboard

Open the file:

$ vim newrelic_dashboard.tf

In this file, insert:

#---------------------------------------------------
# Add newrelic dashboard
#---------------------------------------------------
resource "newrelic_dashboard" "dashboard" {
 count = "${var.dashboard && !var.dashboard_custom ? 1 : 0}"

 title = "${var.dashboard_title !="" ? "${lower(var.dashboard_title)}" : "${lower(var.name)}-nr-dashboard-${lower(var.environment)}" }"
 icon = "${var.dashboard_icon}"
 visibility = "${var.dashboard_visibility}"
 editable = "${var.dashboard_editable}"

 widget {
 title = "${var.dashboard_widget_title !="" ? "${lower(var.dashboard_widget_title)}" : "${lower(var.name)}-nr-widget-${lower(var.environment)}" }"
 visualization = "${var.dashboard_widget_visualization}"
 row = "${var.dashboard_widget_row}"
 column = "${var.dashboard_widget_column}"

 width = "${var.dashboard_widget_width}"
 height = "${var.dashboard_widget_height}"
 notes = "${var.dashboard_widget_notes}"
 nrql = "${var.dashboard_widget_nrql}"
}

 widget {
 title = "Page Views"
 row = 1
 column = 3
 visualization = "billboard"
 nrql = "SELECT count(*) FROM PageView SINCE 1 week ago"
}

 lifecycle = {
 create_before_destroy = true,
 ignore_changes = []
}

 depends_on = [] 
}

resource "newrelic_dashboard" "dashboard_custom" {
 count = "${var.dashboard && var.dashboard_custom ? 1 : 0}"

 title = "${var.dashboard_title !="" ? "${lower(var.dashboard_title)}" : "${lower(var.name)}-nr-dashboard-${lower(var.environment)}" }"
 icon = "${var.dashboard_icon}"
 visibility = "${var.dashboard_visibility}"
 editable = "${var.dashboard_editable}"

 widget = "${var.dashboard_custom_widget}"

 lifecycle = {
 create_before_destroy = true,
 ignore_changes = []
}

 depends_on = []
}

Open the file:

$ vim variables.tf

And write:

#-----------------------------------------------------------
# Global 
#-----------------------------------------------------------
variable "name" {
 description = "The name for newrelic_alert resources"
 default = "test"
} 

variable "environment" {
 description = "environment"
 default = "prod"
}

#-----------------------------------------------------------
# newrelic dashboard
#-----------------------------------------------------------
variable "dashboard" {
 description = "Enable newrelic_dashboard"
 default = "false"
}

variable "dashboard_title" {
 description = "(Required) The title of The dashboard."
 default = ""
}

variable "dashboard_icon" {
 description = "(Optional) The icon for the dashboard. Defaults to bar chart."
 default = "bar-chart"
}

variable "dashboard_visibility" {
 description = "(Optional) Who can see the dashboard in an account. Must be owner or all. Defaults to all."
 default = "all"
}

variable "dashboard_editable" {
 description = "(Optional) Who can edit the dashboard in an account. Must be read_only, editable_by_owner, editable_by_all, or all. Defaults to editable_by_all."
 default = "editable_by_all"
}

variable "dashboard_widget_title" {
 description = "(Required) A title for the widget."
 default = ""
}

variable "dashboard_widget_row" {
 description = "(Required) Row position of the widget from top left, starting at 1."
 default = 1
}

variable "dashboard_widget_visualization" {
 description = "(Required) How the widget visualizes data."
 default = "faceted_line_chart"
}

variable "dashboard_widget_column" {
 description = "(Required) Column position of the widget from top left, starting at 1."
 default = 1
}

variable "dashboard_widget_width" {
 description = "(Optional) Width of the widget. Defaults to 1."
 default = 1
}

variable "dashboard_widget_height" {
 description = "(Optional) Height of the widget. Defaults to 1."
 default = 1
}

variable "dashboard_widget_notes" {
 description = "(Optional), Description of the widget."
 default = ""
}

variable "dashboard_widget_nrql" {
 description = "(Optional) Valid NRQL query string. See Writing NRQL Queries for help."
 default = ""
}

variable "dashboard_custom" {
 description = "Enable newrelic_dashboard for custom usage"
 default = "false"
}

variable "dashboard_custom_widget" {
 description = "(Optional) A widget that describes a visualization. Widgets See below for details."
 type = "list"
 default = []
}

Actually in this file are stored all the variables. Thanks cap!

Open the last file:

$ vim outputs.tf

And need to insert the following lines:

#-----------------------------------------------------------
# newrelic_dashboard
#-----------------------------------------------------------
output "newrelic_dashboard_id" {
 description = "ID for newrelic_dashboard"
 value = "${newrelic_dashboard.dashboard.*.id}"
}

output "newrelic_dashboard_custom_id" {
 description = "ID for dashboard_custom"
 value = "${newrelic_dashboard.dashboard_custom.*.id}"
}

Now go to the folder aws/examples and create another folder to check is written of a miracle:

$ mkdir newrelic_dashboard && cd $_

Inside the folders you created open the file:

$ vim main.tf

And paste the following code into it:

#
# MAINTAINER: Vitaliy Natarov "[email protected]"
#
terraform {
 required_version = "~> 0.11.11"
}

provider "newrelic" {
 api_key = "75e6741e6326cce1666ecfb94c3c0b8fdf"
}

module "newrelic_dashboard" {
 source = "../../modules/newrelic_dashboard"

 dashboard = "true"

 dashboard_custom = "true"
 dashboard_custom_widget = [
{
 title = "Average Transaction Duration"
 row = 1
 column = 1
 width = 2
 visualization = "faceted_line_chart"
 nrql = "SELECT AVERAGE(duration) from Transaction FACET appName TIMESERIES auto"
},
{
 title = "Page Views"
 row = 1
 column = 3
 visualization = "billboard"
 nrql = "SELECT count(*) FROM PageView SINCE 1 week ago"
}
]
}

In the file is to register all needed, but most importantly:

  • api_key — the API key which you can generate in “‘Account settings’->’API keys'”.

Everything is already written and ready to use. Well, let’s start testing. In the folder with your playboycom performed:

$ terraform init

This action, I initialize the project. Then, tighten the module:

$ terraform get

PS: To update the changes in the module itself, you can run:

$ terraform get-update

Check the validation:

$ terraform validate

Zapuskaem run:

$ terraform plan

I brought everything I have is good and you can run the deployment:

$ terraform apply

As you can see from the output, everything went smoothly! To remove creation, you can run:

$ terraform destroy

Another utility:

Working with New Relic (newrelic alert) and Terraform in Unix/Linux

Working with New Relic (newrelic nrql) and Terraform in Unix/Linux

Working with New Relic (newrelic infra) and Terraform in Unix/Linux

Working with New Relic (newrelic synthetics) and Terraform in Unix/Linux

Working with New Relic (newrelic dashboard) and Terraform in Unix/Linux

All material Uploader in github account for easy use:

$ git clone https://github.com/SebastianUA/terraform.git

But that’s about it. This article “Working with New Relic (newrelic dashboard) and Terraform in Unix/Linux” is completed.

Source: linux-notes.org

(Visited 73 times, 1 visits today)