-
Notifications
You must be signed in to change notification settings - Fork 16
/
veeam-stats.ps1
298 lines (251 loc) · 10.9 KB
/
veeam-stats.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
<#
.SYNOPSIS
PRTG Veeam Advanced Sensor
.DESCRIPTION
Advanced Sensor will Report Statistics about Backups during last 24 Hours and Actual Repository usage. It will then convert them into JSON, ready to add into InfluxDB and show it with Grafana
.Notes
NAME: veeam-stats.ps1
ORIGINAL NAME: PRTG-VeeamBRStats.ps1
LASTEDIT: 22/01/2018
VERSION: 0.3
KEYWORDS: Veeam, PRTG
.Link
http://mycloudrevolution.com/
Minor Edits and JSON output for Grafana by https://jorgedelacruz.es/
Minor Edits from JSON to Influx for Grafana by r4yfx
#Requires PS -Version 3.0
#Requires -Modules VeeamPSSnapIn
#>
[cmdletbinding()]
param(
[Parameter(Position=0, Mandatory=$false)]
[string] $BRHost = "veeam",
[Parameter(Position=1, Mandatory=$false)]
$reportMode = "24", # Weekly, Monthly as String or Hour as Integer
[Parameter(Position=2, Mandatory=$false)]
$repoCritical = 10,
[Parameter(Position=3, Mandatory=$false)]
$repoWarn = 20
)
# You can find the original code for PRTG here, thank you so much Markus Kraus - https://github.com/mycloudrevolution/Advanced-PRTG-Sensors/blob/master/Veeam/PRTG-VeeamBRStats.ps1
# Big thanks to Shawn, creating a awsome Reporting Script:
# http://blog.smasterson.com/2016/02/16/veeam-v9-my-veeam-report-v9-0-1/
#region: Start Load VEEAM Snapin (if not already loaded)
if (!(Get-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue)) {
if (!(Add-PSSnapin -PassThru VeeamPSSnapIn)) {
# Error out if loading fails
Write-Error "`nERROR: Cannot load the VEEAM Snapin."
Exit
}
}
#endregion
#region: Functions
Function Get-vPCRepoInfo {
[CmdletBinding()]
param (
[Parameter(Position=0, ValueFromPipeline=$true)]
[PSObject[]]$Repository
)
Begin {
$outputAry = @()
Function Build-Object {param($name, $repohost, $path, $free, $total)
$repoObj = New-Object -TypeName PSObject -Property @{
Target = $name
RepoHost = $repohost
Storepath = $path
StorageFree = [Math]::Round([Decimal]$free/1GB,2)
StorageTotal = [Math]::Round([Decimal]$total/1GB,2)
FreePercentage = [Math]::Round(($free/$total)*100)
}
Return $repoObj | Select Target, RepoHost, Storepath, StorageFree, StorageTotal, FreePercentage
}
}
Process {
Foreach ($r in $Repository) {
# Refresh Repository Size Info
[Veeam.Backup.Core.CBackupRepositoryEx]::SyncSpaceInfoToDb($r, $true)
If ($r.HostId -eq "00000000-0000-0000-0000-000000000000") {
$HostName = ""
}
Else {
$HostName = $($r.GetHost()).Name.ToLower()
}
$outputObj = Build-Object $r.Name $Hostname $r.Path $r.info.CachedFreeSpace $r.Info.CachedTotalSpace
}
$outputAry += $outputObj
}
End {
$outputAry
}
}
#endregion
#region: Start BRHost Connection
$OpenConnection = (Get-VBRServerSession).Server
if($OpenConnection -eq $BRHost) {
} elseif ($OpenConnection -eq $null ) {
Connect-VBRServer -Server $BRHost
} else {
Disconnect-VBRServer
Connect-VBRServer -Server $BRHost
}
$NewConnection = (Get-VBRServerSession).Server
if ($NewConnection -eq $null ) {
Write-Error "`nError: BRHost Connection Failed"
Exit
}
#endregion
#region: Convert mode (timeframe) to hours
If ($reportMode -eq "Monthly") {
$HourstoCheck = 720
} Elseif ($reportMode -eq "Weekly") {
$HourstoCheck = 168
} Else {
$HourstoCheck = $reportMode
}
#endregion
#region: Collect and filter Sessions
# $vbrserverobj = Get-VBRLocalhost # Get VBR Server object
# $viProxyList = Get-VBRViProxy # Get all Proxies
$repoList = Get-VBRBackupRepository # Get all Repositories
$allSesh = Get-VBRBackupSession # Get all Sessions (Backup/BackupCopy/Replica)
# $allResto = Get-VBRRestoreSession # Get all Restore Sessions
$seshListBk = @($allSesh | ?{($_.CreationTime -ge (Get-Date).AddHours(-$HourstoCheck)) -and $_.JobType -eq "Backup"}) # Gather all Backup sessions within timeframe
$seshListBkc = @($allSesh | ?{($_.CreationTime -ge (Get-Date).AddHours(-$HourstoCheck)) -and $_.JobType -eq "BackupSync"}) # Gather all BackupCopy sessions within timeframe
$seshListRepl = @($allSesh | ?{($_.CreationTime -ge (Get-Date).AddHours(-$HourstoCheck)) -and $_.JobType -eq "Replica"}) # Gather all Replication sessions within timeframe
#endregion
#region: Collect Jobs
# $allJobsBk = @(Get-VBRJob | ? {$_.JobType -eq "Backup"}) # Gather Backup jobs
# $allJobsBkC = @(Get-VBRJob | ? {$_.JobType -eq "BackupSync"}) # Gather BackupCopy jobs
# $repList = @(Get-VBRJob | ?{$_.IsReplica}) # Get Replica jobs
#endregion
#region: Get Backup session informations
$totalxferBk = 0
$totalReadBk = 0
$seshListBk | %{$totalxferBk += $([Math]::Round([Decimal]$_.Progress.TransferedSize/1GB, 0))}
$seshListBk | %{$totalReadBk += $([Math]::Round([Decimal]$_.Progress.ReadSize/1GB, 0))}
#endregion
#region: Preparing Backup Session Reports
$successSessionsBk = @($seshListBk | ?{$_.Result -eq "Success"})
$warningSessionsBk = @($seshListBk | ?{$_.Result -eq "Warning"})
$failsSessionsBk = @($seshListBk | ?{$_.Result -eq "Failed"})
$runningSessionsBk = @($allSesh | ?{$_.State -eq "Working" -and $_.JobType -eq "Backup"})
$failedSessionsBk = @($seshListBk | ?{($_.Result -eq "Failed") -and ($_.WillBeRetried -ne "True")})
#endregion
#region: Preparing Backup Copy Session Reports
$successSessionsBkC = @($seshListBkC | ?{$_.Result -eq "Success"})
$warningSessionsBkC = @($seshListBkC | ?{$_.Result -eq "Warning"})
$failsSessionsBkC = @($seshListBkC | ?{$_.Result -eq "Failed"})
$runningSessionsBkC = @($allSesh | ?{$_.State -eq "Working" -and $_.JobType -eq "BackupSync"})
$IdleSessionsBkC = @($allSesh | ?{$_.State -eq "Idle" -and $_.JobType -eq "BackupSync"})
$failedSessionsBkC = @($seshListBkC | ?{($_.Result -eq "Failed") -and ($_.WillBeRetried -ne "True")})
#endregion
#region: Preparing Replicatiom Session Reports
$successSessionsRepl = @($seshListRepl | ?{$_.Result -eq "Success"})
$warningSessionsRepl = @($seshListRepl | ?{$_.Result -eq "Warning"})
$failsSessionsRepl = @($seshListRepl | ?{$_.Result -eq "Failed"})
$runningSessionsRepl = @($allSesh | ?{$_.State -eq "Working" -and $_.JobType -eq "Replica"})
$failedSessionsRepl = @($seshListRepl | ?{($_.Result -eq "Failed") -and ($_.WillBeRetried -ne "True")})
$RepoReport = $repoList | Get-vPCRepoInfo | Select @{Name="Repository Name"; Expression = {$_.Target}},
@{Name="Host"; Expression = {$_.RepoHost}},
@{Name="Path"; Expression = {$_.Storepath}},
@{Name="Free (GB)"; Expression = {$_.StorageFree}},
@{Name="Total (GB)"; Expression = {$_.StorageTotal}},
@{Name="Free (%)"; Expression = {$_.FreePercentage}},
@{Name="Status"; Expression = {
If ($_.FreePercentage -lt $repoCritical) {"Critical"}
ElseIf ($_.FreePercentage -lt $repoWarn) {"Warning"}
ElseIf ($_.FreePercentage -eq "Unknown") {"Unknown"}
Else {"OK"}}} | `
Sort "Repository Name"
#endregion
#region: Number of Endpoints
$number_endpoints = 0
foreach ($endpoint in Get-VBREPJob ) {
$number_endpoints++;
}
#endregion
#region: Influxdb Output for Telegraf
$Count = $successSessionsBk.Count
$body="veeam-stats successfulbackups=$Count"
Write-Host $body
$Count = $warningSessionsBk.Count
$body="veeam-stats warningbackups=$Count"
Write-Host $body
$Count = $failsSessionsBk.Count
$body="veeam-stats failesbackups=$Count"
Write-Host $body
$Count = $failedSessionsBk.Count
$body="veeam-stats failedbackups=$Count"
Write-Host $body
$Count = $runningSessionsBk.Count
$body="veeam-stats runningbackups=$Count"
Write-Host $body
$Count = $successSessionsBkC.Count
$body="veeam-stats successfulbackupcopys=$Count"
Write-Host $body
$Count = $warningSessionsBkC.Count
$body="veeam-stats warningbackupcopys=$Count"
Write-Host $body
$Count = $failsSessionsBkC.Count
$body="veeam-stats failesbackupcopys=$Count"
Write-Host $body
$Count = $failedSessionsBkC.Count
$body="veeam-stats failedbackupcopys=$Count"
Write-Host $body
$Count = $runningSessionsBkC.Count
$body="veeam-stats runningbackupcopys=$Count"
Write-Host $body
$Count = $IdleSessionsBkC.Count
$body="veeam-stats idlebackupcopys=$Count"
Write-Host $body
$Count = $successSessionsRepl.Count
$body="veeam-stats successfulreplications=$Count"
Write-Host $body
$Count = $warningSessionsRepl.Count
$body="veeam-stats warningreplications=$Count"
Write-Host $body
$Count = $failsSessionsRepl.Count
$body="veeam-stats failesreplications=$Count"
Write-Host $body
$Count = $failedSessionsRepl.Count
$body="veeam-stats failedreplications=$Count"
Write-Host $body
$body="veeam-stats totalbackuptransfer=$totalxferBk"
foreach ($Repo in $RepoReport){
$Name = "REPO " + $Repo."Repository Name" -replace '\s','_'
$Free = $Repo."Free (%)"
$body="veeam-stats $Name=$Free"
Write-Host $body
}
$body="veeam-stats protectedendpoints=$number_endpoints"
Write-Host $body
$body="veeam-stats totalbackupread=$totalReadBk"
Write-Host $body
$Count = $runningSessionsRepl.Count
$body="veeam-stats runningreplications=$Count"
Write-Host $body
#endregion
#region: Debug
if ($DebugPreference -eq "Inquire") {
$RepoReport | ft * -Autosize
$SessionObject = [PSCustomObject] @{
"Successful Backups" = $successSessionsBk.Count
"Warning Backups" = $warningSessionsBk.Count
"Failes Backups" = $failsSessionsBk.Count
"Failed Backups" = $failedSessionsBk.Count
"Running Backups" = $runningSessionsBk.Count
"Warning BackupCopys" = $warningSessionsBkC.Count
"Failes BackupCopys" = $failsSessionsBkC.Count
"Failed BackupCopys" = $failedSessionsBkC.Count
"Running BackupCopys" = $runningSessionsBkC.Count
"Idle BackupCopys" = $IdleSessionsBkC.Count
"Successful Replications" = $successSessionsRepl.Count
"Warning Replications" = $warningSessionsRepl.Count
"Failes Replications" = $failsSessionsRepl.Count
"Failed Replications" = $failedSessionsRepl.Count
"Running Replications" = $RunningSessionsRepl.Count
}
$SessionResport += $SessionObject
$SessionResport
}
#endregion