mirror of
https://github.com/ranl/monitor-utils.git
synced 2026-02-05 22:55:17 +01:00
splitting IT project
This commit is contained in:
64
cacti/flexlmMonitor/flexlm-feature-monitor.py
Executable file
64
cacti/flexlmMonitor/flexlm-feature-monitor.py
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Info
|
||||
# parses lmstat utility to get license usage of a specific feature
|
||||
|
||||
# Modules
|
||||
import subprocess
|
||||
import re
|
||||
import sys
|
||||
import os.path
|
||||
|
||||
# Settings
|
||||
lmutil = os.path.dirname(sys.argv[0])
|
||||
|
||||
# Validate settings
|
||||
if len(sys.argv) != 4 :
|
||||
print "Syntax error"
|
||||
print sys.argv[0] + ' [port] [server name] [feature]'
|
||||
quit(3)
|
||||
if os.path.isfile(lmutil) == False :
|
||||
print 'The lmutil binary ' + lmutil + ' does not exists'
|
||||
quit(3)
|
||||
|
||||
# Vars
|
||||
port = sys.argv[1]
|
||||
server = sys.argv[2]
|
||||
feature = sys.argv[3]
|
||||
errorString = re.escape('Users of ' + feature + ': (Error:')
|
||||
|
||||
# Initiate lmstat
|
||||
lmstat = subprocess.Popen([lmutil, 'lmstat' , '-c', port+'@'+server, '-f', feature], shell=False, stdout=subprocess.PIPE, stderr=None, stdin=None)
|
||||
out = lmstat.communicate()[0].splitlines( )
|
||||
exitCode = lmstat.returncode
|
||||
line2Parse = None
|
||||
|
||||
# If an erroe occured -> out
|
||||
if exitCode != 0 :
|
||||
for line in out : print line
|
||||
quit(1)
|
||||
|
||||
# search for the data in stdout
|
||||
for i in range(len(out)):
|
||||
if re.search(re.escape(feature), out[i]) :
|
||||
line2Parse = out[i]
|
||||
break
|
||||
|
||||
# Make sure stdout is valid
|
||||
if line2Parse == None :
|
||||
print 'Can not find feature \"' + feature + '\" in host ' + port+'@'+server
|
||||
quit(1)
|
||||
elif re.search(errorString, line2Parse) :
|
||||
print 'Error in license server:'
|
||||
print line2Parse
|
||||
quit(1)
|
||||
|
||||
# Host is up & Data is valid
|
||||
# parse usage
|
||||
usage = re.findall(r' \d\d* ', line2Parse)
|
||||
total = usage[len(usage)-2].strip()
|
||||
used = usage[len(usage)-1].strip()
|
||||
|
||||
# Output usage
|
||||
sys.stdout.write('total:'+total + ' ' + 'used:' + used)
|
||||
quit(0);
|
||||
BIN
cacti/flexlmMonitor/lmutil
Executable file
BIN
cacti/flexlmMonitor/lmutil
Executable file
Binary file not shown.
70
cacti/oge-jobs.py
Executable file
70
cacti/oge-jobs.py
Executable file
@@ -0,0 +1,70 @@
|
||||
#!/bin/env python
|
||||
|
||||
# Info
|
||||
# Check via the qhost command the number a running jobs on a specific execution host
|
||||
#
|
||||
# Settings
|
||||
# 1. set the gridSettings variable
|
||||
# 2. queues can be excluded by settings the excludeQueues list
|
||||
# 3. the cacti server needs to be configured as the submit host (qconf -as CACTISERVER)
|
||||
|
||||
# Modules
|
||||
import subprocess
|
||||
import re
|
||||
import string
|
||||
import sys
|
||||
|
||||
# Exclude function
|
||||
def isInList(string, dst) :
|
||||
res = False
|
||||
for i in range(len(dst)):
|
||||
if string == dst[i]:
|
||||
res = True
|
||||
break
|
||||
return res
|
||||
|
||||
|
||||
# Settings
|
||||
gridSettings = '/path/to/common/settings.sh'
|
||||
excludeQueues = []
|
||||
|
||||
# Validate command arguments
|
||||
if len(sys.argv) != 2:
|
||||
print "Syntax error"
|
||||
print sys.argv[0] + ' [execHost]'
|
||||
quit(1)
|
||||
|
||||
# Vars
|
||||
execHost = sys.argv[1]
|
||||
execHostEscaped = ''
|
||||
foundExecHost = False
|
||||
jobsCounter = 0
|
||||
|
||||
# Initiate qhost -q
|
||||
qhost = subprocess.Popen('source ' + gridSettings + '; ' + 'qhost -q', shell=True, stdout=subprocess.PIPE, stderr=None, stdin=None)
|
||||
out = qhost.communicate()[0].splitlines( )
|
||||
exitCode = qhost.returncode
|
||||
|
||||
# If an error occured -> quit
|
||||
if exitCode != 0 :
|
||||
for line in out : print line
|
||||
quit(1)
|
||||
|
||||
# Parse out
|
||||
execHostEscaped = re.escape(execHost) + ' '
|
||||
for i in range(len(out)):
|
||||
if foundExecHost and re.search('^ ' ,out[i]) :
|
||||
if not isInList(out[i].split()[0], excludeQueues):
|
||||
jobsCounter += int(string.split(out[i].split()[2],'/')[0])
|
||||
elif foundExecHost and re.search('^\w' ,out[i]) :
|
||||
break
|
||||
else :
|
||||
if re.search(execHostEscaped, out[i]) :
|
||||
foundExecHost = True
|
||||
|
||||
# Print Result
|
||||
if foundExecHost :
|
||||
sys.stdout.write('jobs:'+str(jobsCounter))
|
||||
else :
|
||||
sys.stdout.write('-1')
|
||||
quit(1)
|
||||
53
cacti/oge-queue.py
Executable file
53
cacti/oge-queue.py
Executable file
@@ -0,0 +1,53 @@
|
||||
#!/bin/env python
|
||||
|
||||
# Info:
|
||||
# Get queue usage via qstat -g c command
|
||||
# Note: it will exclude host in error/disable hosts
|
||||
#
|
||||
# Settings:
|
||||
# add the cacti server as submit host
|
||||
# set the gridSettings variable
|
||||
|
||||
# Modules
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# Settings
|
||||
gridSettings = '/path/to/common/settings.sh'
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print "Syntax error"
|
||||
print sys.argv[0] + ' [full queue name]'
|
||||
quit(1)
|
||||
|
||||
# Vars
|
||||
queue = sys.argv[1]
|
||||
jobsCounter = 0
|
||||
foundQueue = False
|
||||
running = 0
|
||||
total = 0
|
||||
|
||||
# Initiate qstat -g c
|
||||
qstat = subprocess.Popen('source ' + gridSettings + '; ' + 'qstat -g c', shell=True, stdout=subprocess.PIPE, stderr=None, stdin=None)
|
||||
out = qstat.communicate()[0].splitlines( )
|
||||
exitCode = qstat.returncode
|
||||
|
||||
# If an error occured -> out
|
||||
if exitCode != 0 :
|
||||
for line in out : print line
|
||||
quit(1)
|
||||
|
||||
# Parse out
|
||||
for i in range(len(out)):
|
||||
queueInfo = out[i].split()
|
||||
if queueInfo[0] == queue:
|
||||
foundQueue = True
|
||||
total = int(queueInfo[2]) + int(queueInfo[4])
|
||||
running = int(queueInfo[2])
|
||||
|
||||
# Print Result
|
||||
if foundQueue :
|
||||
sys.stdout.write('total:'+str(total) + ' ' + 'running:'+str(running))
|
||||
else :
|
||||
sys.stdout.write('-1')
|
||||
quit(1)
|
||||
Reference in New Issue
Block a user