Mbean
mbean的打开很简单,使用jmx启动参数:
java
-Dcom.sun.management.jmxremote.port=9999
-Ddrools.mbeans=enabled
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
但通过jconsole能直观看到的东西也很少
在这里插入图片描述
如果有必要,需要使用代码进一步自行分析,以下是7支持的mbean
Metric
Metric 在doc里面提的很少,几个关键点
- 输出只能在log 和micrometer 二选一
- 只有时间超过threshold才记录
- 只有部分操作记录
输出2选1,及threshold都在以下metric核心类的如下代码中
java
public void logAndEndMetrics() {
if (this.enabled) {
NodeStats stats = (NodeStats)this.nodeStats.get();
if (stats != null && stats.isStarted()) {
long evalCount = stats.getEvalCount();
long elapsedTimeInNanos = System.nanoTime() - stats.getStartTime();
long elapsedTimeInMicro = elapsedTimeInNanos / 1000L;
if (evalCount > 0L && elapsedTimeInMicro > (long)this.threshold) {
if (this.micrometerAvailable) {
MicrometerUtils.INSTANCE.triggerMicrometer(stats.getNode(), evalCount, elapsedTimeInNanos);
} else {
logger.trace("{}, evalCount:{}, elapsedMicro:{}", new Object[]{stats.getNode(), evalCount, elapsedTimeInMicro});
}
}
} else {
logger.warn("nodeStats has to be initialized. Call startMetrics() beforehand : stats = {}", stats);
}
this.nodeStats.remove();
}
}
只有部分操作记录 其实也和上述代码的evalCount 必须大于0有关,以下面的drl 为例:
java
rule "Always Stateless World"
dialect "java"
when
m : Message( status >-1 )
if ( m.getStatus()>2 ) do[giveDiscount]
then
System.out.println( "Always Stateless message" );
Thread.sleep(2000);
then[giveDiscount]
System.out.println( " do---- " );
end
rule "Stateless Hello World"
dialect "mvel"
when
m : Message( status == Message.HELLO, message : message )
then
System.out.println( message );
// modify ( m ) { setMessage( "Goodbyte Stateless cruel world" ),
// setStatus( Message.GOODBYE ) };
modify ( m ) { message = "Goodbye cruel world",
status = Message.GOODBYE };
Thread.sleep(1000);
end
只有如下仅仅ConditionalBranchNode的输出:
powershell
15:08:56.014 [main] TRACE o.drools.metric.util.MetricLogUtils.logAndEndMetrics:94 - [ConditionalBranchNode: cond=if ( org.drools.examples.helloStateLess.Rule_Always_Stateless_World278963341Eval0Invoker@d53a879c ) do[[RuleTerminalNode(6): rule=Always Stateless World, consequence=giveDiscount]]], evalCount:1, elapsedMicro:175
Always Stateless message
Stateless Goodbye cruel world
status=1,Goodbye cruel world
搜索代码incrementEvalCount调用和查看继承关系,大致是如下
会进行记录。