Created
January 29, 2016 21:48
-
-
Save johann8384/1bd4bc4d985eadf56017 to your computer and use it in GitHub Desktop.
Metrics and Stuff
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
import com.google.common.collect.ImmutableMap; | |
import com.github.sps.metrics.OpenTsdbReporter; | |
import com.github.sps.metrics.opentsdb.OpenTsdbTelnet; | |
import com.turn.metrics.system.OperatingSystemMetricSet; | |
import com.turn.metrics.system.FileSystemMetricSet; | |
import com.turn.metrics.system.RuntimeMetricSet; | |
import static java.util.concurrent.TimeUnit.*; | |
static final MetricRegistry metrics = new MetricRegistry(); | |
metrics.registerAll(new OperatingSystemMetricSet()); | |
metrics.registerAll(new FileSystemMetricSet()); | |
metrics.registerAll(new RuntimeMetricSet()); | |
OpenTsdbReporter.forRegistry(metrics) | |
.prefixedWith("app_name") | |
.withTags(ImmutableMap.of("other", "tags")) | |
.build(OpenTsdbTelnet.forService("localhost", 4242) | |
.create()).start(15, SECONDS); | |
private final Timer responses = metrics.timer(name(RequestHandler.class, "responses")); | |
final Timer.Context context = responses.time(); | |
try { | |
// etc; | |
return "OK"; | |
} finally { | |
context.stop(); | |
} | |
private final Counter pendingJobs = metrics.counter(name(QueueManager.class, "pending-jobs")); | |
pendingJobs.inc(); | |
metrics.register(MetricRegistry.name(QueueManager.class, name, "size"), | |
new Gauge<Integer>() { | |
@Override | |
public Integer getValue() { | |
return queue.size(); | |
} | |
}); | |
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
<pom> | |
<repositories> | |
<repository> | |
<id>jitpack.io</id> | |
<url>https://jitpack.io</url> | |
</repository> | |
</repositories> | |
<dependencies> | |
<dependency> | |
<groupId>io.dropwizard</groupId> | |
<artifactId>dropwizard-core</artifactId> | |
<version>${dropwizard.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>io.dropwizard.metrics</groupId> | |
<artifactId>metrics-core</artifactId> | |
<version>${metrics.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>com.github.inst-tech</groupId> | |
<artifactId>metrics-opentsdb</artifactId> | |
<version>1.0.6</version> | |
</dependency> | |
<dependency> | |
<groupId>com.github.inst-tech</groupId> | |
<artifactId>metrics-system</artifactId> | |
<version>1.1.0</version> | |
</dependency> | |
</dependencies> | |
</pom> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment