Search in sources :

Example 6 with MetricsInfo

use of jp.ossc.nimbus.service.aop.interceptor.MetricsInfo in project nimbus by nimbus-org.

the class DefaultInterceptorChain method invokeNext.

// InterceptorChainのJavaDoc
public Object invokeNext(InvocationContext context) throws Throwable {
    final InterceptorChainList list = getInterceptorChainList();
    boolean isError = false;
    boolean isException = false;
    long start = 0;
    if (metricsInfos != null) {
        start = System.currentTimeMillis();
    }
    if (list == null) {
        final Invoker ivk = getInvoker();
        if (ivk != null) {
            try {
                return ivk.invoke(context);
            } catch (Exception e) {
                isException = true;
                throw e;
            } catch (Error err) {
                isError = true;
                throw err;
            } finally {
                if (metricsInfos != null) {
                    long end = System.currentTimeMillis();
                    MetricsInfo metricsInfo = (MetricsInfo) metricsInfos.get(ivk);
                    if (metricsInfo == null) {
                        metricsInfo = new MetricsInfo(createKey(ivk), isCalculateOnlyNormal);
                        MetricsInfo old = (MetricsInfo) metricsInfos.putIfAbsent(ivk, metricsInfo);
                        if (old != null) {
                            metricsInfo = old;
                        }
                    }
                    metricsInfo.calculate(end - start, isException, isError);
                }
            }
        } else {
            return null;
        }
    }
    int index = getCurrentInterceptorIndex();
    try {
        setCurrentInterceptorIndex(++index);
        final Interceptor interceptor = list.getInterceptor(context, index);
        if (interceptor != null) {
            try {
                return interceptor.invoke(context, this);
            } catch (Exception e) {
                isException = true;
                throw e;
            } catch (Error err) {
                isError = true;
                throw err;
            } finally {
                if (metricsInfos != null) {
                    long end = System.currentTimeMillis();
                    MetricsInfo metricsInfo = (MetricsInfo) metricsInfos.get(interceptor);
                    if (metricsInfo == null) {
                        metricsInfo = new MetricsInfo(createKey(interceptor), isCalculateOnlyNormal);
                        MetricsInfo old = (MetricsInfo) metricsInfos.putIfAbsent(interceptor, metricsInfo);
                        if (old != null) {
                            metricsInfo = old;
                        }
                    }
                    metricsInfo.calculate(end - start, isException, isError);
                }
            }
        } else {
            final Invoker ivk = getInvoker();
            if (ivk != null) {
                try {
                    return ivk.invoke(context);
                } catch (Exception e) {
                    isException = true;
                    throw e;
                } catch (Error err) {
                    isError = true;
                    throw err;
                } finally {
                    if (metricsInfos != null) {
                        long end = System.currentTimeMillis();
                        MetricsInfo metricsInfo = (MetricsInfo) metricsInfos.get(ivk);
                        if (metricsInfo == null) {
                            metricsInfo = new MetricsInfo(createKey(ivk), isCalculateOnlyNormal);
                            MetricsInfo old = (MetricsInfo) metricsInfos.putIfAbsent(ivk, metricsInfo);
                            if (old != null) {
                                metricsInfo = old;
                            }
                        }
                        metricsInfo.calculate(end - start, isException, isError);
                    }
                }
            } else {
                return null;
            }
        }
    } finally {
        setCurrentInterceptorIndex(--index);
    }
}
Also used : MetricsInfo(jp.ossc.nimbus.service.aop.interceptor.MetricsInfo)

Example 7 with MetricsInfo

use of jp.ossc.nimbus.service.aop.interceptor.MetricsInfo in project nimbus by nimbus-org.

the class SQLMetricsCollectorService method displayMetricsInfo.

// SQLMetricsCollectorServiceMBeanのJavaDoc
public String displayMetricsInfo() {
    final MetricsInfo[] infos = (MetricsInfo[]) metricsInfos.values().toArray(new MetricsInfo[metricsInfos.size()]);
    Arrays.sort(infos, COMP);
    final SimpleDateFormat format = new SimpleDateFormat(dateFormat);
    final StringBuilder buf = new StringBuilder();
    buf.append("\"No.\"");
    if (isOutputCount) {
        buf.append(",\"Count\"");
    }
    if (isOutputExceptionCount) {
        buf.append(",\"ExceptionCount\"");
    }
    if (isOutputErrorCount) {
        buf.append(",\"ErrorCount\"");
    }
    if (isOutputLastTime) {
        buf.append(",\"LastTime\"");
    }
    if (isOutputLastExceptionTime) {
        buf.append(",\"LastExceptionTime\"");
    }
    if (isOutputLastErrorTime) {
        buf.append(",\"LastErrorTime\"");
    }
    if (isOutputBestPerformance) {
        buf.append(",\"Best performance[ms]\"");
    }
    if (isOutputBestPerformanceTime) {
        buf.append(",\"Best performance time\"");
    }
    if (isOutputWorstPerformance) {
        buf.append(",\"Worst performance[ms]\"");
    }
    if (isOutputWorstPerformanceTime) {
        buf.append(",\"Worst performance time\"");
    }
    if (isOutputAveragePerformance) {
        buf.append(",\"Average performance[ms]\"");
    }
    buf.append(",\"SQL\"");
    buf.append(LINE_SEP);
    for (int i = 0; i < infos.length; i++) {
        buf.append('"').append(i + 1).append('"');
        if (isOutputCount) {
            buf.append(',').append('"').append(infos[i].getCount()).append('"');
        }
        if (isOutputExceptionCount) {
            buf.append(',').append('"').append(infos[i].getExceptionCount()).append('"');
        }
        if (isOutputErrorCount) {
            buf.append(',').append('"').append(infos[i].getErrorCount()).append('"');
        }
        if (isOutputLastTime) {
            if (infos[i].getLastTime() == 0) {
                buf.append(",\"\"");
            } else {
                buf.append(',').append('"').append(format.format(new Date(infos[i].getLastTime()))).append('"');
            }
        }
        if (isOutputLastExceptionTime) {
            if (infos[i].getLastExceptionTime() == 0) {
                buf.append(",\"\"");
            } else {
                buf.append(',').append('"').append(format.format(new Date(infos[i].getLastExceptionTime()))).append('"');
            }
        }
        if (isOutputLastErrorTime) {
            if (infos[i].getLastErrorTime() == 0) {
                buf.append(",\"\"");
            } else {
                buf.append('"').append(',').append(format.format(new Date(infos[i].getLastErrorTime()))).append('"');
            }
        }
        if (isOutputBestPerformance) {
            buf.append(',').append('"').append(infos[i].getBestPerformance()).append('"');
        }
        if (isOutputBestPerformanceTime) {
            if (infos[i].getBestPerformanceTime() == 0) {
                buf.append(",\"\"");
            } else {
                buf.append(',').append('"').append(format.format(new Date(infos[i].getBestPerformanceTime()))).append('"');
            }
        }
        if (isOutputWorstPerformance) {
            buf.append(',').append('"').append(infos[i].getWorstPerformance()).append('"');
        }
        if (isOutputWorstPerformanceTime) {
            if (infos[i].getWorstPerformanceTime() == 0) {
                buf.append(",\"\"");
            } else {
                buf.append(',').append('"').append(format.format(new Date(infos[i].getWorstPerformanceTime()))).append('"');
            }
        }
        if (isOutputAveragePerformance) {
            buf.append(',').append('"').append(infos[i].getAveragePerformance()).append('"');
        }
        buf.append(',').append('"').append(escape(infos[i].getKey())).append('"');
        buf.append(LINE_SEP);
    }
    if (isOutputTimestamp) {
        buf.append(format.format(new Date())).append(LINE_SEP);
    }
    return buf.toString();
}
Also used : MetricsInfo(jp.ossc.nimbus.service.aop.interceptor.MetricsInfo) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

MetricsInfo (jp.ossc.nimbus.service.aop.interceptor.MetricsInfo)7 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 Iterator (java.util.Iterator)1 Category (jp.ossc.nimbus.service.writer.Category)1 MessageWriteException (jp.ossc.nimbus.service.writer.MessageWriteException)1