Working with New Relic (newrelic synthetics) 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 synthetics) 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_synthetics

Go to it:

$ cd modules/newrelic_synthetics

Open the file:

$ vim

In this file, insert:

# Add newrelic synthetics alert condition
resource "newrelic_synthetics_alert_condition" "synthetics_alert_condition" {
 count = "${var.synthetics_alert_condition ? 1 : 0}" 

 policy_id = "${var.synthetics_alert_condition_policy_id}"
 name = "${var.synthetics_alert_condition_name !="" ? "${lower(var.synthetics_alert_condition_name)}" : "${lower(}-nr-synthetics-alert-condition-${lower(var.environment)}" }"
 monitor_id = "${}"

 runbook_url = "${var.synthetics_alert_condition_runbook_url}"
 enabled = "${var.synthetics_alert_condition_enabled}"

 lifecycle = {
 create_before_destroy = true,
 ignore_changes = []

 depends_on = ["data.newrelic_synthetics_monitor.synthetics_monitor"] 


data "newrelic_synthetics_monitor" "synthetics_monitor" {
 name = "${var.synthetics_monitor_name !="" && var.synthetics_alert_condition ? "${lower(var.synthetics_monitor_name)}" : "${lower(}-nr-synthetics-monitor-${lower(var.environment)}" }"

Open the file:

$ vim

And write:

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

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

# newrelic_nrql_alert_condition
variable "synthetics_alert_condition" {
 description = "Enable synthetics_alert_condition"
 default = "false"

variable "synthetics_alert_condition_name" {
 description = "(Required) The title of The condition"
 default = ""

variable "synthetics_alert_condition_policy_id" {
 description = "(Required) The ID of the policy where this condition should be used."
 default = ""

variable "synthetics_monitor_name" {
 description = " (Required) The title of this condition."
 default = ""

variable "synthetics_alert_condition_runbook_url" {
 description = "(Optional) Runbook URL to display in notifications."
 default = ""

variable "synthetics_alert_condition_enabled" {
 description = "(Optional) Set whether to enable the alert condition. Defaults to true."
 default = "true"

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

Open the last file:

$ vim

And need to insert the following lines:

# newrelic_nrql_alert_condition
output "newrelic_synthetics_alert_condition_id" {
 description = "ID for newrelic_synthetics_alert_condition"
 value = "${newrelic_synthetics_alert_condition.synthetics_alert_condition.*.id}"

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

$ mkdir newrelic_synthetics && cd $_

Inside the folders you created open the file:

$ vim

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_alert" {
 source = "../../modules/newrelic_alert"

 # vars for newrelic_alert_policy
 alert_policy = "true"
 #alert_policy_name = "new-relic-policy-PER_CONDITION"
 alert_policy_incident_preference = "PER_CONDITION"
 alert_policy_simple_default = "true"

 alert_channel = "true"
 alert_channel_slack = "true"
 alert_channel_slack_configuration_channel = "new-relic"
 alert_channel_slack_configuration_url = ""
 alert_condition = "true"
 alert_condition_policy_id = "${element(module.newrelic_alert.alert_policy_id, 0)}"
 #alert_condition_policy_id = "${element(module.newrelic_alert.simple_default_alert_policy_id, 0)}"
 alert_condition_type = "apm_app_metric"
 alert_condition_entities = ["PHP Application"]

 alert_policy_channel = "false"

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

 synthetics_alert_condition = "true"
 synthetics_alert_condition_policy_id = "${element(module.newrelic_alert.alert_policy_id, 0)}"
 synthetics_alert_condition_name = "test"
 synthetics_monitor_name = "linux-notes" 

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

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


(Visited 62 times, 1 visits today)