Checking which server in cluster replied - Weblogic
This is a discussion on Checking which server in cluster replied - Weblogic ; Hi,
I have a cluster setup in WL 8.1. I would like my JSP to send me the information
on which server in the cluster I have connected to?
Is there a function which can tell me that?
Thanks,
Suzann...
-
Checking which server in cluster replied
Hi,
I have a cluster setup in WL 8.1. I would like my JSP to send me the information
on which server in the cluster I have connected to?
Is there a function which can tell me that?
Thanks,
Suzann
-
Re: Checking which server in cluster replied
"Suzann" wrote:
>I have a cluster setup in WL 8.1. I would like my JSP to send me the
>information on which server in the cluster I have connected to?
Suzann,
Sure, maybe something like this (formatting my be skewed on BEA's NewsWeb site)...
<%@ page session="false" %>
Weblogic Test page
<%= new java.util.Date().toString() %>
<%
String s = null ;
try
{
s = java.net.InetAddress.getLocalHost().getHostName();
out.println("Weblogic Hostname: "+ s + "
");
}
catch ( Throwable t ) {}
%>
Then, throw it into a WAR file (w/ deployment descriptors, of course) and deploy
to your cluster. Should be good to go.
Brian J. Mitchell
Systems Administrator, TRX
email: brian.mitchell@trx.com
office: +1 404 327 7238
mobile: +1 678 283 6530
-
Re: Checking which server in cluster replied
You could use this bit of JMX code, which I use. If you get load
balanced across a cluster, this will show which managed srever you're
actually attached to.
Hope it helps,
Pete
This bit goes in the top of the jsp
<%
weblogic.management.runtime.ServerRuntimeMBean server = null;
try {
weblogic.jndi.Environment env = new weblogic.jndi.Environment();
javax.naming.Context ctx = env.getInitialContext();
weblogic.management.MBeanHome mbeanHome =
(weblogic.management.MBeanHome)ctx.lookup(weblogic .management.MBeanHome
LOCAL_JNDI_NAME);
java.util.Set mbeanSet =
mbeanHome.getMBeansByType("ServerRuntime");
java.util.Iterator mbeanIterator = mbeanSet.iterator();
while (mbeanIterator.hasNext()) {
server =
(weblogic.management.runtime.ServerRuntimeMBean)mb eanIterator.next();
}
} catch (Exception e) {
%>
Error trying to get MBEAN Reference for local server:
<%=e.getMessage()%>
<%
}
%>
and then the servername is displayed;
-
Re: Checking which server in cluster replied
I use this in a menu and it's handy for diagnostics.
Pete
-
Re: Checking which server in cluster replied
Hi!
I was trying that JMX for a week now and I couldn't get it right.
I was trying to build it on example from eDocs on JMX documentation.
What I missed was the MBean type in line:
java.util.Set mbeanSet = mbeanHome.getMBeansByType("ServerRuntime");
In mine I was just passing "Server"... and it gave me a list of all the servers.
Thanks a million for your help!
Regards,
Suzann
-
Re: Checking which server in cluster replied
You're welcome - glad to finally help someone!
Pete
-
Re: Checking which server in cluster replied
These are certainly both viable options but I'm curious, it looks like
Suzann, the OP, just wanted to see which server handled the request for the
JSP page. If all you want is the name of the server that handled the
request and no other runtime information why not make it exponentially more
simple and just use something like <%= System.getProperty( "weblogic.Name" )
%>
"Pete" wrote in message
news:VA.00000015.0186e1ac@yahoo.co.uk...
> You're welcome - glad to finally help someone!
>
> Pete
>
-
Re: Checking which server in cluster replied
I am going to use this option instead for now.
However in future versions, I think I'll need to go back to JMX anyway 
Thanks 
BTW: what is "OP"
> ... Suzann, the OP, ....
-
Re: Checking which server in cluster replied
Excellent, didn't know that option existed. I'd just seen the JMS
working on the snoopservlet so borrowed the code.
Learn something new every day!
Pete
-
Re: Checking which server in cluster replied
OP is an old usenet idiom for ``original poster'' ;-)
"Suzann" wrote in message
news:3ff9437f$1@newsgroups.bea.com...
>
> I am going to use this option instead for now.
> However in future versions, I think I'll need to go back to JMX anyway 
>
> Thanks 
>
> BTW: what is "OP"
> > ... Suzann, the OP, ....
-
Re: Checking which server in cluster replied
That might not give the result you think it will. What you've provided
below gives the hostname of the machine the managed server is deployed on
which is not guaranteed to be the name of the managed server per se, nor
should it be IMO 
~RU
"Brian Mitchell" wrote in message
news:3ff1c250$1@newsgroups.bea.com...
>
> "Suzann" wrote:
> >I have a cluster setup in WL 8.1. I would like my JSP to send me the
> >information on which server in the cluster I have connected to?
>
> Suzann,
>
> Sure, maybe something like this (formatting my be skewed on BEA's NewsWeb
site)...
>
>
> <%@ page session="false" %>
>
>
> Weblogic Test page
>
>
>
> <%= new java.util.Date().toString() %>
> <%
> String s = null ;
> try
> {
> s = java.net.InetAddress.getLocalHost().getHostName();
> out.println("Weblogic Hostname: "+ s + "
");
> }
> catch ( Throwable t ) {}
> %>
>
>
>
>
>
>
> Then, throw it into a WAR file (w/ deployment descriptors, of course) and
deploy
> to your cluster. Should be good to go.
>
>
> Brian J. Mitchell
> Systems Administrator, TRX
>
> email: brian.mitchell@trx.com
> office: +1 404 327 7238
> mobile: +1 678 283 6530
>
|