我将akka
(java) 与spring boot
. 我想监控指标kamon
并将其显示在grafana
仪表板上。我已经包含kamon core
kamon statsd
在依赖项中,并application.conf
使用正确的端口和主机名创建了statsd
. 没有明确的示例或教程可以显示我正在使用的堆栈。是否可以akka
使用spring boo
t来衡量指标java
,akka
并kamon
在 中部署为战争tomcat
?
问问题
1745 次
1 回答
4
这里是一个简单的例子
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>kamon.annotation</groupId>
<artifactId>kamon-spring-boot</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.kamon</groupId>
<artifactId>kamon-core_2.11</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>io.kamon</groupId>
<artifactId>kamon-annotation_2.11</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>io.kamon</groupId>
<artifactId>kamon-akka_2.11</artifactId>
<version>0.6.2</version>
</dependency>
<dependency>
<groupId>io.kamon</groupId>
<artifactId>kamon-log-reporter_2.11</artifactId>
<version>0.6.2</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>io.kamon</id>
<url>http://snapshots.kamon.io</url>
</repository>
</repositories>
两个演员打乒乓球
import akka.actor.UntypedActor;
class Pinger extends UntypedActor {
static final class PingMessage {}
public void onReceive(Object message) throws Exception {
if (message instanceof Ponger.PongMessage) getSender().tell(new PingMessage(), getSelf());
else unhandled(message);
}
}
import akka.actor.UntypedActor;
class Ponger extends UntypedActor {
static final class PongMessage {}
public void onReceive(Object message) throws Exception {
if (message instanceof Pinger.PingMessage) getSender().tell(new PongMessage(), getSelf());
else unhandled(message);
}
}
一个弹簧组件
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
import akka.actor.Props;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class PingPong {
@PostConstruct
public void initialize() {
final ActorSystem system = ActorSystem.create("kamon-spring-boot-actor-system");
final ActorRef pinger = system.actorOf(Props.create(Pinger.class), "pinger");
final ActorRef ponger = system.actorOf(Props.create(Ponger.class), "ponger");
pinger.tell(new Ponger.PongMessage(), ponger);
}
}
还制作一个简单的控制器,以显示使用kamon-annotation模块收集其他一些指标是多么简单
import org.springframework.boot.autoconfigure.*;
import org.springframework.stereotype.*;
import org.springframework.web.bind.annotation.*;
@Controller
@EnableAutoConfiguration
@RequestMapping("/kamon")
@EnableKamon
public class KamonController {
@RequestMapping("/counter")
@ResponseBody
@Count(name = "awesomeCounter")
public String counter() { return "count!!!"; }
}
应用程序主
import kamon.akka.pingpong.PingPong;
import kamon.annotation.KamonController;
import org.springframework.boot.SpringApplication;
public class KamonSpringApplication {
public static void main(String... args) {
Kamon.start();
SpringApplication.run(KamonController.class, args);
}
}
为测试目的而简化的 application.conf
kamon {
metric {
filters {
trace.includes = [ "**" ]
akka-actor.includes = [ "**" ]
akka-actor.excludes = ["*/system/**", "*/user/IO-**" ]
akka-dispatcher.includes = [ "**" ]
akka-dispatcher.excludes = [ ]
}
}
}
构建应用程序并运行
mvn package && java -javaagent:/path/to/aspectjweaver.jar -jar target/kamon-spring-boot-0.1.0.jar
我们应该得到这样的东西吗
+--------------------------------------------------------------------------------------------------+
| |
| Actor: kamon-spring-boot-actor-system/user/pinger |
| |
| Processing Time (nanoseconds) Time in Mailbox (nanoseconds) Mailbox Size |
| Msg Count: 3393358 Msg Count: 3393405 Min: 0 |
| Min: 237 Min: 178 Avg.: 0.0 |
| 50th Perc: 672 50th Perc: 756 Max: 2 |
| 90th Perc: 988 90th Perc: 1264 |
| 95th Perc: 1088 95th Perc: 1368 |
| 99th Perc: 1520 99th Perc: 1848 Error Count: 0 |
| 99.9th Perc: 20480 99.9th Perc: 17920 |
| Max: 16646144 Max: 34865152 |
| |
+--------------------------------------------------------------------------------------------------+
+--------------------------------------------------------------------------------------------------+
| |
| Actor: kamon-spring-boot-actor-system/user/ponger |
| |
| Processing Time (nanoseconds) Time in Mailbox (nanoseconds) Mailbox Size |
| Msg Count: 3739208 Msg Count: 3739161 Min: 0 |
| Min: 272 Min: 172 Avg.: 0.0 |
| 50th Perc: 672 50th Perc: 732 Max: 2 |
| 90th Perc: 976 90th Perc: 1232 |
| 95th Perc: 1064 95th Perc: 1344 |
| 99th Perc: 1360 99th Perc: 1656 Error Count: 0 |
| 99.9th Perc: 10496 99.9th Perc: 14272 |
| Max: 7766016 Max: 30277632 |
| |
+--------------------------------------------------------------------------------------------------+
如果我们做 2 个卷发
http://localhost:8080/kamon/counter
http://localhost:8080/kamon/counter
+--------------------------------------------------------------------------------------------------+
| |
| Counters |
| ------------- |
| awesomeCounter => 2 |
| |
| |
| Histograms |
| -------------- |
| |
| MinMaxCounters |
| ----------------- |
| |
| Gauges |
| ---------- |
| |
+--------------------------------------------------------------------------------------------------+
链接到完整的例子。
希望这可以帮到你。
于 2016-08-24T19:48:58.253 回答