Skip to content

Commit

Permalink
historical windows uptime calculator (#300)
Browse files Browse the repository at this point in the history
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
lchapman4 and cristianciutea committed Nov 21, 2022
1 parent 2cd57f9 commit e0ba649
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/windows/GetUpTimeFromSystemLogPastDay.ps1
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
}"
10 changes: 10 additions & 0 deletions examples/windows/windows-historical-uptime.yml
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

0 comments on commit e0ba649

Please sign in to comment.