Difference between revisions of "Pushgateway windows"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
# Windows | # Windows | ||
− | ## | + | ## Windows push |
``` | ``` | ||
$ErrorActionPreference = "Stop" | $ErrorActionPreference = "Stop" | ||
Line 13: | Line 13: | ||
Invoke-WebRequest -uri https://pushgateway.example.com/metrics/job/node-windows/instance/$hname -cred $cred -Body $metrics -Method Post | Invoke-WebRequest -uri https://pushgateway.example.com/metrics/job/node-windows/instance/$hname -cred $cred -Body $metrics -Method Post | ||
``` | ``` | ||
+ | ## Run every minute | ||
+ | ``` | ||
+ | $Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NonInteractive -NoLogo -NoProfile -command C:\bin\prompush.ps1' | ||
+ | $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 1) | ||
+ | $Settings = New-ScheduledTaskSettingsSet | ||
+ | $Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings | ||
+ | Register-ScheduledTask -TaskName 'prompush every minute' -InputObject $Task -User 'system' | ||
+ | ``` | ||
+ | |||
+ | |||
− | + | Sandbox not working | |
``` | ``` | ||
$ErrorActionPreference = "Stop" | $ErrorActionPreference = "Stop" |
Revision as of 02:34, 12 January 2024
Windows
Windows push
$ErrorActionPreference = "Stop" $hname = (hostname) $user = "myuser" $pass = "mypass" $secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential($user, $secpasswd) $r=(invoke-webrequest http://localhost:9182/metrics) $metrics = ($r.content.tostring()) Invoke-WebRequest -uri https://pushgateway.example.com/metrics/job/node-windows/instance/$hname -cred $cred -Body $metrics -Method Post
Run every minute
$Action = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument '-NonInteractive -NoLogo -NoProfile -command C:\bin\prompush.ps1' $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 1) $Settings = New-ScheduledTaskSettingsSet $Task = New-ScheduledTask -Action $Action -Trigger $Trigger -Settings $Settings Register-ScheduledTask -TaskName 'prompush every minute' -InputObject $Task -User 'system'
Sandbox not working
$ErrorActionPreference = "Stop" $r=(invoke-webrequest http://localhost:9182/metrics) # $metrics = ($r.tostring() -split "[`r`n]" | select-string -pattern "go_|http_request|http_requests|http_response|process" -NotMatch) $metrics = ($r.content.tostring() -split "[`r`n]" | select-string -pattern "go_|http_request|http_requests|http_response|process" -NotMatch) # $metrics = ($metrics -replace '(?m)^\s*?\n'| out-string ) $metrics = ($metrics -replace '(?m)^\s*?\n') # echo $metrics | more # $metrics = ($r.tostring()) Invoke-WebRequest -uri https://example.uvoo.io/metrics/job/windows-nodes/instance/winhost -cred $cred -Body $metrics -Method Post