本文整理匯總了Java中org.javasimon.SimonManager類的典型用法代碼示例。如果您正苦於以下問題:Java SimonManager類的具體用法?Java SimonManager怎麽用?Java SimonManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SimonManager類屬於org.javasimon包,在下文中一共展示了SimonManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runDiskTest
import org.javasimon.SimonManager; //導入依賴的package包/類
private void runDiskTest ( int diskInMb ) {
Split timer = SimonManager.getStopwatch( INFRASTRUCTURE_TEST_DISK ).start();
try {
int blockSize = 1024;
long numBlocks = diskInMb * 1024 * 1024 / blockSize;
String[] diskTestScript = {
"#!/bin/bash",
"cd ~",
"time dd if=/dev/zero of=csap_test_file bs="+ blockSize + " count=" + numBlocks,
"sync",
"ls -l csap_test_file",
"rm -rf csap_test_file",
"" };
String testResults = osCommandRunner.runUsingDefaultUser( "diskTest", diskTestScript );
if ( showDiskOutputOnce ) {
logger.info( "Results from {}, \n {}", Arrays.asList( diskTestScript ), testResults );
showDiskOutputOnce=false;
}
} catch (Exception e) {
logger.warn( "Failed disk test execution: {}", CSAP.getCsapFilteredStackTrace( e ) );
}
timer.stop();
}
示例2: runCpuTest
import org.javasimon.SimonManager; //導入依賴的package包/類
private void runCpuTest ( int cpuLoopsMillions ) {
Split timer = SimonManager.getStopwatch( INFRASTRUCTURE_TEST_CPU ).start();
try {
long numLoops = cpuLoopsMillions * 1000000;
String[] diskTestScript = {
"#!/bin/bash",
"time $(i="
+ numLoops
+ "; while (( i > 0 )); do (( i=i-1 )); done)",
"" };
String testResults = osCommandRunner.runUsingDefaultUser( "diskTest", diskTestScript );
if ( showCpuOutputOnce ) {
logger.info( "Results from {}, \n {}", Arrays.asList( diskTestScript ), testResults );
showCpuOutputOnce=false;
}
} catch (Exception e) {
logger.warn( "Failed disk test execution: {}", CSAP.getCsapFilteredStackTrace( e ) );
}
timer.stop();
}
示例3: call
import org.javasimon.SimonManager; //導入依賴的package包/類
@Override
public AgentStatus call () {
// Thread.currentThread().setName("HostQuery_" + host);
// if ( !Thread.currentThread().getName().contains("hostQuery") )
// Thread.currentThread().setName("hostQuery_" +
// Thread.currentThread().getName());
Split transferTimer = SimonManager.getStopwatch( "agent.remote.status" ).start();
String jsonResponse = "{\"error\": \"Reason: Initialization in Progress: "
+ host + "\"}";
// always use pooled connection
RestTemplate pooledRest =csapApp.getAgentPooledConnection( 1, 1 ) ;
jsonResponse = queryAgentStatus( pooledRest );
transferTimer.stop();
SimonManager.getStopwatch( "agent.remote.status." + host ).addSplit( transferTimer );
SimonManager.getStopwatch( "java.HostStatusManager.getHostRuntimeJson" ).addSplit( transferTimer );
logger.debug( "{} pool: {} \n response: {}", host, pooledRest, jsonResponse );
return new AgentStatus( host, jsonResponse );
}
示例4: getOpenFilesForInstance
import org.javasimon.SimonManager; //導入依賴的package包/類
/**
*
*
*
*
*/
@CsAgentTimer
private void getOpenFilesForInstance ( ServiceInstance instance ) {
int fileCount = 0;
boolean isCsapProcess = (instance.getUser() == null);
Split openFilesTimer = SimonManager.getStopwatch( "java.OsManager.getOpenFiles." + instance.getServiceName() ).start();
if ( isCsapProcess && !instance.isDockerContainer() ) {
fileCount = getFilesUsingJavaNio( instance, fileCount );
} else {
fileCount = getOpenFilesForNonCsapProcesses( instance );
}
openFilesTimer.stop();
instance.setFileCount( fileCount );
if ( logger.isDebugEnabled() ) {
logger.debug( instance.getServiceName() + " javaFileCount : " + fileCount );
}
}
示例5: findAndRunActiveJobs
import org.javasimon.SimonManager; //導入依賴的package包/類
public void findAndRunActiveJobs () {
Stopwatch allStopWatch = SimonManager.getStopwatch( SERVICE_JOB_ID + "all.script.checkForActive" );
Split allServicesSplit = allStopWatch.start();
try {
csapApplication.getActiveModel()
.getServicesOnHost( Application.getHOST_NAME() )
.filter( ServiceInstance::hasJobs )
.flatMap( this::jobEntries )
.forEach( jobEntry -> {
jobRunnerService.submit( () -> runJob( jobEntry ) );
} );
} catch (Exception e) {
logger.error( "Failed to schedule job", CSAP.getCsapFilteredStackTrace( e ) );
}
allServicesSplit.stop();
}
示例6: updateServicesWithArtifacts
import org.javasimon.SimonManager; //導入依賴的package包/類
public void updateServicesWithArtifacts () {
logger.debug( "starting scan" );
// admins scan for versions for platform score.
// if ( isJvmInManagerMode() ) {
// logger.debug( "Skipping scan as managers access instance state
// through runtime data" );
// return;
// }
Split allServicesSplit = SimonManager.getStopwatch( "application.artifact.scan" ).start();
getActiveModel()
.getServicesOnHost( Application.getHOST_NAME() )
.filter( ServiceInstance::isFileSystemScanRequired )
.forEach( this::scanServiceFolderForArtifacts );
allServicesSplit.stop();
}
示例7: dockerOpenSockets
import org.javasimon.SimonManager; //導入依賴的package包/類
public String dockerOpenSockets ( String pid ) {
String[] lines = {
"#!/bin/bash",
socketStatCommand( pid ) + "r", // resolve host names
"" };
String scriptOutput = "Failed to run";
Split socketTimer = SimonManager.getStopwatch( "docker.socket" ).start();
try {
scriptOutput = osCommandRunner.runUsingRootUser( "dockerSocketStat", lines );
logger.debug( "output from: {} , \n{}", lines[1], scriptOutput );
} catch (IOException e) {
logger.info( "Failed to run docker nsenter: {} , \n reason: {}", lines,
CSAP.getCsapFilteredStackTrace( e ) );
scriptOutput += ", reason: " + e.getMessage() + " type: " +
e.getClass().getName();
}
socketTimer.stop();
return scriptOutput;
}
示例8: handleIOException
import org.javasimon.SimonManager; //導入依賴的package包/類
@ExceptionHandler(IOException.class)
public void handleIOException(HttpServletRequest request, Exception e, HttpServletResponse response) {
String stackFrames = ExceptionUtils.getStackTrace( e ) ;
if ( stackFrames.contains("ClientAbortException")) {
logger.info("ClientAbortException found: " + e.getMessage());
} else {
logger.warn( "{}: {}", request.getRequestURI(),CSAP.getCsapFilteredStackTrace( e ));
SimonManager.getCounter( CsapGlobalId.EXCEPTION.id ).increase();
try {
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value() );
response.getWriter().print( HttpStatus.INTERNAL_SERVER_ERROR.value() + " : Exception during processing, examine server Logs");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
示例9: main
import org.javasimon.SimonManager; //導入依賴的package包/類
public static void main(String[] args) throws InterruptedException {
String stopwatchName = "stopwatch";
Split cpuSplit = Split.start(SimonClock.CPU);
Split systemSplit = Split.start();
System.out.println("cpuSplit = " + cpuSplit);
System.out.println("systemSplit = " + systemSplit);
for (int loop = 0; loop < 10; loop++) {
for (int i = 0; i < 1000000; i++) {
SimonManager.getStopwatch(stopwatchName);
}
Thread.sleep(200); // this should cause roughly 200 ms difference on each loop
System.out.println("\nAfter iteration #" + loop);
System.out.println("cpuSplit = " + cpuSplit);
System.out.println("systemSplit = " + systemSplit);
}
}
示例10: addChangingSimons
import org.javasimon.SimonManager; //導入依賴的package包/類
/**
* Starts a timer which changes Simons values.
* TL is used to test Timeline and Quantiles plugins rendering.
*/
public void addChangingSimons() {
timer.schedule(new TimerTask() {
final Stopwatch tlStopwatch = SimonManager.getStopwatch("TL");
@Override
public void run() {
try {
lock.lock();
System.out.println("TL " + addStopwatchSplit(tlStopwatch));
} finally {
lock.unlock();
}
}
}, 0, 10000L);
}
示例11: method
import org.javasimon.SimonManager; //導入依賴的package包/類
private static void method() {
// StopWatch stopWatch = new LoggingStopWatch();
Split split = SimonManager.getStopwatch("codeBlock2").start();
try {
// the code block being timed - this is just a dummy example
long sleepTime = (long) (Math.random() * 1000L);
Thread.sleep(sleepTime);
if (sleepTime > 500L) {
throw new Exception("Throwing exception");
}
split.stop("success");
// stopWatch.stop("codeBlock2.success", "Sleep time was < 500 ms");
} catch (Exception e) {
split.stop("failure");
// stopWatch.stop("codeBlock2.failure", "Exception was: " + e);
}
}
示例12: register
import org.javasimon.SimonManager; //導入依賴的package包/類
private static SimonManagerMXBeanImpl register() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
ObjectName name = new ObjectName("org.javasimon.jmx.example:type=Simon");
if (mbs.isRegistered(name)) {
mbs.unregisterMBean(name);
}
SimonManagerMXBeanImpl simon = new SimonManagerMXBeanImpl(SimonManager.manager());
mbs.registerMBean(simon, name);
System.out.println("SimonManagerMXBean registerd under name: " + name);
return simon;
} catch (JMException e) {
System.out.println("SimonManagerMXBean registration failed!\n" + e);
}
return null;
}
示例13: main
import org.javasimon.SimonManager; //導入依賴的package包/類
/**
* Entry point to the JMX Callback Example.
*
* @param args unused
* @throws Exception whatever may happen in this crazy world
*/
@SuppressWarnings("InfiniteLoopStatement")
public static void main(String[] args) throws Exception {
SimonManager.callback().addCallback(new JmxRegisterCallback("org.javasimon.examples.jmx.JmxCallbackExample"));
Counter counter = SimonManager.getCounter("org.javasimon.examples.jmx.counter");
Stopwatch stopwatch = SimonManager.getStopwatch("org.javasimon.examples.jmx.stopwatch");
// these created just to have more stuff in jconsole
SimonManager.getCounter("org.javasimon.different.counter");
SimonManager.getStopwatch("org.javasimon.some.other.jmx.stopwatch1");
SimonManager.getStopwatch("org.javasimon.some.other.jmx.stopwatch2");
System.out.println("Now open jconsole and check it out...\nWatch org.javasimon.examples.jmx.stopwatch for changes.");
while (true) {
counter.increase();
try (Split ignored = stopwatch.start()) {
ExampleUtils.waitRandomlySquared(40);
}
}
}
示例14: register
import org.javasimon.SimonManager; //導入依賴的package包/類
/**
* Register Simon MXBean into platform MBeanServer under
* {@code org.javasimon.jmx.example:type=Simon} name.
*
* @return registered SimonManagerMXBean implementation object
*/
private static SimonManagerMXBean register() {
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
try {
ObjectName name = new ObjectName("org.javasimon.jmx.example:type=Simon");
if (mbs.isRegistered(name)) {
mbs.unregisterMBean(name);
}
SimonManagerMXBean simonManagerMXBean = new SimonManagerMXBeanImpl(SimonManager.manager());
mbs.registerMBean(simonManagerMXBean, name);
System.out.println("SimonManagerMXBean registerd under name: " + name);
return simonManagerMXBean;
} catch (JMException e) {
System.out.println("SimonManagerMXBean registration failed!\n" + e);
}
return null;
}
示例15: initServer
import org.javasimon.SimonManager; //導入依賴的package包/類
private void initServer() throws IOException, JMException {
// Register JMX
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName beanObjectName = new ObjectName("org.javasimon:type=Manager");
SimonManagerMXBeanImpl bean = new SimonManagerMXBeanImpl(SimonManager.manager());
beanServer.registerMBean(bean, beanObjectName);
// Server
Map<String, String> serverConfigMap = new HashMap<>();
JolokiaServerConfig serverConfig = new JolokiaServerConfig(serverConfigMap);
server = new JolokiaServer(serverConfig, true);
// Callbacks
CompositeCallback compositeCallback = new CompositeCallbackImpl();
// QuantilesCallback automatically configured after 5 splits (5 buckets)
compositeCallback.addCallback(new AutoQuantilesCallback(5, 5));
// QuantilesCallback manually configured 5 duration buckets 200ms wide each
// compositeCallback.addCallback(new FixedQuantilesCallback(0L, 200L, 5));
// TimelineCallback 10 time range buckets of 1 minute each
compositeCallback.addCallback(new TimelineCallback(10, 60000L));
compositeCallback.addCallback(new JmxRegisterCallback(beanServer, "org.javasimon"));
SimonManager.callback().addCallback(new AsyncCallbackProxyFactory(compositeCallback).newProxy());
// CallTreeCallback doesn't support asynchronous operation
SimonManager.callback().addCallback(new CallTreeCallback(50));
}