Yammer的@Timed在零值留下 [英] yammer @Timed leaving values at zero
问题描述
这是使用Yammer的定时注解这里描述后续我的斗争。
This is a follow-up to my struggle using yammer timing annotations as described here.
我的Spring上下文文件中有简单的:
My spring context file has simply:
<metrics:annotation-driven />
我有以下类:
import com.yammer.metrics.annotation.ExceptionMetered;
import com.yammer.metrics.annotation.Metered;
import com.yammer.metrics.annotation.Timed;
...
@Component
public class GetSessionServlet extends HttpServlet {
private final static Logger log = LoggerFactory.getLogger(GetSessionServlet.class);
@Override
public void init(final ServletConfig config) throws ServletException {
super.init(config);
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(
this, config.getServletContext());
}
@Override
@Timed(name = "get-session", rateUnit = TimeUnit.MILLISECONDS)
@Metered
@ExceptionMetered(name = "get-session-failures", rateUnit = TimeUnit.MILLISECONDS)
public void doGet(final HttpServletRequest req,
final HttpServletResponse resp) throws ServletException, IOException {
final String sessionId = req.getParameter("sessionId");
final String fields = req.getParameter("fields");
final String format = req.getParameter("format");
if (StringUtils.isEmpty(sessionId)) {
resp.getWriter().write("sessionId parameter missing!\n");
return;
}
...
}
我用 MVN清洁tomcat7运行我的应用程序在本地:运行
然后连接JConsole的
I run my app locally with mvn clean tomcat7:run
and then connect jconsole.
在MBeans标签,我可以看到有三个子文件夹我的 GetSessionServlet
类的包名的条目的doGet
(用于@Metered号),获得会话,并获得-会话失败。
In the MBeans tab, I can see an entry with the package name of my GetSessionServlet
class with three subfolders doGet
(for the @Metered numbers), get-session, and get-session-failures.
但是,不管有多少次我打电话给我的servlet,在子文件夹中的所有值以上保持为零。我在想什么?此外,的任何的这些计量指标文档进入比官方文件将大大AP preciated。
However, no matter how many times I call my servlet, all the values in the sub-folders above remain at zero. What am I missing? Also, any documentation on these metered metrics that goes into more details than the official documentation will be greatly appreciated.
推荐答案
我想我得到了这个工作。
I think I got this working.
我注意到的第一件事情是,URI样品Spring上下文文件的schemaLocation属性:
<一href=\"http://www.yammer.com/schema/metrics/metrics.xsd\">http://www.yammer.com/schema/metrics/metrics.xsd
返回404错误。
The first thing I noticed was that the URI in the schemaLocation attribute of the sample spring context file: http://www.yammer.com/schema/metrics/metrics.xsd returns a 404 error.
我GOOGLE了这个问题,看看是否有人曾抱怨模式不可达,发现这个线程,github.com/codahale/metrics/issues/322,其中用户评论指出,指标弹簧模块已经从删除核心指标库,搬到了:github.com/ryantenney/metrics-spring
I googled the issue to see if anyone had complained about the schema being unreachable and found this thread, github.com/codahale/metrics/issues/322, wherein a user comments that the metrics-spring module has been removed from the core metrics repository and moved to: github.com/ryantenney/metrics-spring.
随着该网站上的例子,我从我的POM剥离出来的老指标弹簧的依赖,并增加了以下内容:
Following the example on that website, I stripped out the old metrics-spring dependency from my pom and added the following:
<dependency>
<groupId>com.ryantenney.metrics</groupId>
<artifactId>metrics-spring</artifactId>
<version>2.1.4</version>
</dependency>
然后我更新了xmlns声明我在春天context.xml文件:
I then updated the xmlns declaration in my spring-context.xml file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:metrics="http://www.ryantenney.com/schema/metrics"
xsi:schemaLocation="
http://www.ryantenney.com/schema/metrics
http://www.ryantenney.com/schema/metrics/metrics.xsd
...other schemas...">
添加了注解驱动的元素:
Added the annotation-driven element:
<metrics:annotation-driven proxy-target-class="true" />
我启用了代理的目标类来获取基于类的自动装配工作。
I enabled proxy-target-class to get class based autowiring working.
而在我想时间豆加@Timed注释和@PostConstruct方法以启用ConsoleReporter倾倒统计,每10秒:
And in the bean I wanted to Time added the @Timed annotation and a @PostConstruct method to enable a ConsoleReporter to dump stats every 10 secs:
@PostConstruct
public void init() {
ConsoleReporter.enable(10, TimeUnit.SECONDS);
}
@Timed
public void doService(...) {
.... do stuff ....
}
我便开始了我的webapp ....从SAX解析器得到了一个讨厌的错误解析春季context.xml文件。
I then started up my webapp .... and got a nasty error from the sax parser parsing the spring context.xml file.
似乎www.ryantenney.com/schema/metrics/metrics.xsd 404以及!
It seems that www.ryantenney.com/schema/metrics/metrics.xsd 404s as well!
有关这一问题的方法很简单,但是,我从网上下载的github存储库中的xsd:
<一href=\"https://github.com/ryantenney/metrics-spring/blob/master/src/main/resources/com/ryantenney/metrics/spring/config/metrics-3.0.xsd\">https://github.com/ryantenney/metrics-spring/blob/master/src/main/resources/com/ryantenney/metrics/spring/config/metrics-3.0.xsd
The workaround for this was simple, however, I downloaded the xsd from the github repository: https://github.com/ryantenney/metrics-spring/blob/master/src/main/resources/com/ryantenney/metrics/spring/config/metrics-3.0.xsd
,然后在src /主/资源/ META-INF我Maven项目目录增加了以下文件:
and then in the src/main/resources/META-INF directory of my maven project added the following files:
META-INF/
- spring.schemas
- xsd/
- metrics.xsd
其中metrics.xsd是从GitHub下载的XSD文件,spring.schemas是包含一个文本文件:
where metrics.xsd is the xsd file downloaded from github, and spring.schemas is a text file containing:
http\://www.ryantenney.com/schema/metrics/metrics.xsd=META-INF/xsd/metrics.xsd
该spring.schemas文件由弹簧在启动时读取并告诉它从本地文件拉下XSD。
The spring.schemas file is read by spring at startup and tells it to pull down the xsd from the local file.
通过上面的地方,我是能够成功地火起来我的应用程序和命中所使用的服务方法的端点。
With the above in place I was able to successfully fire up my app and hit the endpoint that used the service method.
看着控制台我确实看到以下倾倒每隔10秒:
Watching the console I did indeed see the following dumped every 10 seconds:
com.sample.service.MyServiceClass:
doService:
count = 8
mean rate = 0.27 calls/s
1-minute rate = 0.23 calls/s
5-minute rate = 0.21 calls/s
15-minute rate = 0.20 calls/s
min = 0.13ms
max = 19.59ms
mean = 2.59ms
stddev = 6.87ms
median = 0.18ms
这篇关于Yammer的@Timed在零值留下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!