Created
April 11, 2015 21:22
-
-
Save eleco/71c084207c0a3b121dfc to your computer and use it in GitHub Desktop.
netflix servo demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package servo; | |
import com.netflix.servo.monitor.Counter; | |
import com.netflix.servo.monitor.MonitorConfig; | |
import com.netflix.servo.monitor.Monitors; | |
import com.netflix.servo.monitor.PeakRateCounter; | |
public class ServoDemo { | |
public static void main(String[] args){ | |
Calculator p = new Calculator(); | |
Monitors.registerObject("calculatorStats", p); | |
new Thread(p).start(); | |
} | |
} | |
class Calculator implements Runnable { | |
private final Counter count = Monitors.newCounter("count"); | |
private final PeakRateCounter peakRateCounter = new PeakRateCounter(MonitorConfig.builder("peakrate").build()); | |
public void run() { | |
int totalTime = 60 * 100000; // in millis; | |
long startTime = System.currentTimeMillis(); | |
boolean finished = false; | |
long prime = 1; | |
while (!finished) { | |
if (isPrime(prime)) { | |
System.out.println(prime); | |
count.increment(); | |
peakRateCounter.increment(); | |
} | |
finished = (System.currentTimeMillis() - startTime) >= totalTime; | |
prime ++; | |
} | |
System.out.println("done"); | |
} | |
private boolean isPrime(long n) { | |
for(int i=2;i<=Math.sqrt(n);i++) { | |
if(n%i==0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment