File: //lib/fm-agent/plugins/jboss.py
import agent_util
import logging
from agent_util import float
logger = logging.getLogger(__name__)
def check_for_curl_installation():
result = agent_util.which("curl")
if result != "None":
return True
return False
def execute_query(config, query, data=None):
if "username" in config:
username = config["username"] + ":"
else:
username = ""
if "password" in config and config["password"].strip():
password = config["password"].strip() + "@"
else:
password = ""
url = config["console_url"].replace("://", "://" + username + password)
# JBoss API does not handle a double-/ well
url.rstrip("/")
if check_for_curl_installation():
queryType = "curl --digest --silent"
else:
queryType = "wget -qO-"
if data != None:
query = query % (queryType, url, data)
else:
query = query % (queryType, url)
ret, output = agent_util.execute_command(query)
return str(output)
class JBossPlugin(agent_util.Plugin):
textkey = "jboss"
label = "JBoss"
@classmethod
def get_metadata(self, config):
status = agent_util.SUPPORTED
msg = None
# check for jboss configuration block
if (
"username" not in config
or "console_url" not in config
or "password" not in config
):
self.log.info("jboss is not configured")
status = agent_util.MISCONFIGURED
msg = "jboss is not configured properly"
return {}
# check if jboss is even installed or running - any response to server-state is enough to pass here
query = '%s "%s/management?operation=attribute&name=server-state"'
output = execute_query(config, query)
if config.get("debug", False):
self.log.debug("#####################################################")
self.log.debug("Jboss command '%s' output:" % query)
self.log.debug(str(output))
self.log.debug("#####################################################")
if output.strip() == "":
self.log.info("jboss is not running or installed")
status = agent_util.UNSUPPORTED
msg = "jboss not found"
return {}
source_options = []
query = (
'%s "%s/management/subsystem/datasources?read-resource'
'&include-runtime=true&recursive&json.pretty"'
)
output = execute_query(config, query)
if config.get("debug", False):
self.log.debug("#####################################################")
self.log.debug("Jboss command '%s' output:" % query)
self.log.debug(str(output))
self.log.debug("#####################################################")
json_output = agent_util.json_loads(output)
for children in json_output["data-source"]:
if children not in source_options:
source_options.append(children)
if status is agent_util.SUPPORTED and not source_options:
status = agent_util.MISCONFIGURED
msg = "No data-source found on JBoss server."
data = {
"jdbc.prepared_statement_cache_access_count": {
"label": "Prepared statement cache access",
"options": source_options,
"status": status,
"error_message": msg,
},
"jdbc.prepared_statement_cache_add_count": {
"label": "Prepared statement cache add",
"options": source_options,
"status": status,
"error_message": msg,
},
"jdbc.prepared_statement_cache_current_size": {
"label": "Prepared statement cache current size",
"options": source_options,
"status": status,
"error_message": msg,
},
"jdbc.prepared_statement_cache_delete_count": {
"label": "Prepared statement cache delete",
"options": source_options,
"status": status,
"error_message": msg,
},
"jdbc.prepared_statement_cache_hit_count": {
"label": "Prepared statement cache hit",
"options": source_options,
"status": status,
"error_message": msg,
},
"jdbc.prepared_statement_cache_miss_count": {
"label": "Prepared statement cache miss",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.active_count": {
"label": "Pool active count",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.available_count": {
"label": "Pool available count",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.average_blocking_time": {
"label": "Pool average blocking time",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.average_creation_time": {
"label": "Pool average creation time",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.created_count": {
"label": "Pools created",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.destroyed_count": {
"label": "Pools destroyed",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.max_creation_time": {
"label": "Pools max creation time",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.max_used_count": {
"label": "Pools max used count",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.max_wait_time": {
"label": "Pools max wait time",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.timed_out": {
"label": "Pools timed out",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.total_blocking_time": {
"label": "Pools total blocking time",
"options": source_options,
"status": status,
"error_message": msg,
},
"pool.TotalCreationTime": {
"label": "Pools total creation time",
"options": source_options,
"status": status,
"error_message": msg,
},
"idle_timeout_minutes": {
"label": "Time spend for idle pools to be timeout",
"options": source_options,
"status": status,
"error_message": msg,
},
"jvm.heap.used": {
"label": "Total heap memory used",
"options": None,
"status": status,
"error_message": msg,
"unit": "MB",
},
"jvm.heap.committed": {
"label": "Total heap memory committed",
"options": None,
"status": status,
"error_message": msg,
"unit": "MB",
},
"jvm.nonheap.used": {
"label": "Total non-heap memory used",
"options": None,
"status": status,
"error_message": msg,
"unit": "MB",
},
"jvm.nonheap.committed": {
"label": "Total non-heap memory committed",
"options": None,
"status": status,
"error_message": msg,
"unit": "MB",
},
"jvm.threads.live": {
"label": "Total number of live threads used",
"options": None,
"status": status,
"error_message": msg,
},
"jvm.threads.daemon": {
"label": "Number of daemon threads used",
"options": None,
"status": status,
"error_message": msg,
},
}
return data
def check(self, textkey, data, config):
if textkey.split(".")[0] in ["jbc", "pool", "idle_timeout_minutes"]:
query = (
'%s "%s/management/subsystem/datasources/data-source/%s/statistics'
'?read-resource&include-runtime=true&recursive&json.pretty"'
)
json_output = execute_query(config, query, data)
data = agent_util.json_loads(json_output)
if textkey == "jdbc.prepared_statement_cache_access_count":
val = data["statistics"]["jdbc"]["PreparedStatementCacheAccessCount"]
elif textkey == "jdbc.prepared_statement_cache_add_count":
val = data["statistics"]["jdbc"]["PreparedStatementCacheAddCount"]
elif textkey == "jdbc.prepared_statement_cache_current_size":
val = data["statistics"]["jdbc"]["PreparedStatementCacheCurrentSize"]
elif textkey == "jdbc.prepared_statement_cache_delete_count":
val = data["statistics"]["jdbc"]["PreparedStatementCacheDeleteCount"]
elif textkey == "jdbc.prepared_statement_cache_hit_count":
val = data["statistics"]["jdbc"]["PreparedStatementCacheHitCount"]
elif textkey == "jdbc.prepared_statement_cache_miss_count":
val = data["statistics"]["jdbc"]["PreparedStatementCacheMissCount"]
elif textkey == "pool.active_count":
val = data["statistics"]["pool"]["ActiveCount"]
elif textkey == "pool.available_count":
val = data["statistics"]["pool"]["AvailableCount"]
elif textkey == "pool.average_blocking_time":
val = data["statistics"]["pool"]["AverageBlockingTime"]
elif textkey == "pool.average_creation_time":
val = data["statistics"]["pool"]["AverageCreationTime"]
elif textkey == "pool.created_count":
val = data["statistics"]["pool"]["CreatedCount"]
elif textkey == "pool.destroyed_count":
val = data["statistics"]["pool"]["DestroyedCount"]
elif textkey == "pool.max_creation_time":
val = data["statistics"]["pool"]["MaxCreationTime"]
elif textkey == "pool.max_used_count":
val = data["statistics"]["pool"]["MaxUsedCount"]
elif textkey == "pool.max_wait_time":
val = data["statistics"]["pool"]["MaxWaitTime"]
elif textkey == "pool.timed_out":
val = data["statistics"]["pool"]["TimedOut"]
elif textkey == "pool.total_blocking_time":
val = data["statistics"]["pool"]["TotalBlockingTime"]
elif textkey == "pool.TotalCreationTime":
val = data["statistics"]["pool"]["TotalCreationTime"]
elif textkey == "idle_timeout_minutes":
val = data["statistics"]["idle-timeout-minutes"]
else:
val = 0
elif textkey.split(".")[0] in ["jvm"]:
query = (
'%s "%s/management/core-service/platform-mbean'
'?read-attribute&recursive&json.pretty"'
)
json_output = execute_query(config, query, data)
data = agent_util.json_loads(json_output)
heap_used_total = 0
heap_committed_total = 0
non_heap_used_total = 0
non_heap_committed_total = 0
if textkey.split(".")[1] in ["heap", "nonheap"]:
data = data["type"]["memory-pool"]
for name, value in data["name"].items():
if value["type"] == "HEAP":
heap_used_total += value["usage"]["used"]
heap_committed_total += value["usage"]["committed"]
elif value["type"] == "NON_HEAP":
non_heap_used_total += value["usage"]["used"]
non_heap_committed_total += value["usage"]["committed"]
elif textkey.split(".")[1] in ["threads"]:
data = data["type"]["threading"]
conversion = 1024**2
if textkey == "jvm.heap.used":
val = heap_used_total / conversion
elif textkey == "jvm.heap.committed":
val = heap_committed_total / conversion
elif textkey == "jvm.nonheap.used":
val = non_heap_used_total / conversion
elif textkey == "jvm.nonheap.committed":
val = non_heap_committed_total / conversion
elif textkey == "jvm.threads.live":
val = data["thread-count"]
elif textkey == "jvm.threads.daemon":
val = data["daemon-thread-count"]
else:
val = 0
else:
val = 0
if not val:
return 0.0
return float(val)