Difference between revisions of "Pushgateway windows"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
# Windows
 
# Windows
  
## Not working
+
## Windows push
 
```
 
```
 
$ErrorActionPreference = "Stop"
 
$ErrorActionPreference = "Stop"
$cred = Get-Credential
+
$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)
 
$r=(invoke-webrequest http://localhost:9182/metrics)
# filter is not working properly
 
# $metrics = ($r.content.tostring() -split "[`r`n]" | select-string -pattern "go_|http_request|http_requests|http_response|process" -NotMatch)
 
 
$metrics = ($r.content.tostring())
 
$metrics = ($r.content.tostring())
Invoke-WebRequest -uri https://pushgateway.example.com/metrics/job/windows-node/instance/winhost -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
 
```
 
```
  
No working
+
## Run as a service
 +
 
 +
## Code
 +
vim C:\app\prompush.ps1
 +
```
 +
# $ErrorActionPreference = "Stop"
 +
$interval_secs = 30
 +
$job_name = "windows-node"
 +
$hname = (hostname)
 +
$user = "myuser"
 +
$pass = "changeme"
 +
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
 +
$cred = New-Object System.Management.Automation.PSCredential($user, $secpasswd)
 +
 
 +
while($true) {
 +
 
 +
  $r=(invoke-webrequest http://localhost:9182/metrics)
 +
  $metrics = ($r.content.tostring())
 +
  Invoke-WebRequest -uri https://pushgateway.example.com/metrics/job/$job_name/instance/$hname -cred $cred -Body $metrics -Method Post
 +
  sleep $interval_secs
 +
}
 +
```
 +
 
 +
## create service
 +
create-service.ps1
 +
```
 +
$Binary = (Get-Command Powershell).Source
 +
$Arguments = '-ExecutionPolicy Bypass -NoProfile -File "C:\app\prompush.ps1"'
 +
nssm.exe install prompush $Binary $Arguments
 +
```
 +
 
 +
```
 +
choco install nssm
 +
./create-service.ps1
 +
start-service prompush
 +
```
 +
 
 +
 
 +
 
 +
 
 +
<hr>
 +
<br>
 +
<br>
 +
<br>
 +
 
 +
 
 +
 
 +
# More stuff
 +
## 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"

Latest revision as of 03:10, 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 as a service

Code

vim C:\app\prompush.ps1

# $ErrorActionPreference = "Stop"
$interval_secs = 30
$job_name = "windows-node"
$hname = (hostname)
$user = "myuser"
$pass = "changeme"
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($user, $secpasswd)

while($true) {

  $r=(invoke-webrequest http://localhost:9182/metrics)
  $metrics = ($r.content.tostring())
  Invoke-WebRequest -uri https://pushgateway.example.com/metrics/job/$job_name/instance/$hname -cred $cred -Body $metrics -Method Post
  sleep $interval_secs
}

create service

create-service.ps1

$Binary = (Get-Command Powershell).Source
$Arguments = '-ExecutionPolicy Bypass -NoProfile -File "C:\app\prompush.ps1"'
nssm.exe install prompush $Binary $Arguments
choco install nssm
./create-service.ps1
start-service prompush




More stuff

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