[Looking for Charlie's main web site?]

Tracking ColdFusion sessions within FusionReactor, by way of FREC logging

Note: This blog post is from 2013. Some content may be outdated--though not necessarily. Same with links and subsequent comments from myself or others. Corrections are welcome, in the comments. And I may revise the content as necessary.
Someone asked on the FusionReactor mailing list (a Google Group) whether FusionReactor tracked CF sessions. I started to write a reply, with the good news/bad news in answer to that, and as sometimes happens, it became long enough that I thought it might be better suited as a blog entry that I could point to from the list instead, and which may also help those not on the list (which is a great resource, as a low-volume list with a high signal to noise ratio.)

Anyway, here is the answer I wanted to offer to that question...

(BTW, here's the link to that specific question, in case there is subsequent discussion there and not here.)

Update: FR 5 DOES now have a chart of the session count

When I wrote this blog entry in Aug 2013, I was focused on the ways that FREC in FR4 (or as built-into FR 5) offered logging of session counts. A week later, FusionReactor 5.0.6 was released which now offers a chart of the session count over time, which is awesome. See the Metrics>Custom Series option on the left. Choose the option for ActiveSessionCount in the drop-down on the top right, if it's not selected by default, and note that you can view it over the last hour, day, or week.

I have stricken out the reference below where I said that sessions were not charted, but the information still applies on how FusionAnalytics lets you see that over a still longer time.

On the question of whether FR tracks session counts, per application: the "bad" news is that while FR itself does not track CF session counts at all, but the "good news" is that the free FREC plugin (FREC: "FusionReactor Extensions for CF", for use with FR 4, and built-into FR 5) does in fact cause FR to log a count of CF sessions. More on that FREC log, as well as how you might view that data graphically, in a moment.

How FR tracks CF sessions

Before addressing that solution, something to consider when contemplating a question like this is that FR is technically not a CF monitor: it's a java server monitor, which can monitor CF as well as Railo, BD, OpenBD, and indeed any Java server like Tomcat, JBoss Jetty, Resin, etc. (And as of FR 5, being a Java agent, it can really monitor ANY java application at all.)

Of course, CF happens to be a Java server under the cover, yet we never really notice that in any way in using FR: it just seems that we are "monitoring ColdFusion", and that's good enough! :-) But technically it's monitoring requests via a Java servlet filter implemented within CF (in FR 4.5 and earlier) or via a java agent implemented in the JVM within CF (in FR 5).

But an upshot of that fact (that it only really monitors CF as a Java engine) is that since CF sessions are (by default) purely CF thing, FR does not see them. (Now, technically, one could configure the CF Admin to cause CF to use J2EE sessions, which means then that it gives control of sessions to the underlying servlet engine--JRun by default in CF9 and earlier, Tomcat in CF 10. But either way, FR's interface also does not track Java sessions.)

How FREC does log a count of CF sessions

But as I said at the outset, though, the good news is that while the FR *interface* does not track CF sessions, the free add-on, FREC (availble for FR 5 and built-into FR 5), does cause CF to track sessions, as well as many other very helpful CF metrics (which might otherwise be viewed only in the CF Server Monitor). After installing FREC (for FR 4, or automatically for FR 5), you will find a new log (one of a few) in the FR logs directory, called the realtimestats.log. It writes out a few dozen really valuable metrics every 5 seconds, including a count of CF sessions (regardless of whether CF or J2EE sessions are used within CF.)

Now, it's important to note that there is NO change at all in the FR interface, once FREC is added in FR 4. FREC only causes new data to be logged. (FR 5.0.6 and above offers the new charting of sessions, and FusionAnalytics allows charting of sessions (and more) over a still longer time. More on that in a moment.)

Some more great things about FREC: not only is it free (for FR 4 and included in FR 5), but it also works even with CF Standard (whereas the CF Server Monitor) runs only in CF Enterprise (8 and above). Still more great news, for either those running CF Standard or Enterprise, is that FREC's logging of stuff is something that even the CF Enterprise Server Monitor doesn't do. It logs nothing. I often (in my CF troubleshooting consulting services) help people understand and resolve problems with CF by enabling FREC and helping them make use of the FREC logs.

Obtaining FREC

As I said above, FREC is a free extension for FusionReactor 4, and it's built-into FR 5. You can download it for 4 here, and after installing it, you can enable it in any FR instance monitoring ColdFusion. (There is currently no such plugin for Railo or other CFML or Java server engines.) Note that FREC should be removed before installing FR 5.

FusionAnalytics also provides an interface to view CF session counts over still longer time

Finally, while I noted that the FR interface doesn't show anything based on FREC being enabled (FREC only logs things), note that FusionAnalytics (the sister product to FR) DOES in fact use the FREC logs (if enabled) and DOES show in its interface various measures (charts and reports) that reflect things based on this FREC data, so for instance it DOES track sessions in CF, over time. And that can include before CF restarted, and indeed can go back days, weeks, months, or longer, depending on how you have configured FR and FA.

You can learn more about FREC in the FR online doc page for FREC, which has a link with details on the columns to the realtimestats.log it enables.

Again, lots of cool stuff there, including counts of the CF query cache use, the CF Template cache use, the count of queued CF requests, and lots more.

Just note that SOME of the data in that log is only available if running on CF Enterprise and specifically with certain "start" buttons enabled in the CF Server Monitor. The log page does not always clarify that as well as it might. But the session count, and those other counts I mentioned at the opening of this paragraph, are in fact tracked in there.

Getting a count of CF sessions per application

All that said, FREC's tracking of the session count (in the log, the FR 5 interface, or in FA) is NOT per application, as you had sought. Still, having the session count at all is really valuable for so many people, so I hope this is of value to others.

If you are in need of the session count per application, while you could dig it out of the CF Admin API (if you had CF Enterprise), or using the undocumented session tracker (available in CF Standard), you can get it very easily in a single simple report (that is created in just seconds) from a nifty free tool called ServerStats, which was written years ago by Mark Lynch and which calls the undocumented sessiontracker object within CF, to produce a report of a count of total sessions, and sessions per application. It runs in just seconds (and does not require any modification of your code. You just drop it into an executable CF code directory and run it.)

More in a blog entry I did about ServerStats.

Note that you could also review his code (its open source) to create your own means to perhaps log session counts per application (as the ServerStats report is just a point in time display of the count per application).

Hope that helps.

For more content like this from Charlie Arehart: Need more help with problems?
  • If you may prefer direct help, rather than digging around here/elsewhere or via comments, he can help via his online consulting services
  • See that page for more on how he can help a) over the web, safely and securely, b) usually very quickly, c) teaching you along the way, and d) with satisfaction guaranteed
Comments
In FR5 (from update 5.0.6) we added support for graphing the ColdFusion Active Session Count if you go into Metrics->Custom Series you should see /ColdFusionServerMonitor/ACTIVESESSIONCOUNT as one of the custom graphs. The data is coming from the ColdFusion Server Monitoring API via FREC which is integrated into FR5 by default.
# Posted By Darren | 10/15/13 12:07 PM
Excellent news, Darren. Thanks for pointing that out.
Darren, is there a documentation on how "ColdFusion Server Monitoring API" works to populate this chart?!
# Posted By Paolo | 12/11/13 8:30 AM
I'm don't think there is any on how it works. Just the documentation of the CF Server Monitoring API itself.
# Posted By Darren | 12/11/13 8:34 AM
Thanks Darren,
but which API is called -> "cfide.adminapi.servermonitoring.getActiveSessionCount()" ?
# Posted By Paolo | 12/11/13 10:22 AM
Paolo, got it... yes it is getActiveSessionCount.
# Posted By Darren | 12/11/13 10:33 AM
You can add a metric series to FusionReactor using FRAPI. Basically your code posts metric values into FR and these will be added to the custom series.

Here is another example using the ColdFusion Server Monitor API to track memory:
<cfscript>
frapi = createObject("java", "com.intergral.fusionreactor.api.FRAPI").getInstance();
adminObj = createObject("component","cfide.adminapi.administrator").login("passwordhere");
srvMon = createObject("component","cfide.adminapi.servermonitoring");
</cfscript>

<cfobject type="java" action="create" class="java.lang.Thread" name="Thread">

<cfloop from=1 to=120 index="j">
<cfscript>

frapi.postNumericAggregateMetric("/CF/MemoryUsage",
srvMon.getRealtimeStats().JVMUSEDMEMORY / 1048576 );

WriteOutput( srvMon.getRealtimeStats().JVMUSEDMEMORY / 1048576 );

Thread.sleep( JavaCast( "long",1000 ) );

</cfscript>
<cfflush>
</cfloop>


Here is an example where you are adding a series called Revenue (doesn't have to be a technical series :-) ). Notice I've just put these into loops with delays because they don't run in a sampler. Typically you would embed them into your code when you have a metric to track. Currently we only show the average of the series if you post multiple values inside the same second.

<cfscript>
frapi = createObject("java", "com.intergral.fusionreactor.api.FRAPI").getInstance();
</cfscript>

<cfobject type="java" action="create" class="java.lang.Thread" name="Thread">

<cfloop from=1 to=120 index="j">
<cfscript>
frapi.postNumericAggregateMetric("/Website/Revenue", RandRange(100,300));
Thread.sleep( JavaCast( "long",1000 ) );
</cfscript>
<cfflush>
</cfloop>



I'm not sure what the unknown series is, can you provide me with a little more information?
# Posted By Darren | 12/12/13 6:50 AM
Copyright ©2024 Charlie Arehart
Carehart Logo
BlogCFC was created by Raymond Camden. This blog is running version 5.005.
(Want to validate the html in this page?)

Managed Hosting Services provided by
Managed Dedicated Hosting