Skip to content

Commit 3ef9de7

Browse files
author
Klas Pihl
committed
change from WSL2 to container
1 parent caa8b73 commit 3ef9de7

File tree

1 file changed

+10
-39
lines changed

1 file changed

+10
-39
lines changed

measure-bbk/measure-bbk.ps1

+10-39
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<#
22
.SYNOPSIS
3-
Use WSL on Windows together with Bredbandskollens's binary to measure internet speed
3+
Use container together with Bredbandskollens's binary to measure internet speed
44
55
66
.DESCRIPTION
7-
Use WSL on Windows together with Bredbandskollens's binary to measure internet speed
8-
Output 4 PRTG channels
7+
Use docker container that package bbk cli and returns a json object.
98
109
WSL and Linux distro must be accessable from the user session that is invoked by the custom sensor (PRTG Security context).
1110
@@ -16,10 +15,11 @@
1615
1716
.NOTES
1817
2023-04-11 Version 1 [email protected]
18+
2023-08-31 Version 2 using docker as application /[email protected]
1919
.LINK
2020
https://www.bredbandskollen.se/om/mer-om-bbk/bredbandskollen-cli/
2121
.EXAMPLE
22-
. .\measure-bbk.ps1 -Duration 2 -Logfile "c:\temp\bbk.log" -Verbose
22+
. .\measure-bbk.ps1
2323
2424
.PARAMETER Duration
2525
Duration in seconds to measure
@@ -78,57 +78,28 @@ param (
7878
)
7979
$script:ErrorActionPreference='Stop'
8080
try {
81-
[scriptblock]$command = {
82-
if (-not $using:Logfile) {
83-
$Logfile = New-TemporaryFile
84-
} else {
85-
$Logfile = Get-Item -Path $using:Logfile
86-
}
87-
Set-Location $Logfile.Directory
88-
89-
if ($using:Duration) {
90-
$Duration = "--duration={0}" -f $using:Duration
91-
}
92-
else {
93-
$Duration = $null
94-
}
95-
96-
$command = 'wsl bbk_cli --out={0} --quiet {1}' -f $Logfile.Name, $Duration
97-
Invoke-Expression $command
98-
$Latency, $Download, $Upload, $null = (Get-Content $Logfile.FullName -Last 1) -split (' ')
99-
[PSCustomObject]@{
100-
Latency = [int][math]::Round($Latency,0)
101-
Download = [int][math]::Round($Download,0)
102-
Upload = [int][math]::Round($Upload,0)
103-
ExecutionTime = $null #[int][math]::Round($ExecutionTime.TotalMilliseconds,0)
104-
}
105-
}
106-
Write-Verbose ($command | Out-String)
10781
$ExecutionTime = Measure-Command {
108-
#Invoke-Expression $command
109-
[securestring]$Password = ConvertTo-SecureString $env:prtg_windowspassword -AsPlainText -Force
110-
[pscredential]$Credential = New-Object System.Management.Automation.PSCredential ($env:prtg_windowsuser, $Password)
111-
$Result = Invoke-Command -ComputerName $Computer -ScriptBlock $command -Credential $Credential
82+
$Result = Invoke-Command -ComputerName $Computer -command {docker run --rm --name prtg_bbk klaspihl/bbk_json:latest} | ConvertFrom-Json | Select-Object *,ExecutionTime
11283
}
11384
$Result.ExecutionTime=[int][math]::Round($ExecutionTime.TotalMilliseconds,0)
11485

115-
86+
write-verbose $result
11687
#region PRTG output
11788
$Output = [PSCustomObject]@{
11889
prtg = [PSCustomObject]@{
11990
result =
12091
[PSCustomObject]@{
12192
Channel = 'Download'
12293
Float = 0
123-
Value = $Result.Download
94+
Value = [int][math]::Round($Result.Download,0)
12495
LimitMode = 1
12596
LimitMinError = "100"
12697
CustomUnit = 'MB/s'
12798
},
12899
[PSCustomObject]@{
129100
Channel = 'Upload'
130101
Float = 0
131-
Value = $Result.Upload
102+
Value = [int][math]::Round($Result.Upload,0)
132103
LimitMode = 1
133104
LimitMinError = "100"
134105
CustomUnit = 'MB/s'
@@ -139,12 +110,12 @@ try {
139110
Value = $Result.ExecutionTime
140111
CustomUnit = 'ms'
141112
LimitMode = 1
142-
LimitMaxError = 30000
113+
LimitMaxError = 15000
143114
},
144115
[PSCustomObject]@{
145116
Channel = "Latency"
146117
Float = 0
147-
Value = $Result.Latency
118+
Value = [int][math]::Round($Result.Latency,0)
148119
CustomUnit = 'ms'
149120
LimitMode = 1
150121
LimitMaxError = 50

0 commit comments

Comments
 (0)