-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-MemStats.ps1
30 lines (23 loc) · 984 Bytes
/
Get-MemStats.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
$compname = $env:COMPUTERNAME.tolower()
$wmiOs = Get-WmiObject -Class Win32_OperatingSystem
[int]$freeMemory = 0 + $wmiOs.freephysicalmemory
[int]$totalMemory = 0 + $wmiOs.totalvisiblememorysize
[int]$memoryUsage = ($totalMemory - $freeMemory) / $totalMemory * 100
## Set the Graphite carbon server location and port number
$carbonServer = "graphite.cat.pdx.edu"
$carbonServerPort = 2003
#Get Unix epoch Time
$epochTime=[int](Get-Date -UFormat "%s") + 28800
## Formatted for Graphite
$graphiteString = ("wintel.terminal_server.${compname}_ds_cecs_pdx_edu.loadpercent.memory " + $memoryUsage + " " + $epochTime)
# Stream results to the Carbon server
$socket = New-Object System.Net.Sockets.TCPClient
$socket.connect($carbonServer, $carbonServerPort)
$stream = $socket.GetStream()
$writer = New-Object System.IO.StreamWriter($stream)
#Write out metric to the stream.
$writer.WriteLine($graphiteString)
#Flush and write our metrics.
$writer.Flush()
$writer.Close()
$stream.Close()