cocaine plugin
This commit is contained in:
parent
c5b954b1c6
commit
aad92b67be
66
plugins/cocaine/check_cocaine.py
Executable file
66
plugins/cocaine/check_cocaine.py
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from cox_check import *
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-s', '--host')
|
||||
args = parser.parse_args()
|
||||
if args.host:
|
||||
cocaine_tool = cocaine_tool + ' -h ' + args.host
|
||||
|
||||
|
||||
# Cocaine applications
|
||||
apps_array = get_apps()
|
||||
|
||||
# Runlists
|
||||
runlists_array = get_runlists()
|
||||
|
||||
apps_info = {}
|
||||
|
||||
# Get info about app
|
||||
for app_name in apps_array:
|
||||
apps_info[app_name] = get_app_info(app_name)
|
||||
|
||||
apps_status = {}
|
||||
|
||||
for app_name in apps_info:
|
||||
state = get_app_state(app_name)
|
||||
|
||||
if state == 'running':
|
||||
apps_status[app_name] = { '0': state }
|
||||
else:
|
||||
# Check production runlist
|
||||
runlist = get_runlist(runlists_array, app_name)
|
||||
if runlist == 'production':
|
||||
apps_status[app_name] = { '2': state }
|
||||
else:
|
||||
apps_status[app_name] = { '1': state }
|
||||
|
||||
crit_apps = []
|
||||
warn_apps = []
|
||||
for app in apps_status:
|
||||
for code in apps_status[app]:
|
||||
message = apps_status[app][code]
|
||||
if code == '2':
|
||||
crit_apps.append(app)
|
||||
if code == '1':
|
||||
warn_apps.append(app)
|
||||
|
||||
if len(crit_apps) == 0:
|
||||
pass
|
||||
else:
|
||||
print crit_apps
|
||||
sys.exit(2)
|
||||
|
||||
if len(warn_apps) == 0:
|
||||
pass
|
||||
else:
|
||||
print warn_apps
|
||||
sys.exit(1)
|
||||
|
||||
print "OK"
|
||||
sys.exit(0)
|
44
plugins/cocaine/cocaine_metrics.py
Executable file
44
plugins/cocaine/cocaine_metrics.py
Executable file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import time
|
||||
import socket
|
||||
from cox_check import get_apps, get_app_info, get_app_state
|
||||
|
||||
apps = get_apps()
|
||||
hostname = socket.getfqdn()
|
||||
|
||||
for app in apps:
|
||||
status = get_app_state(app)
|
||||
if status == 'running':
|
||||
info = get_app_info(app)
|
||||
print hostname + '.' + app + ".load-median " + str( info['apps'][app]['load-median'] ) + ' ' + str ( time.time() )
|
||||
print hostname + '.' + app + ".sessions.pending " + str( info['apps'][app]['sessions']['pending'] ) + ' ' + str ( time.time() )
|
||||
print hostname + '.' + app + ".queue.depth " + str( info['apps'][app]['queue']['depth'] ) + ' ' + str ( time.time() )
|
||||
print hostname + '.' + app + ".queue.capacity " + str( info['apps'][app]['queue']['capacity'] ) + ' ' + str ( time.time() )
|
||||
print hostname + '.' + app + ".slaves.active " + str( info['apps'][app]['slaves']['active'] ) + ' ' + str ( time.time() )
|
||||
print hostname + '.' + app + ".slaves.idle " + str( info['apps'][app]['slaves']['idle'] ) + ' ' + str ( time.time() )
|
||||
print hostname + '.' + app + ".slaves.capacity " + str( info['apps'][app]['slaves']['capacity'] ) + ' ' + str ( time.time() )
|
||||
|
||||
|
||||
#{
|
||||
# "apps": {
|
||||
# "js": {
|
||||
# "load-median": 0,
|
||||
# "profile": "default",
|
||||
# "sessions": {
|
||||
# "pending": 0
|
||||
# },
|
||||
# "queue": {
|
||||
# "depth": 0,
|
||||
# "capacity": 100
|
||||
# },
|
||||
# "state": "running",
|
||||
# "slaves": {
|
||||
# "active": 0,
|
||||
# "idle": 0,
|
||||
# "capacity": 10
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
#}
|
78
plugins/cocaine/cox_check.py
Executable file
78
plugins/cocaine/cox_check.py
Executable file
@ -0,0 +1,78 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import os
|
||||
import ast
|
||||
|
||||
cocaine_tool = '/usr/bin/cocaine-tool'
|
||||
|
||||
# Get applications array
|
||||
def get_apps():
|
||||
apps = get_cmd( cocaine_tool + ' app list' )
|
||||
apps_array = get_dict(apps)
|
||||
|
||||
return apps_array
|
||||
|
||||
|
||||
# Get runlists array
|
||||
def get_runlists():
|
||||
runlists = get_cmd( cocaine_tool + ' runlist list' )
|
||||
runlists_array = get_dict(runlists)
|
||||
|
||||
return runlists_array
|
||||
|
||||
|
||||
# Return dictionary of cocaine applicatio info
|
||||
def get_app_info(app_name):
|
||||
info = get_cmd( cocaine_tool + ' info -n ' + app_name )
|
||||
info_dict = get_dict(info)
|
||||
|
||||
return info_dict
|
||||
|
||||
|
||||
# Get application state
|
||||
def get_app_state(app_name):
|
||||
app_info = get_app_info(app_name)
|
||||
state = ''
|
||||
try:
|
||||
state = app_info['apps'][app_name]['state']
|
||||
except:
|
||||
state = 'not running'
|
||||
|
||||
return state
|
||||
|
||||
|
||||
# Get dictionary from string
|
||||
def get_dict(string):
|
||||
out_dict = ast.literal_eval(string)
|
||||
|
||||
return out_dict
|
||||
|
||||
|
||||
# Check runlis
|
||||
def get_runlist(runlists, app):
|
||||
for runlist in runlists:
|
||||
runlist_info = get_runlist_info(runlist)
|
||||
try:
|
||||
if runlist_info[app]:
|
||||
return runlist
|
||||
except:
|
||||
pass
|
||||
|
||||
return 'Not in runlist'
|
||||
|
||||
|
||||
# Get runlist info
|
||||
def get_runlist_info(runlist):
|
||||
info = get_cmd( cocaine_tool + ' runlist view -n ' + runlist )
|
||||
info_dict = get_dict(info)
|
||||
|
||||
return info_dict
|
||||
|
||||
|
||||
# Get shell command output
|
||||
def get_cmd(cmd):
|
||||
out = os.popen(cmd).read()
|
||||
|
||||
return out
|
||||
|
Loading…
Reference in New Issue
Block a user