Skip to main content
Inspiring
August 10, 2021
Answered

Forcing login to a specific ColdFusion Instance

  • August 10, 2021
  • 2 replies
  • 471 views

I have a server with 4 instances set up with the CFadmin Instance Manager.

All is well, but when I try to get a user count, you only get the count on your logged in instance.

I'm trying to log in to a specific instance, any suggestions?

 

-Chuck   

    This topic has been closed for replies.
    Correct answer BKBK
    quote

    I understand and agree with your methodology and can use it when I am remoted into the server, but I'm on a secure server and I can't pass in port numbers. (At least not that I know of)


    By @cbeckwith

     

    Please don't read much into the ports. That was just an example that pertains to my particular environment: 

    ColdFusion Developer Edition, 4 instances accessed by http via respective ports 8501, 8502, 8503, 8504.

     

     

    If I could create four cfhttps that worked on https, that would help even more.

     

     

    Of course. The 4 urls in the above example could be https instead. The principle remains exactly the same.  

     

    One advantage of this approach is that it enables you to gain insight into all the instances. For example,

     

    • You could, in totalSessionCount.cfm, find the total number of sessions on all the instances:
      <cfset totalNumberOfSessions = result1.M4S_Active_Sessions + result2.M4S_Active_Sessions + result3.M4S_Active_Sessions + result4.M4S_Active_Sessions>
    • You could set up a scheduled task to run totalSessionCount.cfm and log the number of sessions at specific times of the day.

    2 replies

    BKBK
    Community Expert
    Community Expert
    August 12, 2021

    Each instance is an independent application. For all we know, the 4 instances could be hosting, respectively, Adobe.com, Google.com, Microsoft.com and Cbeckwith.com. 🙂 If you could easily tunnel from one to the other, then that would literally be a security hole.

     

    Nil desperandum! There is a neat way out. 

     

    Within each of the instances, write a CFM that does all the counting for the instance. That is, you will have 4 identical CFM pages.

     

    Let each page output its result in JSON format. For example,

     

    <cfoutput>{"M4S_Active_Sessions" : "#StructCount(sessions)#"}</cfoutput>


    Then write a 5th CFM page, to be run on any arbitrary instance. This page contains cfhttp calls to each of the 4 instances.

    For example, let's call the 5th page totalSessionCount.cfm. Its code will consist of something like:

     

     

    <cfhttp url="http://127.0.0.1:8501/workspace/sessionCount.cfm" method="get" username="me1" password="myPw1" result="httpresult1">
    <!--- a struct --->
    <cfset result1=deserializeJSON(httpresult1.filecontent)>
    <p>
    Instance 1 user count: <cfoutput>#result1.M4S_Active_Sessions#</cfoutput>
    </p>
    
    <cfhttp url="http://127.0.0.1:8502/workspace/sessionCount.cfm" method="get" username="me2" password="myPw2" result="httpresult2">
    <!--- a struct --->
    <cfset result2=deserializeJSON(httpresult2.filecontent)>
    <p>
    Instance 2 user count: <cfoutput>#result2.M4S_Active_Sessions#</cfoutput>
    </p>
    
    <cfhttp url="http://127.0.0.1:8503/workspace/sessionCount.cfm" method="get" username="me3" password="myPw3" result="httpresult3">
    <!--- a struct --->
    <cfset result3=deserializeJSON(httpresult3.filecontent)>
    <p>
    Instance 3 user count: <cfoutput>#result3.M4S_Active_Sessions#</cfoutput>
    </p>
    
    <cfhttp url="http://127.0.0.1:8504/workspace/sessionCount.cfm" method="get" username="me4" password="myPw4" result="httpresult4">
    <!--- a struct --->
    <cfset result4=deserializeJSON(httpresult4.filecontent)>
    <p>
    Instance 4 user count: <cfoutput>#result4.M4S_Active_Sessions#</cfoutput>
    </p>

     

    cbeckwithAuthor
    Inspiring
    August 13, 2021

    BKBK,

    I understand and agree with your methodology and can use it when I am remoted into the server, but I'm on a secure server and I can't pass in port numbers. (At least not that I know of)

    If I could create four cfhttps that worked on https, that would help even more.

     

    Chuck

    BTW, lost my login stats, I've been a CF programmer since version 3. But this instance management is fairly new.

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    August 13, 2021
    quote

    I understand and agree with your methodology and can use it when I am remoted into the server, but I'm on a secure server and I can't pass in port numbers. (At least not that I know of)


    By @cbeckwith

     

    Please don't read much into the ports. That was just an example that pertains to my particular environment: 

    ColdFusion Developer Edition, 4 instances accessed by http via respective ports 8501, 8502, 8503, 8504.

     

     

    If I could create four cfhttps that worked on https, that would help even more.

     

     

    Of course. The 4 urls in the above example could be https instead. The principle remains exactly the same.  

     

    One advantage of this approach is that it enables you to gain insight into all the instances. For example,

     

    • You could, in totalSessionCount.cfm, find the total number of sessions on all the instances:
      <cfset totalNumberOfSessions = result1.M4S_Active_Sessions + result2.M4S_Active_Sessions + result3.M4S_Active_Sessions + result4.M4S_Active_Sessions>
    • You could set up a scheduled task to run totalSessionCount.cfm and log the number of sessions at specific times of the day.
    RaviShankar Chagnur
    Adobe Employee
    Adobe Employee
    August 10, 2021

    Hello Chuck,

     

    Can you please explain inbrief about your requirement, ie please let us know how you are counting the number of logged in users, 

    Also, please let us know if all the instances are up and running 

     

    Thanks & Regards

    Ravi

    cbeckwithAuthor
    Inspiring
    August 11, 2021

    Yes, I'm using a Dell 730 with Windows 2012 R2 pointed to our Oracle database on an Enterprise 2018 CF version.

    I used the CF instance manager and created four instances with sticky sessions.

    For metrics, I'm trying to determine the number of users online.

    When I had only one instance, I used:
    <cfset tracker = CreateObject("java","coldfusion.runtime.SessionTracker")>
    <cfset sessions = tracker.getSessionCollection(application.applicationName)>
    M4S Active Sessions:#StructCount(sessions)#</b><br>

    Since adding the additional instances, I used:

    <cfset tracker = CreateObject("java","coldfusion.runtime.SessionTracker")>
    <cfset sessions = tracker.getSessionCollection(application.applicationName)>
    <cfset serverLen = len(server.coldfusion.rootdir)>
    <b>Server Instance: #mid(server.coldfusion.rootDir,19,serverLen-18)#<br>
    M4S Active Sessions:#StructCount(sessions)#</b><br>

    to identify the specific server instance.

     

    Currently I need to have four different browser sessions to get a count of all four instances.

    I have to open and close browsers to capture each of the four.

    It would be nice to be able to tweak the url and point to a specific instance.

    Is there any way to make a url directed at a specific instance?

     

    cbeckwithAuthor
    Inspiring
    August 11, 2021

    Addendum:  and yes, all four instances are running.