windows-exporter 설치 스크립트
source link: https://gist.github.com/choshsh/e7c54224f088dc8cc35a8d5500aa4b35
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Instantly share code, notes, and snippets.
$service_name = "windows-exporter" $version = "0.16.0" $workDir = "C:\windows-exporter\" $file = "windows_exporter-$version-amd64.exe" $url = "https://github.com/prometheus-community/windows_exporter/releases/download/v$version/"
Write-Host "service name: $service_name" -f Green Write-Host "agent version: $version" -f Green Write-Host "dir: $workdir`n" -f Green
Write-Host "Check already installed ..." -f Green $isInstalled = $null -ne (Get-Service $service_name -ErrorAction SilentlyContinue -WarningAction SilentlyContinue)
if ($isInstalled) { Write-Host "Remove old version ..." -f Green Start-Process -FilePath sc.exe -ArgumentList "stop $service_name" Start-Sleep -Seconds 2 Start-Process -FilePath sc.exe -ArgumentList "delete $service_name" Start-Sleep -Seconds 2 }
Write-Host "Start install ..." -f Green
try { if (!(Test-Path $workDir)) { New-Item -ItemType Directory -Path $workDir -Force } # 다운로드 Write-Host "Download ..." -f Green (New-Object Net.WebClient).DownloadFile( $url + $file, $workDir + $file )
# 서비스 등록 Write-Host "Add Service ..." -f Green New-Service ` -Name $service_name ` -BinaryPathName ($workDir + $file) ` -Description "TAK monitoring service"
# Attempt to set the service to delayed start using sc config. Try { Start-Process -FilePath sc.exe -ArgumentList "config $service_name start= delayed-auto" } Catch { Write-Host -f red "An error occured setting the service to delayed start." } # 서비스 시작 Write-Host "`nStart Service ..." -f Green Start-Service -Name $service_name -PassThru
# 방화벽 설정 $frName = "tak-monitoring" $fr = Get-NetFirewallRule -Name $frName -ErrorAction Ignore -WarningAction Ignore Write-Host "`nConfig Firewall Rule - [$frName] - Allow port 9182 ..." -f Green if ($null -eq $fr) { New-NetFirewallRule -DisplayName $frName -Name $frName -Direction Inbound -Action Allow -Protocol "TCP" -LocalPort 9182 -Enabled True | Out-Null } else { $fr | Set-NetFirewallRule -LocalPort 9182 | Out-Null }
Write-Host "`nCompleted" -f Green } catch { Write-Host -f red "An error occured." Write-Host -f red $_.Exception.Message }
exit 0
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK