feat: Telegraf node installer (Linux apt/dnf/apk/static, Proxmox, Apache, Docker; Windows PowerShell)
This commit is contained in:
commit
9a878e8b8b
9 files changed
+513
No files matched your search
+113
@@ -0,0 +1,113 @@
|
||||
<#
|
||||
.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(),
|
||||
[string]$Collector = "100.83.134.46",
|
||||
[string]$Version = "1.40.0",
|
||||
[switch]$Uninstall
|
||||
)
|
||||
$ErrorActionPreference = "Stop"
|
||||
$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 {
|
||||
Invoke-WebRequest -UseBasicParsing -TimeoutSec 8 "http://${Collector}:9090/-/ready" | Out-Null
|
||||
Write-Host "[netbird-telegraf] Collector erreichbar."
|
||||
} catch {
|
||||
Write-Warning "Collector http://${Collector}:9090 nicht erreichbar — NetBird verbunden? 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 = "http://${Collector}:9090/api/v1/write"
|
||||
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"
|
||||
|
||||
[[outputs.loki]]
|
||||
domain = "http://${Collector}:3100"
|
||||
endpoint = "/loki/api/v1/push"
|
||||
namepass = ["win_eventlog"]
|
||||
sanitize_label_names = true
|
||||
metric_name_label = ""
|
||||
|
||||
[[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 http://${Collector}:9090 (Metriken) und :3100 (Eventlog Warn/Error)."
|
||||
Write-Host "[netbird-telegraf] Grafana: http://${Collector}:3000 (nur im NetBird)"
|
||||
Reference in new issue
Block a user