Skip to content

Newrelic Agent Deployment SSM Docs

Posted on:December 17, 2022 at 12:19 PM

Hi There, This is my first blog post on this Blog, I created this blog to share my Works or Research most of the scripts here I’ve used in my work, Hope you like it.

Linux

---
schemaVersion: "2.2"
description: "Install New Relic Agent-Linux"
parameters:
  APIKey:
    type: "String"
    description: "New Relic API Key"
  AccountId:
    type: "String"
    description: "New Relic Account ID"
mainSteps:
  - action: aws:runShellScript
    name: ExecuteInstaller
    precondition:
      StringEquals:
        - platformType
        - Linux
    onFailure: Abort
    inputs:
      timeoutSeconds: "300"
      runCommand:
        - "curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh | bash && sudo NEW_RELIC_API_KEY={{ APIKey }} NEW_RELIC_ACCOUNT_ID={{ AccountId }} /usr/local/bin/newrelic install"
  - action: aws:runShellScript
    name: DisablingProcessMetrics
    inputs:
      timeoutSeconds: "60"
      runCommand:
        - "sed -i 's/enable_process_metrics: true/enable_process_metrics: false/g' /etc/newrelic-infra.yml"
  - action: aws:runShellScript
    name: RestartAgent
    inputs:
      timeoutSeconds: "60"
      runCommand:
        - "sudo systemctl restart newrelic-infra"

Windows

---
schemaVersion: "2.2"
description: "Install New Relic Agent-Windows"
parameters:
  APIKey:
    type: "String"
    description: "New Relic API Key"
  AccountId:
    type: "String"
    description: "New Relic Account ID"
mainSteps:
  - action: aws:runPowerShellScript
    name: ExecuteInstaller
    precondition:
      StringEquals:
        - platformType
        - Windows
    onFailure: Abort
    inputs:
      timeoutSeconds: "300"
      runCommand:
        - "[Net.ServicePointManager]::SecurityProtocol = 'tls12, tls'"
        - '(New-Object System.Net.WebClient).DownloadFile("https://download.newrelic.com/install/newrelic-cli/scripts/install.ps1", "$env:TEMP\install.ps1")'
        - '& PowerShell.exe -ExecutionPolicy Bypass -File $env:TEMP\install.ps1'
        - "$env:NEW_RELIC_API_KEY='{{ APIKey }}'"
        - "$env:NEW_RELIC_ACCOUNT_ID='{{ AccountId }}'"
        - "& 'C:\\Program Files\\New Relic\\New Relic CLI\\newrelic.exe' install"
  - action: aws:runPowerShellScript
    name: DisableProcessMetrics
    inputs:
      timeoutSeconds: "60"
      runCommand:
        - "((Get-Content -path 'C:\Program Files\New Relic\newrelic-infra\newrelic-infra.yml' -Raw) -replace 'enable_process_metrics: true','enable_process_metrics: false') | Set-Content -Path 'C:\Program Files\New Relic\newrelic-infra\newrelic-infra.yml'"
        - "Get-Content -path 'C:\Program Files\New Relic\newrelic-infra\newrelic-infra.yml'"
  - action: aws:runPowerShellScript
    name: RestartAgent
    inputs:
      timeoutSeconds: "60"
      runCommand:
        - "Restart-Service -Name NewRelic-Infra"

Create an SSM Docs on System Manager Select Command and Paste the script accordingly, The API Key and Account ID can be taken from the Install Script from your New Relic Console when using the Guided Install method.

Example Script:

curl -Ls https://download.newrelic.com/install/newrelic-cli/scripts/install.sh | bash && sudo NEW_RELIC_API_KEY={NRAK-Q6QNDxxxxxxxxxx}
NEW_RELIC_ACCOUNT_ID={323****}
NEW_RELIC_REGION=EU /usr/local/bin/newrelic install

API Key == NEW_RELIC_API_KEY AND Account ID == NEW_RELIC_ACCOUNT_ID

SSM Docs above are using US Region if you need to use EU Region you will need to update the “ExecuteInstaller” Steps to add the NEW_RELIC_REGION=EU before executing the Installer similar to the Example Script.

I gonna put this as a placeholder, later I will update this with more information if needed.