-
Notifications
You must be signed in to change notification settings - Fork 10
/
example.ps1
25 lines (20 loc) · 1.15 KB
/
example.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ErrorActionPreference = "Stop"
Import-Module .\PrometheusExporter
$TotalConnections = New-MetricDescriptor -Name "rras_connections_total" -Type counter -Help "Total connections since server start"
$CurrentConnections = New-MetricDescriptor -Name "rras_connections" -Type gauge -Help "Current established connections" -Labels "protocol"
function collector () {
$RRASConnections = Get-RemoteAccessConnectionStatistics
$TotalCurrent = $RRASConnections.count
$IKEv2 = @($RRASConnections | Where-Object { $_.TunnelType -eq "Ikev2" }).count
$SSTP = @($RRASConnections | Where-Object { $_.TunnelType -eq "Sstp" }).count
$Cumulative = (Get-RemoteAccessConnectionStatisticsSummary).TotalCumulativeConnections
@(
New-Metric -MetricDesc $TotalConnections -Value $Cumulative
New-Metric -MetricDesc $CurrentConnections -Value $TotalCurrent -Labels ("all")
New-Metric -MetricDesc $CurrentConnections -Value $IKEv2 -Labels ("ikev2")
New-Metric -MetricDesc $CurrentConnections -Value $SSTP -Labels ("sstp")
)
}
$exp = New-PrometheusExporter -Port 9700
Register-Collector -Exporter $exp -Collector $Function:collector
$exp.Start()