forked from outlyerapp/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindows.py
More file actions
executable file
·45 lines (38 loc) · 1.35 KB
/
windows.py
File metadata and controls
executable file
·45 lines (38 loc) · 1.35 KB
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
#!/usr/bin/env python
import subprocess
import sys
import re
counters = ['\Memory\Available MBytes',
'\Memory\Pages/sec',
'\PhysicalDisk(_Total)\% Disk Time',
'\PhysicalDisk(_Total)\Current Disk Queue Length',
'\PhysicalDisk(_Total)\Disk Transfers/sec',
'\PhysicalDisk(_Total)\Disk Bytes/sec',
'\PhysicalDisk(_Total)\Disk Reads/sec',
'\PhysicalDisk(_Total)\Disk Writes/sec',
'\PhysicalDisk(_Total)\Avg. Disk sec/Read',
'\PhysicalDisk(_Total)\Avg. Disk sec/Write',
'\Processor(_Total)\% Processor Time',
'\Processor(_Total)\% Privileged Time',
'\System\Processor Queue Length',
'\System\Context Switches/sec']
command = [r'c:\windows\system32\typeperf.exe', '-sc', '1']
try:
output = subprocess.check_output(command + counters)
except:
print "Plugin Failed!"
sys.exit(2)
perf_data = {}
i = 1
for counter in counters:
metric = counter.split('\\')[2].lower()
metric = re.sub('[^0-9a-zA-Z]+', '_', metric)
metric = re.sub('(^[\W_]*)|([\W_]*$)', '', metric)
value = output.splitlines()[2].split(',')[i].replace('"','').strip()
perf_data[metric] = value
i += 1
response = "OK | "
for k, v in perf_data.iteritems():
response += k + '=' + v + ';;;; '
print response
sys.exit(0)