加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
README.adoc 3.96 KB
一键复制 编辑 原始数据 按行查看 历史
Julien Viet 提交于 2021-07-20 15:11 . Update to Vert.x 4.1.2

Vert.x Micrometer Metrics examples

These examples demonstrate how to use the Vert.x Micrometer Metrics module.

There are examples for Prometheus, InfluxDB and JMX backends.

Each of them deploys 3 verticles:

  • SimpleWebServer creates an HTTP server - visit http://localhost:8080/ to trigger requests.

  • EventbusProducer sends messages over the event bus.

  • EventbusConsumer receives event bus messages.

Each simulates a random processing time.

For Prometheus, the verticle WebServerForBoundPrometheus is an alternative of SimpleWebserver that binds the prometheus /metrics endpoint to an existing HTTP server.

Launching the example from the command line

First, build the fat jar:

mvn clean package

Then run any of these Main classes:

Prometheus

Check here for Prometheus getting started guide.

You need to configure the Prometheus server to scrape localhost:8081.

  - job_name: 'vertx-8081'
    static_configs:
      - targets: ['localhost:8081']
Tip

To run a pre-configured Prometheus server on your machine with Docker, go to this example directory and run:

docker run --network host \
-v ${PWD}/prometheus:/etc/prometheus \
-it prom/prometheus

To start the example from the command line:

java -cp target/micrometer-metrics-examples-4.1.2-fat.jar io.vertx.example.micrometer.prometheus.Main

By default, histogram sampling is disabled. You can enable it manually in the Micrometer registry, as shown in commented code in class io.vertx.example.micrometer.prometheus.Main:

registry.config().meterFilter(
    new MeterFilter() {
      @Override
      public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) {
        return DistributionStatisticConfig.builder()
            .percentilesHistogram(true)
            .build()
            .merge(config);
      }
    });

Prometheus with endpoint bound to existing server

java -cp target/micrometer-metrics-examples-4.1.2-fat.jar io.vertx.example.micrometer.prometheus.MainWithBoundPrometheus

You need to configure the Prometheus server to scrape localhost:8080.

  - job_name: 'vertx-8080'
    static_configs:
      - targets: ['localhost:8080']

InfluxDB

This sample application expects an InfluxDB server running on localhost, port 8086, without authentication. For quick setup, you can run it with this docker command:

docker run -p 8086:8086 influxdb

Start the application:

java -cp target/micrometer-metrics-examples-4.1.2-fat.jar io.vertx.example.micrometer.influxdb.Main

JMX

java -cp target/micrometer-metrics-examples-4.1.2-fat.jar io.vertx.example.micrometer.jmx.Main

Metrics will be available under domain metrics.

Triggering some workload

You can trigger some workload to see the impact on HTTP server metrics:

while true
do curl http://localhost:8080/
    sleep .8
done

View in Grafana

Metrics can be observed from Grafana.

Tip

To run a Grafana server on your machine with Docker, go to this example directory and run:

docker run --network host \
-it grafana/grafana

These dashboards track some HTTP server and event bus metrics:

HTTP server metrics

HTTP server metrics

Event bus metrics

Event bus metrics

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化