You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by sgjava <sg...@gmail.com> on 2016/08/05 14:59:34 UTC

JCache stats without JMX?

Is there a simple way to access a JCache cache statistics without a JMX
client? I really only care about the current size.



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/JCache-stats-without-JMX-tp4679621.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: JCache stats without JMX?

Posted by Steve Goldsmith <sg...@gmail.com>.
Yea, I was looking at one of my GlassFish health checks that uses JMX
client and it's using the GlassFish admin user and connecting via
service:jmx:rmi:///jndi/rmi://myserver:28686/jmxrmi. I'd be fine using the
manager-gui account since I'm using UserDatabase for that.

On Fri, Aug 5, 2016 at 1:11 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> in jaas you can define a list of loginmodules and use a "one match"
> strategy, then question is how to check it is "local". One easy way can be
> to have a local secret and test it as password, A kind of local admin only.
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> <http://rmannibucau.wordpress.com> | Github <https://github.com/
> rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com> | JavaEE Factory
> <https://javaeefactory-rmannibucau.rhcloud.com>
>
> 2016-08-05 18:41 GMT+02:00 Steve Goldsmith <sg...@gmail.com>:
>
> > I'm configuring my auth via JDK params, so I'm not using a Tomcat realm.
> > i.e.
> >
> > export CATALINA_OPTS="-Xmx1000m -Dfile.encoding=UTF-8
> > -Djava.awt.headless=true -Djava.rmi.server.hostname=myhost
> > -Dcom.sun.management.jmxremote.login.config=Tomcat
> > -Djava.security.auth.login.config=$CATALINA_HOME/conf/login.config
> > -Dcom.sun.management.jmxremote.access.file=$
> CATALINA_HOME/conf/jmxremote.
> > access
> > -Dcom.sun.management.jmxremote.ssl=false"
> >
> >
> >
> > On Fri, Aug 5, 2016 at 12:10 PM, Romain Manni-Bucau <
> rmannibucau@gmail.com
> > >
> > wrote:
> >
> > > used a combinedrealm supporting either ldap or localhost access?
> > >
> > >
> > > Romain Manni-Bucau
> > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > > <http://rmannibucau.wordpress.com> | Github <https://github.com/
> > > rmannibucau> |
> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > <http://www.tomitribe.com> | JavaEE Factory
> > > <https://javaeefactory-rmannibucau.rhcloud.com>
> > >
> > > 2016-08-05 18:08 GMT+02:00 Steve Goldsmith <sg...@gmail.com>:
> > >
> > > > OK, thanks. It's really to log stats, so I only need local access.
> > > Problem
> > > > is I have server configured for LDAP auth which I do not want to do
> > > > locally.
> > > >
> > > > On Fri, Aug 5, 2016 at 11:47 AM, Romain Manni-Bucau <
> > > rmannibucau@gmail.com
> > > > >
> > > > wrote:
> > > >
> > > > > Not in a portable way I think so options are likely:
> > > > > - use JMX locally and expose it through another API (JAX-RS or
> other)
> > > > > - use some vendor API (like cache.getStatistics() for JCS)
> > > > >
> > > > >
> > > > > Romain Manni-Bucau
> > > > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > > > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > > > > <http://rmannibucau.wordpress.com> | Github <https://github.com/
> > > > > rmannibucau> |
> > > > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > > > <http://www.tomitribe.com> | JavaEE Factory
> > > > > <https://javaeefactory-rmannibucau.rhcloud.com>
> > > > >
> > > > > 2016-08-05 16:59 GMT+02:00 sgjava <sg...@gmail.com>:
> > > > >
> > > > > > Is there a simple way to access a JCache cache statistics
> without a
> > > JMX
> > > > > > client? I really only care about the current size.
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > View this message in context: http://tomee-openejb.979440.
> > > > > > n4.nabble.com/JCache-stats-without-JMX-tp4679621.html
> > > > > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > > > > >
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Steven P. Goldsmith
> > > >
> > >
> >
> >
> >
> > --
> > Steven P. Goldsmith
> >
>



-- 
Steven P. Goldsmith

Re: JCache stats without JMX?

Posted by sgjava <sg...@gmail.com>.
I found a simpler way using a scheduled service to log stats:

@Singleton
@Startup
@SuppressWarnings("checkstyle:designforextension") // CDI beans not allowed
to have final methods
public class CacheStatService {

    /**
     * Logger.
     */
    @SuppressWarnings({"checkstyle:constantname",
        "PMD.VariableNamingConventions"}) // Logger OK to be static final
and lower case
    private static final Logger log = LoggerFactory.getLogger(
            CacheStatService.class);

    @Schedule(second = "*", minute = "*/1", hour = "*", persistent = false)
    public void logCacheStats() {
        try {
            // Get MBean server list
            final ArrayList list = MBeanServerFactory.findMBeanServer(null);
            // Grab first one
            final MBeanServer mbeanServer = (MBeanServer) list.get(0);
            // Name of the cache in JCache
            final ObjectName objectName = new ObjectName(
                   
"javax.cache:type=CacheStatistics,CacheManager=hazelcast,Cache=header");
            // Get MBean info
            final MBeanInfo info = mbeanServer.getMBeanInfo(objectName);
            // Get array of attributes
            final MBeanAttributeInfo[] attributes = info.getAttributes();
            final Map<String, Object> attrMap = new HashMap<>();
            // Get all attributes
            for (final MBeanAttributeInfo attr : attributes) {
                attrMap.put(attr.getName(),
mbeanServer.getAttribute(objectName,
                        attr.getName()));
            }
            log.info(String.format("Cache stats: %s", attrMap));
        } catch (MalformedObjectNameException | InstanceNotFoundException |
                IntrospectionException | ReflectionException |
MBeanException |
                AttributeNotFoundException e) {
            log.error(e.getMessage());
        }
    }

08/05/2016 14:06:05.001 [EjbTimerPool - 1] INFO 
com.bhn.services.CacheStatService - Cache stats: {CacheGets=10,
AverageGetTime=61.4972, CacheRemovals=0, CacheHitPercentage=80.0,
AveragePutTime=376.1885, CacheMissPercentage=20.0, AverageRemoveTime=0.0,
CachePuts=4, CacheEvictions=0, CacheMisses=2, CacheHits=8}





--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/JCache-stats-without-JMX-tp4679621p4679636.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: JCache stats without JMX?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
in jaas you can define a list of loginmodules and use a "one match"
strategy, then question is how to check it is "local". One easy way can be
to have a local secret and test it as password, A kind of local admin only.


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-08-05 18:41 GMT+02:00 Steve Goldsmith <sg...@gmail.com>:

> I'm configuring my auth via JDK params, so I'm not using a Tomcat realm.
> i.e.
>
> export CATALINA_OPTS="-Xmx1000m -Dfile.encoding=UTF-8
> -Djava.awt.headless=true -Djava.rmi.server.hostname=myhost
> -Dcom.sun.management.jmxremote.login.config=Tomcat
> -Djava.security.auth.login.config=$CATALINA_HOME/conf/login.config
> -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.
> access
> -Dcom.sun.management.jmxremote.ssl=false"
>
>
>
> On Fri, Aug 5, 2016 at 12:10 PM, Romain Manni-Bucau <rmannibucau@gmail.com
> >
> wrote:
>
> > used a combinedrealm supporting either ldap or localhost access?
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > <http://rmannibucau.wordpress.com> | Github <https://github.com/
> > rmannibucau> |
> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > <http://www.tomitribe.com> | JavaEE Factory
> > <https://javaeefactory-rmannibucau.rhcloud.com>
> >
> > 2016-08-05 18:08 GMT+02:00 Steve Goldsmith <sg...@gmail.com>:
> >
> > > OK, thanks. It's really to log stats, so I only need local access.
> > Problem
> > > is I have server configured for LDAP auth which I do not want to do
> > > locally.
> > >
> > > On Fri, Aug 5, 2016 at 11:47 AM, Romain Manni-Bucau <
> > rmannibucau@gmail.com
> > > >
> > > wrote:
> > >
> > > > Not in a portable way I think so options are likely:
> > > > - use JMX locally and expose it through another API (JAX-RS or other)
> > > > - use some vendor API (like cache.getStatistics() for JCS)
> > > >
> > > >
> > > > Romain Manni-Bucau
> > > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > > > <http://rmannibucau.wordpress.com> | Github <https://github.com/
> > > > rmannibucau> |
> > > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > > <http://www.tomitribe.com> | JavaEE Factory
> > > > <https://javaeefactory-rmannibucau.rhcloud.com>
> > > >
> > > > 2016-08-05 16:59 GMT+02:00 sgjava <sg...@gmail.com>:
> > > >
> > > > > Is there a simple way to access a JCache cache statistics without a
> > JMX
> > > > > client? I really only care about the current size.
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > View this message in context: http://tomee-openejb.979440.
> > > > > n4.nabble.com/JCache-stats-without-JMX-tp4679621.html
> > > > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Steven P. Goldsmith
> > >
> >
>
>
>
> --
> Steven P. Goldsmith
>

Re: JCache stats without JMX?

Posted by Steve Goldsmith <sg...@gmail.com>.
I'm configuring my auth via JDK params, so I'm not using a Tomcat realm.
i.e.

export CATALINA_OPTS="-Xmx1000m -Dfile.encoding=UTF-8
-Djava.awt.headless=true -Djava.rmi.server.hostname=myhost
-Dcom.sun.management.jmxremote.login.config=Tomcat
-Djava.security.auth.login.config=$CATALINA_HOME/conf/login.config
-Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access
-Dcom.sun.management.jmxremote.ssl=false"



On Fri, Aug 5, 2016 at 12:10 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> used a combinedrealm supporting either ldap or localhost access?
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> <http://rmannibucau.wordpress.com> | Github <https://github.com/
> rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com> | JavaEE Factory
> <https://javaeefactory-rmannibucau.rhcloud.com>
>
> 2016-08-05 18:08 GMT+02:00 Steve Goldsmith <sg...@gmail.com>:
>
> > OK, thanks. It's really to log stats, so I only need local access.
> Problem
> > is I have server configured for LDAP auth which I do not want to do
> > locally.
> >
> > On Fri, Aug 5, 2016 at 11:47 AM, Romain Manni-Bucau <
> rmannibucau@gmail.com
> > >
> > wrote:
> >
> > > Not in a portable way I think so options are likely:
> > > - use JMX locally and expose it through another API (JAX-RS or other)
> > > - use some vendor API (like cache.getStatistics() for JCS)
> > >
> > >
> > > Romain Manni-Bucau
> > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > > <http://rmannibucau.wordpress.com> | Github <https://github.com/
> > > rmannibucau> |
> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > <http://www.tomitribe.com> | JavaEE Factory
> > > <https://javaeefactory-rmannibucau.rhcloud.com>
> > >
> > > 2016-08-05 16:59 GMT+02:00 sgjava <sg...@gmail.com>:
> > >
> > > > Is there a simple way to access a JCache cache statistics without a
> JMX
> > > > client? I really only care about the current size.
> > > >
> > > >
> > > >
> > > > --
> > > > View this message in context: http://tomee-openejb.979440.
> > > > n4.nabble.com/JCache-stats-without-JMX-tp4679621.html
> > > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > > >
> > >
> >
> >
> >
> > --
> > Steven P. Goldsmith
> >
>



-- 
Steven P. Goldsmith

Re: JCache stats without JMX?

Posted by Steve Goldsmith <sg...@gmail.com>.
I'll check that out.

On Fri, Aug 5, 2016 at 12:10 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> used a combinedrealm supporting either ldap or localhost access?
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> <http://rmannibucau.wordpress.com> | Github <https://github.com/
> rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com> | JavaEE Factory
> <https://javaeefactory-rmannibucau.rhcloud.com>
>
> 2016-08-05 18:08 GMT+02:00 Steve Goldsmith <sg...@gmail.com>:
>
> > OK, thanks. It's really to log stats, so I only need local access.
> Problem
> > is I have server configured for LDAP auth which I do not want to do
> > locally.
> >
> > On Fri, Aug 5, 2016 at 11:47 AM, Romain Manni-Bucau <
> rmannibucau@gmail.com
> > >
> > wrote:
> >
> > > Not in a portable way I think so options are likely:
> > > - use JMX locally and expose it through another API (JAX-RS or other)
> > > - use some vendor API (like cache.getStatistics() for JCS)
> > >
> > >
> > > Romain Manni-Bucau
> > > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > > <http://rmannibucau.wordpress.com> | Github <https://github.com/
> > > rmannibucau> |
> > > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > > <http://www.tomitribe.com> | JavaEE Factory
> > > <https://javaeefactory-rmannibucau.rhcloud.com>
> > >
> > > 2016-08-05 16:59 GMT+02:00 sgjava <sg...@gmail.com>:
> > >
> > > > Is there a simple way to access a JCache cache statistics without a
> JMX
> > > > client? I really only care about the current size.
> > > >
> > > >
> > > >
> > > > --
> > > > View this message in context: http://tomee-openejb.979440.
> > > > n4.nabble.com/JCache-stats-without-JMX-tp4679621.html
> > > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > > >
> > >
> >
> >
> >
> > --
> > Steven P. Goldsmith
> >
>



-- 
Steven P. Goldsmith

Re: JCache stats without JMX?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
used a combinedrealm supporting either ldap or localhost access?


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-08-05 18:08 GMT+02:00 Steve Goldsmith <sg...@gmail.com>:

> OK, thanks. It's really to log stats, so I only need local access. Problem
> is I have server configured for LDAP auth which I do not want to do
> locally.
>
> On Fri, Aug 5, 2016 at 11:47 AM, Romain Manni-Bucau <rmannibucau@gmail.com
> >
> wrote:
>
> > Not in a portable way I think so options are likely:
> > - use JMX locally and expose it through another API (JAX-RS or other)
> > - use some vendor API (like cache.getStatistics() for JCS)
> >
> >
> > Romain Manni-Bucau
> > @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> > <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> > <http://rmannibucau.wordpress.com> | Github <https://github.com/
> > rmannibucau> |
> > LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> > <http://www.tomitribe.com> | JavaEE Factory
> > <https://javaeefactory-rmannibucau.rhcloud.com>
> >
> > 2016-08-05 16:59 GMT+02:00 sgjava <sg...@gmail.com>:
> >
> > > Is there a simple way to access a JCache cache statistics without a JMX
> > > client? I really only care about the current size.
> > >
> > >
> > >
> > > --
> > > View this message in context: http://tomee-openejb.979440.
> > > n4.nabble.com/JCache-stats-without-JMX-tp4679621.html
> > > Sent from the TomEE Users mailing list archive at Nabble.com.
> > >
> >
>
>
>
> --
> Steven P. Goldsmith
>

Re: JCache stats without JMX?

Posted by Steve Goldsmith <sg...@gmail.com>.
OK, thanks. It's really to log stats, so I only need local access. Problem
is I have server configured for LDAP auth which I do not want to do locally.

On Fri, Aug 5, 2016 at 11:47 AM, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Not in a portable way I think so options are likely:
> - use JMX locally and expose it through another API (JAX-RS or other)
> - use some vendor API (like cache.getStatistics() for JCS)
>
>
> Romain Manni-Bucau
> @rmannibucau <https://twitter.com/rmannibucau> |  Blog
> <https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
> <http://rmannibucau.wordpress.com> | Github <https://github.com/
> rmannibucau> |
> LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
> <http://www.tomitribe.com> | JavaEE Factory
> <https://javaeefactory-rmannibucau.rhcloud.com>
>
> 2016-08-05 16:59 GMT+02:00 sgjava <sg...@gmail.com>:
>
> > Is there a simple way to access a JCache cache statistics without a JMX
> > client? I really only care about the current size.
> >
> >
> >
> > --
> > View this message in context: http://tomee-openejb.979440.
> > n4.nabble.com/JCache-stats-without-JMX-tp4679621.html
> > Sent from the TomEE Users mailing list archive at Nabble.com.
> >
>



-- 
Steven P. Goldsmith

Re: JCache stats without JMX?

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Not in a portable way I think so options are likely:
- use JMX locally and expose it through another API (JAX-RS or other)
- use some vendor API (like cache.getStatistics() for JCS)


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Wordpress Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | Tomitriber
<http://www.tomitribe.com> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2016-08-05 16:59 GMT+02:00 sgjava <sg...@gmail.com>:

> Is there a simple way to access a JCache cache statistics without a JMX
> client? I really only care about the current size.
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.
> n4.nabble.com/JCache-stats-without-JMX-tp4679621.html
> Sent from the TomEE Users mailing list archive at Nabble.com.
>