1

如何计算 Glassfish 3.1 上部署的 Web 服务的调用次数?实际上我可以通过控制台命令得到我想要的东西吗?如下

asadmin get -m "server.applications.hello-jaxws2*" server.applications.hello-jaxws2.2.server.Hello.requestcount-count = 14

但我想知道是否有办法以编程方式获取 Web 服务的调用计数?

4

1 回答 1

2

作为使用 Glassfish 3.1.2 的示例。此处名为“NewWebService”的 Web 服务是提取该 Web 服务的请求数的代码摘录。

public static void showRequestCount(MBeanServerConnection mbs) throws Exception {
    ObjectName on = new ObjectName("amx:pp=/mon/server-mon[server],type=servlet-instance-mon,name=WebApplication1/server/NewWebService");
    final Set<ObjectInstance> mBeans = mbs.queryMBeans(on, null);
    for (ObjectInstance mbean : mBeans) {
        System.out.println("mbean: " + mbean);
        final MBeanInfo info = mbs.getMBeanInfo(on);
        final MBeanAttributeInfo[] attributes = info.getAttributes();
        for (int i = 0; i < attributes.length; i++) {
            MBeanAttributeInfo mBeanAttributeInfo = attributes[i];
            if (mBeanAttributeInfo.getName().equals("requestcount")) {
                final Object attribute = mbs.getAttribute(on, mBeanAttributeInfo.getName());
                CompositeDataSupport cds = (CompositeDataSupport) attribute;
                final Object requestCount = cds.get("count");
                System.out.println("Object name: " + on.getKeyProperty("name"));
                System.out.println("Request count: " + requestCount);
            }
        }
    }
}

结果是:

mbean: servlet-instance-mon[amx:pp=/mon/server-mon[server],type=servlet-instance-mon,name=WebApplication1/server/NewWebService]
Object name: WebApplication1/server/NewWebService
Request count: 18

请注意,MBean 的 ObjectName 和/或其属性可能会因您的 Glassfish 版本而异。

于 2012-12-26T13:55:04.673 回答