rocketmq-exporter部署(干货)
简单介绍
rocketmq_exporter是prometheus提供的用于监控rocketmq运行状态的exporter
环境
系统 | 版本 |
---|---|
CentOS | 7.6.1810 (Core) |
CPU/内存 | 4核、8G |
clone已有软件包,自行mvn
[root@ecs rocketmq-exporter]# pwd /opt/rocketmq-exporter
vim 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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>org.apache</groupId> <artifactId>rocketmq-exporter</artifactId> <version>0.0.2-SNAPSHOT</version> <name>rocketmq-exporter</name> <description>Apache RocketMQ Prometheus Exporter</description> <properties> <rocketmq.version>4.9.4</rocketmq.version> <docker.image.prefix>docker.io</docker.image.prefix> </properties> <dependencies> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>19.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.rocketmq</groupId> <artifactId>rocketmq-tools</artifactId> <version>${rocketmq.version}</version> </dependency> <dependency> <groupId>org.apache.rocketmq</groupId> <artifactId>rocketmq-store</artifactId> <version>${rocketmq.version}</version> </dependency> <dependency> <groupId>org.jooq</groupId> <artifactId>joor</artifactId> <version>0.9.6</version> </dependency> <dependency> <groupId>io.prometheus</groupId> <artifactId>simpleclient</artifactId> <version>0.6.0</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.7</version> <executions> <execution> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <phase>test</phase> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <executable>true</executable> </configuration> </plugin> <!-- <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-checkstyle-plugin</artifactId> <version>2.17</version> <executions> <execution> <id>verify</id> <phase>verify</phase> <configuration> <configLocation>style/rmq_checkstyle.xml</configLocation> <encoding>UTF-8</encoding> <consoleOutput>true</consoleOutput> <failsOnError>true</failsOnError> <includeTestSourceDirectory>false</includeTestSourceDirectory> </configuration> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> --> <!-- Use dockerfile-maven instead, https://github.com/spotify/dockerfile-maven --> <plugin> <groupId>com.spotify</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.4.11</version> <dependencies> <dependency> <groupId>javax.activation</groupId> <artifactId>javax.activation-api</artifactId> <version>1.2.0</version> <scope>compile</scope> </dependency> </dependencies> <configuration> <imageName>${docker.image.prefix}/${project.artifactId}</imageName> <dockerDirectory>src/main/docker</dockerDirectory> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</directory> <include>${project.build.finalName}.jpackagingar</include> </resource> </resources> </configuration> </plugin> <plugin> <groupId>org.apache.rat</groupId> <artifactId>apache-rat-plugin</artifactId> <version>0.12</version> <configuration> <excludes> <exclude>.travis.yml</exclude> <exclude>.asf.yaml</exclude> <exclude>CONTRIBUTING.md</exclude> <exclude>.github/*</exclude> <exclude>.github/*/*</exclude> <exclude>pom.xml</exclude> <exclude>style/**</exclude> <exclude>README.md</exclude> <exclude>BUILDING</exclude> <exclude>LICENSE</exclude> <exclude>NOTICE</exclude> <exclude>example.rules</exclude> <exclude>rocketmq_exporter_quickstart.md</exclude> <exclude>rocketmq_exporter_overview.json</exclude> <exclude>src/main/resources/application.yml</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.7</version> <configuration> <formats> <format>html</format> <format>xml</format> </formats> <check/> </configuration> </plugin> </plugins> </build> </project>
编辑配置添加namesrvAddr(若roketmq为k8s 部署直接填写k8s地址即可,集群用;隔开)
vim src/main/resources/application.yml
开始编译(后面跟着打docker镜像,若失败可直接进入 target/docker目录手动build docker)
mvn package -Dmaven.test.skip=true docker:build
手动build
docker build -t docker.io/rocketmq-exporter:dev .
手动build时,将编译好的jar包cp到Dockerfile所在目录
cp ../rocketmq-exporter-0.0.2-SNAPSHOT.jar ./
编译
docker build -t docker.io/rocketmq-exporter:dev .
docker push docker.io/rocketmq-exporter:dev
自定义docker 仓库
docker build -t xxxxxxx/rocketmq-exporter:dev .
docker push xxxxxxxx/rocketmq-exporter:dev
使用打出的镜像部署 rocketmq-exporter 到k8s 即可
Prometheus配置
- job_name: rocketmq-exporter-cfhy
static_configs:
- targets: ["rocketmq-exporter.monitoring.svc.cluster.local:5557"] #端口可以在application.yml中自己定义
labels:
instance: rocketmq-exporter-cfhy.rocketmq
grafana导入模板 14612
总结
以上部署rocketmq_exporter监控rocketmq的方法,有问题联系博主,后续也有其他插件,欢迎交流