import agent_util
import os
metrics = {
#Work Manager Metrics
"work_manager": {
"type": "WorkManagerRuntime",
"metrics": {
"completed_requests": {
"label": "The number of requests that have been processed",
"property": "CompletedRequests"
},
"pending_requests": {
"label": "The number of waiting requests in the queue",
"property": "PendingRequests"
},
"stuck_thread_count": {
"label": "The number of threads that are considered to be stuck on the basis of any stuck thread constraints",
"property": "StuckThreadCount"
}
}
},
#JDBC Data Source Metrics
"jdbc_datasource": {
"type": "JDBCDataSourceRuntime",
"metrics": {
"active_connections_current_count": {
"label": "The number of connections currently in use by applications",
"property": "ActiveConnectionsCurrentCount"
}
}
},
#EJB Cache Metrics
"ejb_cache": {
"type": "EJBCacheRuntime",
"metrics": {
"activation_count": {
"label": "Work Manager: The total number of beans from this EJB Home that have been activated",
"property": "ActivationCount"
},
"cache_access_count": {
"label": "Work Manager: The total number of attempts to access a bean from the cache",
"property": "CacheAccessCount"
},
"cache_beans_current_count": {
"label": "Work Manager: The total number of beans from this EJB Home currently in the EJB cache",
"property": "CachedBeansCurrentCount"
},
"cache_hit_count": {
"label": "Work Manager: The total number of times an attempt to access a bean from the cache succeeded",
"property": "CacheHitCount"
},
"cache_miss_count": {
"label": "Work Manager: The total number of times an attempt to access a bean from the cache failed",
"property": "CacheMissCount"
},
"passivation_count": {
"label": "Work Manager: The total number of beans from this EJB Home that have been passivated",
"property": "PassivationCount"
}
}
},
#EJB Pool Metrics
"ejb_pool": {
"type": "EJBPoolRuntime",
"metrics": {
"access_total_count": {
"label": "EJB Pool: The total number of times an attempt was made to get an instance from the free pool",
"property": "AccessTotalCount"
},
"beans_in_use_count": {
"label": "EJB Pool: The total number of bean instances currently in use from the free pool",
"property": "BeansInUseCount"
},
"beans_in_use_current_count": {
"label": "EJB Pool: The number of bean instances currently being used from the free pool",
"property": "BeansInUseCurrentCount"
},
"destroyed_total_count": {
"label": "EJB Pool: The total number of times a bean instance from this pool was destroyed due to a non-application Exception being thrown from it",
"property": "DestroyedTotalCount"
},
"idle_beans_count": {
"label": "EJB Pool: The total number of available bean instances in the free pool",
"property": "IdleBeansCount"
},
"miss_total_count": {
"label": "EJB Pool: The total number of times a failed attempt was made to get an instance from the free pool",
"property": "MissTotalCount"
},
"pooled_beans_current_count": {
"label": "EJB Pool: The current number of available bean instances in the free pool",
"property": "PooledBeansCurrentCount"
},
"timeout_total_count": {
"label": "EJB Pool: The total number of Threads that have timed out waiting for an available bean instance from the free pool",
"property": "TimeoutTotalCount"
},
"waiter_current_count": {
"label": "EJB Pool: The number of Threads currently waiting for an available bean instance from the free pool",
"property": "WaiterCurrentCount"
},
"waiter_total_count": {
"label": "EJB Pool: The total number of Threads currently waiting for an available bean instance from the free pool",
"property": "WaiterTotalCount"
}
}
},
#EJB Transaction Metrics
"ejb_transaction": {
"type": "EJBTransactionRuntime",
"metrics": {
"transactions_committed_total_count": {
"label": "EJB Transaction: The total number of transactions that have been committed for this EJB",
"property": "TransactionsCommittedTotalCount"
},
"transactions_rolled_back_total_count": {
"label": "EJB Transaction: The total number of transactions that have been rolled back for this EJB",
"property": "TransactionsRolledBackTotalCount"
},
"transactions_timeout_total_count": {
"label": "EJB Transaction: The total number of transactions that have timed out for this EJB",
"property": "TransactionsTimedOutTotalCount"
}
}
},
#Executive Queue Metrics
"executive_queue": {
"type": "ExecuteQueueRuntime",
"metrics": {
"execute_thread_current_idle_count": {
"label": "Executive Queue: The number of idle threads assigned to the queue",
"property": "ExecuteThreadCurrentIdleCount"
},
"execute_thread_total_count": {
"label": "Executive Queue: The total number of execute threads assigned to the queue",
"property": "ExecuteThreadTotalCount"
},
"pending_request_current_count": {
"label": "Executive Queue: The number of waiting requests in the queue",
"property": "PendingRequestCurrentCount"
},
"pending_request_oldest_time": {
"label": "Executive Queue: The time since the longest waiting request was placed in the queue",
"property": "PendingRequestOldestTime"
},
"serviced_request_total_count": {
"label": "Executive Queue: The number of requests that have been processed by the queue",
"property": "ServicedRequestTotalCount"
}
}
},
#Servlet Metrics
"servlet": {
"type": "ServletRuntime",
"metrics": {
"execution_time_average": {
"label": "Servlet: The average amount of time all invocations of the servlet have executed since created",
"property": "ExecutionTimeAverage"
},
"execution_time_high": {
"label": "Servlet: The amount of time the single longest invocation of the servlet has executed since created",
"property": "ExecutionTimeHigh"
},
"execution_time_low": {
"label": "Servlet: The amount of time the single shortest invocation of the servlet has executed since created",
"property": "ExecutionTimeLow"
},
"execution_time_total": {
"label": "Servlet: The total amount of time all invocations of the servlet have executed since created",
"property": "ExecutionTimeTotal"
},
"invocation_total_count": {
"label": "Servlet: The total count of the times this servlet has been invoked",
"property": "InvocationTotalCount"
},
"pool_max_capacity": {
"label": "Servlet: The maximum capacity of this servlet for single thread model servlets",
"property": "PoolMaxCapacity"
},
"reload_total_count": {
"label": "Servlet: The total count of the number of times this servlet has been reloaded",
"property": "ReloadTotalCount"
}
}
},
#Web App Component Metrics
"web_app_component": {
"type": "WebAppComponentRuntime",
"metrics": {
"open_sessions_current_count": {
"label": "Web App Component: The current total number of open sessions in this module",
"property": "OpenSessionsCurrentCount"
},
"open_sessions_high_count": {
"label": "Web App Component: The high water mark of the total number of open sessions in this server",
"property": "OpenSessionsHighCount"
},
"sessions_opened_total_count": {
"label": "Web App Component: The total number of sessions opened",
"property": "SessionsOpenedTotalCount"
}
}
}
}
def get_metric(config, type, property=None):
set_env_command = ""
if 'wl_home' in config:
set_env_command = ("CLASSPATH=%s " % os.path.join(config['wl_home'], "server/lib/weblogic.jar"))
cmd = set_env_command + "java weblogic.Admin"
if "username" in config: cmd += " -username %s" % config["username"]
if "password" in config and config["password"].strip(): cmd += " -password %s" % config["password"].strip()
cmd += " GET -pretty -type %s" % type
if property: cmd += " -property %s" % property
status, output = agent_util.execute_command(cmd)
if status != 0: raise Exception(output)
output = output.strip().split("\n")[-1]
if not property:
if output == "No MBeans found": raise Exception(output)
else: return output
else:
parsed_output = output[output.index(":") + 1:].strip()
return parsed_output
class WeblogicPlugin(agent_util.Plugin):
textkey = "weblogic"
label = "Oracle WebLogic Webserver"
@classmethod
def get_metadata(self, config):
status = agent_util.SUPPORTED
msg = None
# check if oracle weblogic is installed, running, and on path
set_env_command = ""
if 'wl_home' in config:
set_env_command = ("CLASSPATH=%s " % os.path.join(config['wl_home'], "server/lib/weblogic.jar"))
installed = False
if agent_util.which("java"):
cmd = set_env_command + "java weblogic.Admin"
if "username" in config: cmd += " -username %s" % config["username"]
if "password" in config and config["password"].strip(): cmd += " -password %s" % config["password"].strip()
status, output = agent_util.execute_command(cmd)
if status == 0:
installed = True
if not installed:
self.log.info("Oracle weblogic was not found installed or not on path")
status = agent_util.UNSUPPORTED
return {}
if not config:
msg = "The [weblogic] configuration block was not found in the agent config file."
self.log.info(msg)
status = agent_util.MISCONFIGURED
if status == agent_util.SUPPORTED and not ("wl_home" in config and "username" in config and "password" in config):
msg = "Weblogic configuration parameters missing from the [weblogic] block of the agent config file."
self.log.info(msg)
status = agent_util.MISCONFIGURED
if status == agent_util.SUPPORTED and not os.path.exists(os.path.join(config['wl_home'], "server/bin/setWLSEnv.sh")):
msg ="Weblogic setWLSEnv.sh script not found"
self.log.info(msg)
status = agent_util.MISCONFIGURED
if status == agent_util.SUPPORTED:
try: output = get_metric(config, "ApplicationRuntime")
except:
self.log.exception("error getting weblogic metric")
status = agent_util.MISCONFIGURED
msg = "Unable to access Weblogic metrics. Please double check your Weblogic login username and password as well as wl_home in the agent config file."
data = {}
for type, vals in metrics.items():
try: output = get_metric(config, vals["type"])
except: continue
for property, meta in vals["metrics"].items():
textkey = "%s.%s" % (type, property)
data[textkey] = {
"label": meta["label"][:100],
"options": meta.get('options', None),
"status": status,
"error_message": msg
}
if "unit" in meta: data[textkey]["unit"] = meta["unit"]
if not data:
data = {'servlet': {"label": "WebLogic Servlets",
"options": None,
"status": status,
"error_message": msg}}
return data
def check(self, textkey, data, config):
try: type, property = textkey.split(".")
except: return False
if type not in metrics or property not in metrics[type]["metrics"]: return False
val = int(get_metric(config, metrics[type]["type"], metrics[type]["metrics"][property]["property"]))
self.log.debug("%s: %d" % (textkey, val))
return val