Monitoring as Code with Newrelic and Terraform

#Initializeterraform {
# Require Terraform version 0.13.x (recommended)
required_version = "~> 1.0.3"
# Require the latest 2.x version of the New Relic provider
required_providers {
newrelic = {
source = "newrelic/newrelic"
version = "~> 2.21"
}
}
}
#NR provider detailsprovider "newrelic" {
account_id = 7-digit-key # Your New Relic account ID
api_key = "NRAK-YOURKEY" # Your New Relic user key
region = "US" # US or EU (defaults to US)
}
#Create a New Dashboardresource "newrelic_one_dashboard" "dash_au_prod" {
name = "Your Dashboard Name"
page {
name = "Page 1"
widget_line {
title = "CPU %"
row = 1
column = 1
height = 3
width = 4
nrql_query {
query = "SELECT latest(`host.cpuPercent`) FROM Metric FACET `host.fullHostname` SINCE 30 MINUTES AGO TIMESERIES where host.fullHostname like '%prod_cluster%' AND apmApplicationNames ='|java_apm_1|'"
}
}
widget_line {
title = "Memory %"
row = 1
column = 5
height = 3
width = 4
nrql_query {
query = "NRQL Query here"
}
}
widget_line {
title = "Web Requests"
row = 1
column = 9
height = 3
width = 4
nrql_query {
query = "NRQL Query Here"
}
}
} #page closepage {
name = "Page 2
widget_pie {
title = "APM Transactions"
row = 1
column = 1
height = 3
width = 4
nrql_query {
query = "SELECT count(*) FROM Transaction WHERE appName = 'dotnet_core' FACET `host` LIMIT 10 SINCE 30 minutes ago EXTRAPOLATE"
}
}

widget_table {
title = "Host load"
row = 1
column = 5
height = 3
width = 4
nrql_query {
query = "NRQL Query here"
}
}
widget_table {
title = "AU PROD load Average"
row = 1
column = 9
height = 3
width = 4
nrql_query {
query = "Query Here"
}
}
} #pageclose

} #dashboard closure
Create New Alert Policyresource "newrelic_alert_policy" "load_test_alert_policy" {
name = "Load Testing Alerts Policy"
}
Dot_NET_Exceptionsresource "newrelic_nrql_alert_condition" "load_test_dot_net_exceptions" {
policy_id = newrelic_alert_policy.load_test_alert_policy.id
type = "static"
name = "System.Net.WebException alert"
description = "system.Net.WebException count > 100 in 5 min window"
enabled = true
value_function = "single_value"
violation_time_limit_seconds = 86400
nrql {
query = "SELECT count(*) FROM TransactionError FACET `error.class` WHERE appId = YOUR_APM_ID AND `error.expected` IS not true AND `error.class` = 'System.Net.WebException'"
evaluation_offset = 3
}
critical {
operator = "above"
threshold = 100
threshold_duration = 300
threshold_occurrences = "ALL"
}
}

--

--

--

https://www.linkedin.com/in/hasanb21/

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Desaturation Shader in OpenGL

3 Popular Websites Built With Django in 2021

Kafka, where are all my messages 😱?

An Ideal Data Science Environment on a Google Virtual Machine

Use Kali Linux tools in Ubuntu and other Debian based OS in a convenient way.

{UPDATE} Chicken Scream Metsästys Simulator 2017 Hack Free Resources Generator

Linux Containers

A Developer’s Guide to Building Serverless Applications on the Cloud — Part 1 (Deployment)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
HasanB

HasanB

https://www.linkedin.com/in/hasanb21/

More from Medium

What is Infrastructure as Code and How Can You Leverage It?

Understanding the Kubernetes manifest

Understanding Logical flow of Terraform initialization

KUBERNETES IS NOW THE DOMINANT TECHNOLOGY FOR CLOUD APPLICATIONS