4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShellAdvent Calendar 2017

Day 19

New Relic をバージョンアップした話

Last updated at Posted at 2017-12-11

NewRelic Server Monitorが使えなくなると言うんで、
NewRelic Server Monitorの代わりにNewrelic Infrastructureを導入することになったらしい。
Azure上の仮想マシンはPowershellDSC、CloudServiceはPowershellで自動化していたインストールのScriptを書き換えてみようと思います。

#NewRelicServerMonitorのときは、、、

chkNRSM.ps1
$r = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -match "New Relic Server Monitor"}
if ($r -ne $null)
{......

installNRSM.ps1

Write-Verbose "Installing NewRelic module ... Downloading ..."

# download module files
$sourceContainer = $installSourceStorageUrl + "installmodules";
C:\AzCopy\AzCopy.exe /Source:$sourceContainer /Dest:"c:\Users\newrelicusr" /Y /sourceKey:$installSourceStorageKey /Pattern:$installNewRelicFile

$package = "c:\Users\newrelicusr\$installNewRelicFile"
$license_key = "NR_LICENSE_KEY="+$installNewRelicKey

#install NewRelic
Write-Verbose "Start .. NewRelic install"
Start-Process -FilePath "msiexec.exe" -ArgumentList /i , $package,'/L*v c:\Users\newrelicusr\installNewRelic.log',/qn ,$license_key -Wait

Write-Verbose "Success."

#Delete temporary msi.
Remove-Item -Force -Recurse -Path $package -ErrorAction Ignore

unInstallNRSM.ps1

Write-Verbose "NewRelic module ... Deleting ..."

#Get NewRelic module
$r = Get-WmiObject -Class Win32_Product | Where-Object {$_.Name -match "newrelic-infra"}
if ($r -ne $null)
{
    $r.Uninstall()
}

と、まぁこんな感じです。

#NewRelic Infrastructureを導入するには、、、

installNRI.ps1

#Downloading New Relic client
Write-Output "Downloading New Relic Client"
$File = "$env:temp\newrelic-infra.msi"

#Downloading the file
(New-Object System.Net.WebClient).DownloadFile($NewRelicClientUrl, $File)   
Write-Output "Downloaded to: $File"

#Installing client
Write-Output "Installing Client"
Start-Process msiexec.exe -Wait -ArgumentList "/I `"$File`" TARGETDIR=`"$InstallDir`" /qn"
Write-Output "Client Installed"

#Updating license file
Write-Output "Updating License file"
(Get-Content "$InstallDir\newrelic-infra\newrelic-infra.yml").Replace("<ENTER YOUR NEW RELIC KEY HERE>", $NewRelicKey) | Set-Content "$InstallDir\newrelic-infra\newrelic-infra.yml"

#Wait a bit to get the service registered properly
Start-Sleep 5

#Restarting service
Get-Service -Name newrelic-infra | Restart-Service

#Cleaning up
Write-Output "Cleaning up"
Remove-Item $File -Force

とまぁこんな感じで、、、

#おわり
見ての通り、まだ開発途中なんでインストールしか書いていませんが(アンインストールはなしにするかもしれませんが)、、、
とにかく、NewRelicは結構便利なのでみなさん試しに触ってみましょう。
あとできちんと記事の追記を行います。
※Azureの情報少ないなー

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?