Skip to content

Instantly share code, notes, and snippets.

@pfreitag
Created October 1, 2015 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfreitag/fd000198d8d16c68de90 to your computer and use it in GitHub Desktop.
Save pfreitag/fd000198d8d16c68de90 to your computer and use it in GitHub Desktop.
<cfparam name="url.key" default="">
<cfparam name="url.threadName" default="">
<cfif url.key IS "pete">
<cfparam name="url.header" default="1">
<cfif url.header>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<cfoutput>
<script>
var intervalID = 0;
reload = function() {
$.get('threads.cfm?header=0&key=pete&threadName=#JSStringFormat(url.threadName)#', function(data) {
if (data.indexOf('ThreadID') != -1) {
$('##main').html(data);
} else {
clearInterval(intervalID);
alert('Server Down?')
}
})
}
$(document).ready(function() {
setInterval(reload, 10000);
});
</script>
</cfoutput>
<style>
td { font-size:x-small; border-bottom:1px solid silver; }
tr.ignore { display:none; }
tr.ignore td { display:none; }
tr.highlight td { color:red; font-weight:bold; font-size:larger; }
tr.current td { color:blue; }
#metrics { padding:4px; position:absolute; top:5px; right:5px; background-color: #f1f1f1; border-radius:3px; font-weight:bold; width: 250px; }
</style>
<div id="main">
</cfif>
<cfset mf = CreateObject("java", "java.lang.management.ManagementFactory")>
<cfset threadBean = mf.getThreadMXBean()>
<cfset currentThread = CreateObject("java", "java.lang.Thread").currentThread()>
<cfoutput>Current Thread: #currentThread.getName()#</cfoutput>
<cfset threadDump = threadBean.dumpAllThreads(false, false)>
<h2><cfoutput>#Dateformat(now(), "full")# <small>at</small> #TimeFormat(now(), "full")#</cfoutput></h2>
<table>
<tr>
<th>ThreadID</th>
<th>Name</th>
<th>In Native Code</th>
<th>Lock Owner</th>
<th>StackTrace</th>
</tr>
<cfoutput>
<cfloop array="#threadDump#" index="threadInfo">
<cfif NOT Len(url.threadName) OR threadInfo.getThreadName() IS url.threadName>
<!--- threadInfo is a java.lang.management.ThreadInfo --->
<cfset stackTrace = "">
<cfset cfTrace = "">
<cfloop array="#threadInfo.getStackTrace()#" index="st">
<cfset stackTrace = stackTrace & st.toString() & Chr(10)>
<cfif ReFindNoCase("\.cf[mc]:", st.ToString())>
<cfset cfTrace = cfTrace & st.toString() & Chr(10)>
</cfif>
</cfloop>
<cfset ignore = stackTrace contains "ProxyEndpoint.java:591">
<cfif NOT FindNoCase("jrpp", threadInfo.getThreadName()) AND NOT FindNoCase("ajp-bio", threadInfo.getThreadName())>
<cfset ignore = true>
</cfif>
<cfset cls = "">
<cfif ignore>
<cfset cls = "ignore">
<cfelseif Len(cfTrace)>
<cfset cls = "highlight">
</cfif>
<cfif currentThread.getName() IS threadInfo.getThreadName()>
<cfset cls = "current " & cls>
</cfif>
<tr class="#cls#">
<td>#threadInfo.getThreadID()#</td>
<td><a href="threads.cfm?threadName=#URLEncodedFormat(threadInfo.getThreadName())#&key=#URLEncodedFormat(url.key)#">#threadInfo.getThreadName()#</a></td>
<td>#YesNoFormat(threadInfo.isInNative())#</td>
<td>#threadInfo.getLockOwnerName()#</td>
<td>
<cfif Len(cfTrace)>
<small><pre>#cfTrace#</pre></small>
</cfif>
<small><pre>#stackTrace#</pre></small>
</td>
</tr>
</cfif>
</cfloop>
</cfoutput>
</table>
<cftry>
<cfset metrics = GetMetricData("PERF_MONITOR")>
<div id="metrics">
<cfoutput>
ColdFusion Server Metrics: <br>
<br>
InstanceName: #metrics.InstanceName# <br>
PageHits: #metrics.PageHits# <br>
ReqQueued: #metrics.ReqQueued# <br>
DBHits: #metrics.DBHits# <br>
ReqRunning: #metrics.ReqRunning# <br>
<!---ReqTimedOut: #metrics.ReqTimedOut# <br>--->
BytesIn: #metrics.BytesIn# <br>
BytesOut: #metrics.BytesOut# <br>
AvgQueueTime: #metrics.AvgQueueTime# <br>
AvgReqTime: #metrics.AvgReqTime# <br>
AvgDBTime: #metrics.AvgDBTime# <br>
CachePops: #metrics.CachePops# <br>
Simple Load: #GetMetricData("SIMPLE_LOAD").toString()#<br>
<!--- Prev Request Time: #GetMetricData("PREV_REQ_TIME")#ms<br>--->
Avg Request Time: #GetMetricData("AVG_REQ_TIME")#ms<br>
</cfoutput>
</div>
<cfcatch></cfcatch>
</cftry>
<cfif url.header>
</div>
</cfif>
</cfif>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment