本文整理汇总了Java中com.jamonapi.MonitorFactory类的典型用法代码示例。如果您正苦于以下问题:Java MonitorFactory类的具体用法?Java MonitorFactory怎么用?Java MonitorFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MonitorFactory类属于com.jamonapi包,在下文中一共展示了MonitorFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: invokeUnderTrace
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
/**
* Wraps the invocation with a JAMon Monitor and writes the current
* performance statistics to the log (if enabled).
* @see com.jamonapi.MonitorFactory#start
* @see com.jamonapi.Monitor#stop
*/
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
String name = createInvocationTraceName(invocation);
MonKey key = new MonKeyImp(name, name, "ms.");
Monitor monitor = MonitorFactory.start(key);
try {
return invocation.proceed();
}
catch (Throwable ex) {
trackException(key, ex);
throw ex;
}
finally {
monitor.stop();
if (!this.trackAllInvocations || isLogEnabled(logger)) {
logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor);
}
}
}
示例2: testInvokeUnderTraceWithExceptionTracking
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
@Test
public void testInvokeUnderTraceWithExceptionTracking() throws Throwable {
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
given(mi.proceed()).willThrow(new IllegalArgumentException());
try {
interceptor.invokeUnderTrace(mi, log);
fail("Must have propagated the IllegalArgumentException");
}
catch (IllegalArgumentException expected) {
}
assertEquals("Monitors must exist for the method invocation and 2 exceptions",
3, MonitorFactory.getNumRows());
assertTrue("The jamon report must contain the toString method that was invoked",
MonitorFactory.getReport().contains("toString"));
assertTrue("The jamon report must contain the generic exception: " + MonitorFactory.EXCEPTIONS_LABEL,
MonitorFactory.getReport().contains(MonitorFactory.EXCEPTIONS_LABEL));
assertTrue("The jamon report must contain the specific exception: IllegalArgumentException'",
MonitorFactory.getReport().contains("IllegalArgumentException"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:JamonPerformanceMonitorInterceptorTests.java
示例3: profileInvocation
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
public Object profileInvocation(ProceedingJoinPoint pjp) throws Throwable {
if (logger.isDebugEnabled()) {
logger.debug("profiling call for method" + pjp.toLongString());
}
Monitor mon = MonitorFactory.start(createMonitorName(pjp));
try {
return pjp.proceed();
} finally {
mon.stop();
long now = System.currentTimeMillis();
if (now - lastOutput > outputInterval) {
lastOutput = now;
try {
outputStats();
} catch (IOException ioe) {
logger.warn("error writing to '" + getReportOutputLocation() + "'", ioe);
}
}
}
}
示例4: jamonreset
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
public ModelAndView jamonreset(HttpServletRequest request, HttpServletResponse httpServletResponse) {
String tenantId = ServletUtils.getSafeParameter(request, "tenantId", "");
String operatorId = ServletUtils.getSafeParameter(request, "operatorId", "");
ModelAndView mav = new ModelAndView("page");
mav.addObject("title", "easyrec :: administration");
mav.addObject("operatorId", operatorId);
mav.addObject("tenantId", tenantId);
if (Security.isDeveloper(request)) {
mav.setViewName("dev/page");
mav.addObject("page", "output");
mav.addObject("outstr", "report reset");
MonitorFactory.reset();
return mav;
} else {
return MessageBlock.createSingle(mav, MSG.NOT_SIGNED_IN, JAMON_RESET, MSG.ERROR);
}
}
示例5: run
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
@Override
public void run(ExecutionContext ctx, DiagnosticTaskResult result) throws DiagnoseException {
MonitorComposite monco = MonitorFactory.getRootMonitor();
Monitor[] monitors = monco.getMonitors();
if (monitors == null) {
result.setPassedMessage("No monitor activity recorded");
return;
}
// sort monitors by label lexicographically
Arrays.sort(monitors,new Comparator<Monitor>() {
public int compare(Monitor o1, Monitor o2) {
return o1.getLabel().compareTo(o2.getLabel());
}
});
CompositeDiagnosticTaskResult comResult = (CompositeDiagnosticTaskResult) result;
for (Monitor each : monitors) {
DiagnosticTaskResult localResult = new DiagnosticTaskResult(this);
localResult.setComment(each.getLabel());
localResult.setPassedMessage(this.composeRow(each));
comResult.addResult(localResult);
}
}
示例6: invokeUnderTrace
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
/**
* Wraps the invocation with a JAMon Monitor and writes the current
* performance statistics to the log (if enabled).
* @see com.jamonapi.MonitorFactory#start
* @see com.jamonapi.Monitor#stop
*/
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
String name = createInvocationTraceName(invocation);
Monitor monitor = MonitorFactory.start(name);
try {
return invocation.proceed();
}
finally {
monitor.stop();
if (!this.trackAllInvocations || isLogEnabled(logger)) {
logger.trace("JAMon performance statistics for method [" + name + "]:\n" + monitor);
}
}
}
示例7: trackException
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
/**
* Count the thrown exception and put the stack trace in the details portion of the key.
* This will allow the stack trace to be viewed in the JAMon web application.
*/
protected void trackException(MonKey key, Throwable ex) {
String stackTrace = "stackTrace=" + Misc.getExceptionTrace(ex);
key.setDetails(stackTrace);
// Specific exception counter. Example: java.lang.RuntimeException
MonitorFactory.add(new MonKeyImp(ex.getClass().getName(), stackTrace, "Exception"), 1);
// General exception counter which is a total for all exceptions thrown
MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, stackTrace, "Exception"), 1);
}
示例8: testInvokeUnderTraceWithNormalProcessing
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
@Test
public void testInvokeUnderTraceWithNormalProcessing() throws Throwable {
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
interceptor.invokeUnderTrace(mi, log);
assertTrue("jamon must track the method being invoked", MonitorFactory.getNumRows() > 0);
assertTrue("The jamon report must contain the toString method that was invoked",
MonitorFactory.getReport().contains("toString"));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:JamonPerformanceMonitorInterceptorTests.java
示例9: outputStats
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
/**
* @throws IOException
*/
private void outputStats() throws IOException {
if (logger.isInfoEnabled()) {
logger.info("producing html output and writing to '" + reportOutputLocation + "'");
}
if (outfile == null) throw new IllegalStateException("Outfile parameter must not be null!");
String report = MonitorFactory.getRootMonitor().getReport();
FileUtils.writeStringToFile(outfile, report);
if (logger.isDebugEnabled()) {
logger.debug("html output successfully written to '" + reportOutputLocation + "'");
}
}
示例10: storeProfileInternal
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
private Response storeProfileInternal(String apiKey, String tenantID, String itemID, String itemType, String profile) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_STORE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
if (checkParameters(apiKey, tenantID, itemID, itemType, errorMessages) &&
checkParameterProfile(profile, errorMessages)) {
Integer coreTenantID = operatorDAO.getTenantId(apiKey, tenantID);
if (coreTenantID == null)
errorMessages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
else {
if (profileService.storeProfile(coreTenantID, itemID, itemType, profile))
responseObject.add(MSG.PROFILE_SAVED);
else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
}
} catch (IllegalArgumentException illegalArgumentException) {
if (illegalArgumentException.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
} catch (RuntimeException runtimeException) {
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_STORE, null);
mon.stop();
return response;
}
示例11: storeItemWithProfileInternal
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
private Response storeItemWithProfileInternal(String apiKey, String tenantID, String itemID, String itemType,
String itemDescription, String itemUrl, String itemImageUrl, String profile) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_STORE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
Integer coreTenantId = operatorDAO.getTenantId(apiKey, tenantID);
if (checkParameters(coreTenantId, itemID, itemDescription, itemUrl, errorMessages) && checkParameterProfile(profile, errorMessages)) {
itemType = checkItemType(itemType, coreTenantId, Item.DEFAULT_STRING_ITEM_TYPE, errorMessages);
if (itemType != null) {
itemDAO.insertOrUpdate(coreTenantId, itemID, itemType, itemDescription, itemUrl, itemImageUrl);
if (profileService.storeProfile(coreTenantId, itemID, itemType, profile))
responseObject.add(MSG.PROFILE_SAVED);
else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
}
} catch (IllegalArgumentException illegalArgumentException) {
if (illegalArgumentException.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else
errorMessages.add(MSG.PROFILE_NOT_SAVED);
} catch (RuntimeException runtimeException) {
errorMessages.add(MSG.PROFILE_NOT_SAVED);
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_STORE, null);
mon.stop();
return response;
}
示例12: pushFieldInternal
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
private Response pushFieldInternal(String apiKey, String tenantID, String itemID, String itemType, String path, String value) {
Monitor mon = MonitorFactory.start(JAMON_PROFILE_FIELD_STORE);
List<Message> errorMessages = new ArrayList<>();
List<Message> responseObject = new ArrayList<>();
try {
if (checkParameters(apiKey, tenantID, itemID, itemType, errorMessages) &&
checkParameterValue(value, errorMessages)) {
Integer coreTenantID = operatorDAO.getTenantId(apiKey, tenantID);
if (coreTenantID == null)
errorMessages.add(MSG.TENANT_WRONG_TENANT_APIKEY);
else {
if (profileService.pushToArrayField(
coreTenantID, itemID, itemType,
path, value))
responseObject.add(MSG.PROFILE_FIELD_SAVED);
else
errorMessages.add(MSG.PROFILE_FIELD_NOT_SAVED);
}
}
} catch (Exception e) {
if (e instanceof IllegalArgumentException) {
if (e.getMessage().contains("unknown item type")) {
errorMessages.add(MSG.OPERATION_FAILED.append(
String.format(" itemType %s not found for tenant %s", itemType, tenantID)));
} else {
errorMessages.add(MSG.PROFILE_FIELD_NOT_SAVED.append(e.getMessage()));
}
} else {
errorMessages.add(MSG.OPERATION_FAILED.append(
"Exception: " + e.getMessage()));
}
}
Response response = formatResponse(responseObject, errorMessages,
WS.PROFILE_FIELD_PUSH, null);
mon.stop();
return response;
}
示例13: getServiceMonitors
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
/**
* Retrieves all the Service Monitor Values
*/
public ServiceMonitorVoCollection getServiceMonitors(String filter)
{
MonitorComposite rootMonitor = MonitorFactory.getRootMonitor();
Monitor[] allMonitors = rootMonitor.getMonitors();
ServiceMonitorVoCollection ret = new ServiceMonitorVoCollection();
Monitor currentMonitor = null;
String serviceName = null;
for (int i = 0; i < allMonitors.length; i++)
{
currentMonitor = allMonitors[i];
ServiceMonitorVo vo = new ServiceMonitorVo();
List list = new ArrayList();
currentMonitor.getMonKey().getRowData(list);
serviceName = list.get(0).toString();
if (filter == null || filter.equals("") || (serviceName.indexOf(filter) != -1))
{
vo.setServiceName(serviceName);
vo.setHits(new Integer((int) currentMonitor.getHits()));
vo.setAvg(new Integer((int) currentMonitor.getAvg()));
vo.setTotal(new Integer((int) currentMonitor.getTotal()));
vo.setStdDev(new Float((float) currentMonitor.getStdDev()));
vo.setLast(new Float((float) currentMonitor.getLastValue()));
vo.setMin(new Float((float) currentMonitor.getMin()));
vo.setMax(new Float((float) currentMonitor.getMax()));
vo.setActive(new Integer((int) currentMonitor.getActive()));
vo.setAvgActive(new Float((float) currentMonitor.getAvgActive()));
vo.setMaxActive(new Integer((int) currentMonitor.getMaxActive()));
vo.setFirstAccess(new DateTime(currentMonitor.getFirstAccess()));
vo.setLastAccess(new DateTime(currentMonitor.getLastAccess()));
ret.add(vo);
}
}
return ret;
}
示例14: trackException
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
@Override
protected void trackException(JoinPoint jp, Throwable throwable) {
AutomonExpirable exceptionContext = populateArgNamesAndValues_InExceptionContext(jp, throwable);
// Multiple monitors are tracked for the exception such as one of the specific exception and one that represents
// all exceptions.
List<String> labels = getLabels(throwable);
for (String label : labels) {
MonKey key = new MonKeyImp(label, exceptionContext, "Exception");
MonitorFactory.add(key, 1);
}
}
示例15: testException
import com.jamonapi.MonitorFactory; //导入依赖的package包/类
@Test
public void testException() throws Exception {
assertThat(MonitorFactory.exists(SharedConstants.EXCEPTION_LABEL, "Exception")).describedAs("The exception monitor should not exist yet").isFalse();
openMon.exception(jp, SharedConstants.EXCEPTION);
assertThat(MonitorFactory.getMonitor(SharedConstants.EXCEPTION_LABEL, "Exception").getHits()).describedAs("One exception should have been thrown").isEqualTo(1);
assertThat(MonitorFactory.getMonitor(OpenMon.EXCEPTION_LABEL, "Exception").getHits()). describedAs("One exception should have been thrown").isEqualTo(1);
Map<Throwable, AutomonExpirable> map = openMon.getExceptionsMap();
assertThat(map.get(SharedConstants.EXCEPTION).getThrowable()).describedAs("Throwable should have been set").isEqualTo(SharedConstants.EXCEPTION);
assertThat(map.get(SharedConstants.EXCEPTION).getArgNamesAndValues()).describedAs("Arg names and values should have been set").isNotNull();
}