An EJB to depend on in a ee-project, that supplies:
- a
jolokia.html
index file with stats (and pie chart) from the application jolokia/
the jolokia servletjolokia/name
a text file providing the first found value of- Environment variable
$JOLOKIA_NAME
- Environment variable
$APPLICAITON_NAME
- the application name as declared in the ee container
- Environment variable
- Annotations to provide stats using metric
@Counted
- simple counter@Metered
-@Counted
+ Rate of calls@Timed
-@Metered
+ durations of calls@LifeCycleMetric
- class level annotation needed for the other 3 to work okConstructor
,@PostConstruct
and@PreDestroy
. If this is needed but not supplied, anEJBException
is thrown on startup. If it's present, but unneeded, an error is logged.
This is only for Beans example:
Simple bean invocations
@Stateless
@Path("foo")
public class Foo {
@GET
@Path("now")
@Produces(MediaType.TEXT_PLAIN)
@dk.kosmisk.ee.stats.Timed // @Metered or @Counted
public String now() {
return Instant.now().toString();
}
}
LifeCycle measurements
@Stateless
@LifeCycleMetric
public class Foo {
@PostConstruct
@Timed
public void init() {
// Something time consuming
// like initialization of JavaScript environment
}
}
Remember measurements can only be made on bean-method invocations, ie.
this.method()
cannot me measured.
One workaround is, Make a bean with business logic, and invoke the methods
needed to accomplish the task, this way you can measure which part of the
process that takes time.
You can inject:
- MetricRegistry
- Counter
- Meter
- Timer
Counter/Meter/Timer gets fully qualified name as JMX metric name unless annotated
with @ExposeAs("name")
.
in pom.xml
<dependencies>
...
<dependency>
<groupId>dk.kosmisk</groupId>
<artifactId>ee-stats</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>