1
1
<#
2
2
. 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
4
4
5
5
6
6
. 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.
9
8
10
9
WSL and Linux distro must be accessable from the user session that is invoked by the custom sensor (PRTG Security context).
11
10
16
15
17
16
. NOTES
18
17
2023-04-11 Version 1 [email protected]
18
+ 2023-08-31 Version 2 using docker as application /[email protected]
19
19
. LINK
20
20
https://www.bredbandskollen.se/om/mer-om-bbk/bredbandskollen-cli/
21
21
. EXAMPLE
22
- . .\measure-bbk.ps1 -Duration 2 -Logfile "c:\temp\bbk.log" -Verbose
22
+ . .\measure-bbk.ps1
23
23
24
24
. PARAMETER Duration
25
25
Duration in seconds to measure
@@ -78,57 +78,28 @@ param (
78
78
)
79
79
$script :ErrorActionPreference = ' Stop'
80
80
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 )
107
81
$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
112
83
}
113
84
$Result.ExecutionTime = [int ][math ]::Round($ExecutionTime.TotalMilliseconds , 0 )
114
85
115
-
86
+ write-verbose $result
116
87
# region PRTG output
117
88
$Output = [PSCustomObject ]@ {
118
89
prtg = [PSCustomObject ]@ {
119
90
result =
120
91
[PSCustomObject ]@ {
121
92
Channel = ' Download'
122
93
Float = 0
123
- Value = $Result.Download
94
+ Value = [ int ][ math ]::Round( $Result.Download , 0 )
124
95
LimitMode = 1
125
96
LimitMinError = " 100"
126
97
CustomUnit = ' MB/s'
127
98
},
128
99
[PSCustomObject ]@ {
129
100
Channel = ' Upload'
130
101
Float = 0
131
- Value = $Result.Upload
102
+ Value = [ int ][ math ]::Round( $Result.Upload , 0 )
132
103
LimitMode = 1
133
104
LimitMinError = " 100"
134
105
CustomUnit = ' MB/s'
@@ -139,12 +110,12 @@ try {
139
110
Value = $Result.ExecutionTime
140
111
CustomUnit = ' ms'
141
112
LimitMode = 1
142
- LimitMaxError = 30000
113
+ LimitMaxError = 15000
143
114
},
144
115
[PSCustomObject ]@ {
145
116
Channel = " Latency"
146
117
Float = 0
147
- Value = $Result.Latency
118
+ Value = [ int ][ math ]::Round( $Result.Latency , 0 )
148
119
CustomUnit = ' ms'
149
120
LimitMode = 1
150
121
LimitMaxError = 50
0 commit comments