-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
historical windows uptime calculator (#300)
custom powershell script to track historical uptime of windows per 24 hour period. Co-authored-by: Cristian Ciutea <cristi.ciutea@gmail.com>
- Loading branch information
1 parent
2cd57f9
commit e0ba649
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[timespan]$downTime = New-TimeSpan -start 0 -end 0 | ||
[timespan]$totalDownTime = New-TimeSpan -start 0 -end 0 | ||
Get-EventLog -LogName system | | ||
Where-Object ` | ||
{ $_.eventid -eq 6005 -OR $_.eventID -eq 6006 -AND $_.timegenerated -gt (get-date).adddays(-1) } | | ||
Sort-Object -Property timegenerated | | ||
Foreach-Object ` | ||
{ | ||
if ($_.EventID -eq 6006) | ||
{ | ||
$down = $_.TimeGenerated | ||
} #end if eventID | ||
Else | ||
{ | ||
$up = $_.TimeGenerated | ||
} #end else | ||
if($down -AND $up) | ||
{ | ||
if($down -ge $up) | ||
{ | ||
Write-Host -foregroundColor Red "*** Invalid data. Ignoring $($up)" | ||
$up = $down | ||
} #end if down is greater than up | ||
[timespan]$CurrentDownTime = new-TimeSpan -start $down -end $up | ||
[timeSpan]$TotalDownTime = $currentDownTime + $TotalDownTime | ||
$down = $up = $null | ||
} #end if down and up | ||
} #end foreach | ||
#"Total down time on $env:computername is:" | ||
#$TotaldownTime | ||
$minutesInMonth = (24*60)*30 | ||
$minutesInDay = 24*60 | ||
$downTimeMinutes = $TotaldownTime.TotalMinutes | ||
$percentUpTime = "{0:n2}" -f (100 - ($downTimeMinutes/$minutesInDay)*100) | ||
"{ | ||
""UptimePercent1Day"": $percentUptime | ||
}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
integrations: | ||
- name: nri-flex | ||
config: | ||
name: WindowsUptime | ||
apis: | ||
- event_type: systemUptime | ||
shell: powershell | ||
commands: | ||
- run: "C:/Program` Files/New` Relic/newrelic-infra/integrations.d/GetUpTimeFromSystemLogPastDay.ps1" | ||
timeout: 29000 |