130 lines
4.8 KiB
PowerShell
130 lines
4.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
NetBird Observability — Telegraf Node Installer (Windows, als Administrator)
|
|
.EXAMPLE
|
|
Set-ExecutionPolicy Bypass -Scope Process -Force
|
|
iwr -useb https://gitea.m-m.bio/mm/netbird-telegraf-installer/raw/branch/main/install.ps1 | iex
|
|
# mit Parametern:
|
|
& ([scriptblock]::Create((iwr -useb https://gitea.m-m.bio/mm/netbird-telegraf-installer/raw/branch/main/install.ps1))) -Name mypc -Collector 100.83.134.46
|
|
#>
|
|
param(
|
|
[string]$Name = $env:COMPUTERNAME.ToLower(),
|
|
# nvidia_smi-Input wird nur aktiv genutzt, wenn nvidia-smi installiert ist
|
|
[string]$Collector = "",
|
|
[string]$Token = "",
|
|
[string]$Version = "1.40.0",
|
|
[switch]$Uninstall
|
|
)
|
|
$ErrorActionPreference = "Stop"
|
|
if (-not $Token -and -not $Collector) { throw "Kein Token: -Token <Bearer-Token> angeben (siehe README)." }
|
|
if ($Collector) {
|
|
$PromUrl = "http://${Collector}:9090/api/v1/write"; $LokiUrl = "http://${Collector}:3100"; $Base = "http://${Collector}"
|
|
} else {
|
|
$PromUrl = "https://imac-prometheus.x05.idx.wf/api/v1/write"; $LokiUrl = "https://imac-loki.x05.idx.wf"; $Base = "https://imac-prometheus.x05.idx.wf"
|
|
}
|
|
$Dir = "C:\Program Files\Telegraf"
|
|
$Exe = "$Dir\telegraf.exe"
|
|
$Conf = "$Dir\telegraf.conf"
|
|
|
|
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
if (-not $isAdmin) { throw "Bitte als Administrator ausführen." }
|
|
|
|
if ($Uninstall) {
|
|
if (Test-Path $Exe) { Stop-Service telegraf -ErrorAction SilentlyContinue; & $Exe --service uninstall 2>$null }
|
|
Remove-Item -Recurse -Force $Dir -ErrorAction SilentlyContinue
|
|
Write-Host "[netbird-telegraf] Telegraf entfernt."; exit 0
|
|
}
|
|
|
|
$arch = "amd64"
|
|
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { $arch = "arm64" }
|
|
elseif (-not [Environment]::Is64BitOperatingSystem) { $arch = "i386" }
|
|
Write-Host "[netbird-telegraf] Node=$Name Arch=$arch Collector=$Collector"
|
|
|
|
try {
|
|
$h = @{}
|
|
if ($Token) { $h["Authorization"] = "Bearer $Token" }
|
|
$readyUrl = if ($Collector) { "$Base/-/ready" } else { "$Base/-/ready" }
|
|
Invoke-WebRequest -UseBasicParsing -TimeoutSec 10 -Headers $h $readyUrl | Out-Null
|
|
Write-Host "[netbird-telegraf] Collector erreichbar (auth ok)."
|
|
} catch {
|
|
Write-Warning "Collector $PromUrl nicht erreichbar oder Token falsch — Installation läuft weiter, Telegraf puffert."
|
|
}
|
|
|
|
if (-not (Test-Path $Exe)) {
|
|
$zip = Join-Path $env:TEMP "telegraf.zip"
|
|
$url = "https://dl.influxdata.com/telegraf/releases/telegraf-${Version}_windows_${arch}.zip"
|
|
Write-Host "[netbird-telegraf] Lade $url"
|
|
Invoke-WebRequest -UseBasicParsing $url -OutFile $zip
|
|
$tmp = Join-Path $env:TEMP "telegraf-extract"
|
|
Remove-Item -Recurse -Force $tmp -ErrorAction SilentlyContinue
|
|
Expand-Archive $zip $tmp
|
|
New-Item -ItemType Directory -Force $Dir | Out-Null
|
|
$bin = Get-ChildItem $tmp -Recurse -Filter telegraf.exe | Select-Object -First 1
|
|
Copy-Item $bin.FullName $Exe -Force
|
|
}
|
|
|
|
$cfg = @"
|
|
[global_tags]
|
|
node = "$Name"
|
|
|
|
[agent]
|
|
interval = "15s"
|
|
flush_interval = "15s"
|
|
metric_batch_size = 1000
|
|
metric_buffer_limit = 20000
|
|
hostname = "$Name"
|
|
|
|
[[outputs.http]]
|
|
url = "$PromUrl"
|
|
data_format = "prometheusremotewrite"
|
|
timeout = "10s"
|
|
namedrop = ["win_eventlog"]
|
|
[outputs.http.headers]
|
|
Content-Type = "application/x-protobuf"
|
|
Content-Encoding = "snappy"
|
|
X-Prometheus-Remote-Write-Version = "0.1.0"
|
|
Authorization = "Bearer $Token"
|
|
|
|
[[outputs.loki]]
|
|
domain = "$LokiUrl"
|
|
endpoint = "/loki/api/v1/push"
|
|
namepass = ["win_eventlog"]
|
|
sanitize_label_names = true
|
|
metric_name_label = ""
|
|
http_headers = { "Authorization" = "Bearer $Token" }
|
|
|
|
[[inputs.nvidia_smi]]
|
|
timeout = "10s"
|
|
|
|
[[inputs.cpu]]
|
|
percpu = false
|
|
totalcpu = true
|
|
[[inputs.mem]]
|
|
[[inputs.swap]]
|
|
[[inputs.system]]
|
|
[[inputs.disk]]
|
|
[[inputs.diskio]]
|
|
[[inputs.net]]
|
|
[[inputs.win_services]]
|
|
|
|
[[inputs.win_eventlog]]
|
|
xpath_query = "<QueryList><Query Id='0' Path='System'><Select Path='System'>*[System[(Level=1 or Level=2 or Level=3)]]</Select></Query><Query Id='1' Path='Application'><Select Path='Application'>*[System[(Level=1 or Level=2 or Level=3)]]</Select></Query></QueryList>"
|
|
from_beginning = false
|
|
only_first_line_of_message = true
|
|
|
|
[[processors.override]]
|
|
namepass = ["win_eventlog"]
|
|
fieldinclude = ["Message", "Source", "EventID"]
|
|
"@
|
|
Set-Content -Path $Conf -Value $cfg -Encoding UTF8
|
|
|
|
& $Exe --config $Conf --test --input-filter cpu | Out-Null
|
|
Stop-Service telegraf -ErrorAction SilentlyContinue
|
|
& $Exe --service uninstall 2>$null | Out-Null
|
|
& $Exe --service install --config $Conf | Out-Null
|
|
Start-Service telegraf
|
|
Start-Sleep -Seconds 3
|
|
if ((Get-Service telegraf).Status -ne "Running") { throw "Dienst telegraf läuft nicht." }
|
|
Write-Host "[netbird-telegraf] OK — Node '$Name' liefert an $PromUrl (Metriken) und $LokiUrl (Eventlog Warn/Error)."
|
|
Write-Host "[netbird-telegraf] Grafana: http://100.83.134.46:3000 (nur im NetBird)"
|