forked from outlyerapp/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmssql.py
More file actions
executable file
·48 lines (41 loc) · 1.69 KB
/
Copy pathmssql.py
File metadata and controls
executable file
·48 lines (41 loc) · 1.69 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
46
47
#!/usr/bin/env python
import subprocess
import sys
import re
counters = ['\SQLServer:Access Methods\FreeSpace Scans/sec',
'\SQLServer:Access Methods\Full Scans/sec',
'\SQLServer:Buffer Manager\Buffer cache hit ratio',
'\SQLServer:Buffer Manager\Free pages',
'\SQLServer:Buffer Manager\Page life expectancy',
'\SQLServer:Latches\Total Latch Wait Time (ms)',
'\SQLServer:Locks(_Total)\Lock Timeouts/sec',
'\SQLServer:Locks(_Total)\Lock Wait Time (ms)',
'\SQLServer:Locks(_Total)\Number of Deadlocks/sec',
'\SQLServer:Memory Manager\Memory Grants Pending',
'\SQLServer:Memory Manager\Target Server Memory (KB)',
'\SQLServer:Memory Manager\Total Server Memory (KB)',
'\SQLServer:SQL Statistics\Batch Requests/sec',
'\SQLServer:SQL Statistics\SQL Re-Compilations/sec',
'\SQLServer:SQL Statistics\SQL Compilations/sec',
'\SQLServer:General Statistics\User Connections']
command = [r'c:\windows\system32\typeperf.exe', '-sc', '1']
try:
output = subprocess.check_output(command + counters)
except:
print "Plugin Failed!"
sys.exit(2)
s_counters = output.splitlines()[1].split(',')
perf_data = {}
i = 1
for s_counter in s_counters:
if 'PDH-CSV' not in s_counter:
metric = s_counter.rsplit('\\', 1)[1].strip('"').lower()
metric = re.sub('[^0-9a-zA-Z]+', '_', metric).strip('_')
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)