├── .gitignore
├── README.md
├── grafana
└── sample.png
├── pom.xml
├── spring-boot-monitoring-actuator-prometheus-grafana
├── Dockerfile
├── docker-compose.yml
├── grafana
│ └── Spring Boot监控.json
├── pom.xml
├── prometheus
│ └── prometheus.yml
└── src
│ └── main
│ ├── java
│ └── fun
│ │ └── pullock
│ │ └── monitoring
│ │ └── MonitoringActuatorPrometheusGrafanaApplication.java
│ └── resources
│ └── application.yml
├── spring-boot-monitoring-actuator-telegraf-influxdb-grafana
├── Dockerfile
├── docker-compose.yml
├── grafana
│ └── Spring Boot监控.json
├── pom.xml
├── src
│ └── main
│ │ ├── java
│ │ └── fun
│ │ │ └── pullock
│ │ │ └── monitoring
│ │ │ └── MonitoringActuatorTelegrafInfluxdbGrafanaApplication.java
│ │ └── resources
│ │ └── application.yml
└── telegraf
│ └── telegraf.conf
├── spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana
├── Dockerfile
├── docker-compose.yml
├── grafana
│ └── Spring Boot监控.json
├── pom.xml
├── src
│ └── main
│ │ ├── java
│ │ └── fun
│ │ │ └── pullock
│ │ │ └── monitoring
│ │ │ └── MonitoringActuatorTelegrafInfluxdb1xGrafanaApplication.java
│ │ └── resources
│ │ └── application.yml
└── telegraf
│ └── telegraf.conf
├── spring-boot-monitoring-admin
├── README.md
├── pom.xml
├── spring-boot-monitoring-admin-client
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ ├── java
│ │ └── fun
│ │ │ └── pullock
│ │ │ └── monitoring
│ │ │ └── MonitoringAdminClientApplication.java
│ │ └── resources
│ │ └── application.yml
└── spring-boot-monitoring-admin-server
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ └── fun
│ │ └── pullock
│ │ └── monitoring
│ │ ├── AdminServerConfig.java
│ │ └── MonitoringAdminServerApplication.java
│ └── resources
│ └── application.yml
├── spring-boot-monitoring-skywalking
├── Dockerfile
├── README.md
├── docker-compose.yml
├── pom.xml
└── src
│ └── main
│ └── java
│ └── fun
│ └── pullock
│ └── monitoring
│ ├── MonitoringSkywalkingApplication.java
│ ├── controller
│ └── UserController.java
│ └── service
│ └── UserService.java
└── spring-boot-monitoring-sleuth-zipkin
├── Dockerfile
├── README.md
├── docker-compose.yml
├── pom.xml
└── src
└── main
├── java
└── fun
│ └── pullock
│ └── monitoring
│ ├── MonitoringSleuthZipkinApplication.java
│ ├── controller
│ └── UserController.java
│ └── service
│ └── UserService.java
└── resources
└── application.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | *.iml
3 | target/
4 | .DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Spring-boot-monitoring
2 |
3 | Spring boot项目监控,作为一个示例项目,研究其可行性。
4 |
5 | 
6 |
7 | # 方案
8 |
9 | - `Spring Boot Actuator` + `Telegraf` + `Influxdb 1.x` + `Grafana`
10 | - `Spring Boot Actuator` + `Telegraf` + `Influxdb 2.x` + `Grafana`
11 | - `Spring Boot Actuator` + `Prometheus` + `Grafana`
12 | - `Spring Boot Actuator` + `Spring Boot Admin`,具体可参考`spring-boot-monitoring-admin`模块
13 |
14 | # Spring Boot Actuator + Telegraf + Influxdb 1.x + Grafana方案
15 |
16 | Spring boot项目,开启Actuator和Jolokia支持,使用Telegraf采集项目运行信息,InfluxDB 1.x时序数据库存储数据,Grafana展示数据。
17 |
18 | ## 将当前项目打包为Docker镜像
19 |
20 | 1. 在`spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana`根目录下创建`Dockerfile`文件,文件内容如下:
21 |
22 | ```
23 | FROM openjdk:8-jre-alpine
24 |
25 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
26 | apk update && \
27 | mkdir -p /app
28 | COPY target/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana-1.0.0-SNAPSHOT.jar app/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana.jar
29 | EXPOSE 8080
30 | ENTRYPOINT ["java", "-jar", "app/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana.jar"]
31 | ```
32 |
33 | 2. 将项目`spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana`进行打包:`mvn clean package -Dmaven.test.skip=true`
34 |
35 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana:1.0.0-SNAPSHOT .`
36 |
37 | ## 使用Docker启动Telegraf、Influxdb 1.x、Grafana以及示例项目
38 |
39 | 使用docker compose安装`Telegraf`、`Influxdb 1.x`和`Grafana`:
40 |
41 | 1. 先编写`docker-compose.yml`文件,内容参考下方的`docker-compose.yml`文件内容
42 | 2. 启动`docker compose up -d`
43 | 3. 访问grafana:`http://localhost:3000`,grafana的默认用户名密码:`admin/admin`
44 | 4. 在grafana创建数据源,在Query Language中选择InfluxQL,这样才可以设置Influxdb 1.x的信息
45 | 5. 创建完数据源后,在Dashboards中选择Import,然后选择`spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana/grafana/SpringBoot监控.json`文件进行导入
46 |
47 | ## 怎样运行当前方案
48 |
49 | 1. 克隆当前项目,进入`spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana`目录下
50 | 2. 将项目`spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana`进行打包:`mvn clean package -Dmaven.test.skip=true`
51 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana:1.0.0-SNAPSHOT .`
52 | 4. 启动:`docker compose up -d`
53 | 5. 访问grafana:`http://localhost:3000`,grafana的默认用户名密码:`admin/admin`
54 | 6. 在grafana创建数据源,在Query Language中选择InfluxQL,这样才可以设置Influxdb 1.x的信息
55 | 7. 创建完数据源后,在Dashboards中选择Import,然后选择`spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana/grafana/SpringBoot监控.json`文件进行导入
56 |
57 | ## `docker-compose.yml`文件内容
58 |
59 | ```yaml
60 | version: "3.8"
61 |
62 | # 定义网络:local_net
63 | networks:
64 | local_net:
65 | name: local_net
66 |
67 | # 定义服务
68 | services:
69 | # influxdb服务
70 | influxdb:
71 | image: influxdb:1.8
72 | ports:
73 | - 8086:8086
74 | networks:
75 | - local_net
76 | environment:
77 | - INFLUXDB_DB=telegraf
78 | - INFLUXDB_ADMIN_USER=admin
79 | - INFLUXDB_ADMIN_PASSWORD=12345678
80 | - INFLUXDB_USER=telegraf
81 | - INFLUXDB_USER_PASSWORD=12345678
82 |
83 | # telegraf服务
84 | telegraf:
85 | image: telegraf:latest
86 | networks:
87 | - local_net
88 | depends_on:
89 | - influxdb
90 | volumes:
91 | - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
92 |
93 | # grafana服务
94 | grafana:
95 | image: grafana/grafana:latest
96 | ports:
97 | - 3000:3000
98 | networks:
99 | - local_net
100 |
101 | # 示例项目服务
102 | spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana:
103 | image: local_test/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana:1.0.0-SNAPSHOT
104 | ports:
105 | - 8080:8080
106 | networks:
107 | - local_net
108 | ```
109 |
110 | # Spring Boot Actuator + Telegraf + Influxdb 2.x + Grafana方案
111 |
112 | Spring boot项目,开启Actuator和Jolokia支持,使用Telegraf采集项目运行信息,InfluxDB 2.x时序数据库存储数据,Grafana展示数据。
113 |
114 | ## 将当前项目打包为Docker镜像
115 |
116 | 1. 在`spring-boot-monitoring-actuator-telegraf-influxdb-grafana`根目录下创建`Dockerfile`文件,文件内容如下:
117 |
118 | ```
119 | FROM openjdk:8-jre-alpine
120 |
121 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
122 | apk update && \
123 | mkdir -p /app
124 | COPY target/spring-boot-monitoring-actuator-telegraf-influxdb-grafana-1.0.0-SNAPSHOT.jar app/spring-boot-monitoring-actuator-telegraf-influxdb-grafana.jar
125 | EXPOSE 8080
126 | ENTRYPOINT ["java", "-jar", "app/spring-boot-monitoring-actuator-telegraf-influxdb-grafana.jar"]
127 | ```
128 |
129 | 2. 将项目`spring-boot-monitoring-actuator-telegraf-influxdb-grafana`进行打包:`mvn clean package -Dmaven.test.skip=true`
130 |
131 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-actuator-telegraf-influxdb-grafana:1.0.0-SNAPSHOT .`
132 |
133 | ## 使用Docker启动Telegraf、Influxdb 2.x、Grafana以及示例项目
134 |
135 | 使用docker compose安装`Telegraf`、`Influxdb 2.x`和`Grafana`:
136 |
137 | 1. 先编写`docker-compose.yml`文件,内容参考下方的`docker-compose.yml`文件内容
138 | 2. 启动`docker compose up -d`
139 | 3. 访问grafana:`http://localhost:3000`,grafana的默认用户名密码:`admin/admin`
140 | 4. 在grafana创建数据源,在Query Language中选择Flux,这样才可以设置Influxdb 2.x的信息
141 | 5. 创建完数据源后,在Dashboards中选择Import,然后选择`spring-boot-monitoring-actuator-telegraf-influxdb-grafana/grafana/SpringBoot监控.json`文件进行导入
142 |
143 | ## 怎样运行当前方案
144 |
145 | 1. 克隆当前项目,进入`spring-boot-monitoring-actuator-telegraf-influxdb-grafana`目录下
146 | 2. 将项目`spring-boot-monitoring-actuator-telegraf-influxdb-grafana`进行打包:`mvn clean package -Dmaven.test.skip=true`
147 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-actuator-telegraf-influxdb-grafana:1.0.0-SNAPSHOT .`
148 | 4. 启动:`docker compose up -d`
149 | 5. 访问grafana:`http://localhost:3000`,grafana的默认用户名密码:`admin/admin`
150 | 6. 在grafana创建数据源,在Query Language中选择Flux,这样才可以设置Influxdb 2.x的信息
151 | 7. 创建完数据源后,在Dashboards中选择Import,然后选择`spring-boot-monitoring-actuator-telegraf-influxdb-grafana/grafana/SpringBoot监控.json`文件进行导入
152 |
153 | ## `docker-compose.yml`文件内容
154 |
155 | ```yaml
156 | version: "3.8"
157 |
158 | # 定义网络:local_net
159 | networks:
160 | local_net:
161 | name: local_net
162 |
163 | # 定义服务
164 | services:
165 | # influxdb服务
166 | influxdb:
167 | image: influxdb:latest
168 | ports:
169 | - 8086:8086
170 | networks:
171 | - local_net
172 | environment:
173 | - DOCKER_INFLUXDB_INIT_MODE=setup
174 | - DOCKER_INFLUXDB_INIT_USERNAME=admin
175 | - DOCKER_INFLUXDB_INIT_PASSWORD=12345678
176 | - DOCKER_INFLUXDB_INIT_ORG=pullock
177 | - DOCKER_INFLUXDB_INIT_BUCKET=pullock-bucket
178 | - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=12345678
179 |
180 | # telegraf服务
181 | telegraf:
182 | image: telegraf:latest
183 | networks:
184 | - local_net
185 | depends_on:
186 | - influxdb
187 | volumes:
188 | - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
189 |
190 | # grafana服务
191 | grafana:
192 | image: grafana/grafana:latest
193 | ports:
194 | - 3000:3000
195 | networks:
196 | - local_net
197 |
198 | # 示例项目服务
199 | spring-boot-monitoring-actuator-telegraf-influxdb-grafana:
200 | image: local_test/spring-boot-monitoring-actuator-telegraf-influxdb-grafana:1.0.0-SNAPSHOT
201 | ports:
202 | - 8080:8080
203 | networks:
204 | - local_net
205 | ```
206 |
207 | # Spring Boot Actuator + Prometheus + Grafana方案
208 |
209 | Spring boot项目,开启Actuator支持,使用Prometheus采集项目运行信息并存储数据,Grafana展示数据。
210 |
211 | ## 将当前项目打包为Docker镜像
212 |
213 | 1. 在`spring-boot-monitoring-actuator-prometheus-grafana`根目录下创建`Dockerfile`文件,文件内容如下:
214 |
215 | ```
216 | FROM openjdk:8-jre-alpine
217 |
218 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
219 | apk update && \
220 | mkdir -p /app
221 | COPY target/spring-boot-monitoring-actuator-prometheus-grafana-1.0.0-SNAPSHOT.jar app/spring-boot-monitoring-actuator-prometheus-grafana.jar
222 | EXPOSE 8080
223 | ENTRYPOINT ["java", "-jar", "app/spring-boot-monitoring-actuator-prometheus-grafana.jar"]
224 | ```
225 |
226 | 2. 将项目`spring-boot-monitoring-actuator-prometheus-grafana`进行打包:`mvn clean package -Dmaven.test.skip=true`
227 |
228 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-actuator-prometheus-grafana:1.0.0-SNAPSHOT .`
229 |
230 | ## 使用Docker启动Prometheus、Grafana以及示例项目
231 |
232 | 使用docker compose安装`Prometheus`和`Grafana`:
233 |
234 | 1. 先编写`docker-compose.yml`文件,内容参考下方的`docker-compose.yml`文件内容
235 | 2. 启动`docker compose up -d`
236 | 3. 访问prometheus:`http://localhost:9090`
237 | 3. 访问grafana:`http://localhost:3000`,grafana的默认用户名密码:`admin/admin`
238 | 4. 在grafana创建数据源,选择Prometheus后填写信息即可
239 | 5. 创建完数据源后,在Dashboards中选择Import,然后选择`spring-boot-monitoring-actuator-prometheus-grafana/grafana/SpringBoot监控.json`文件进行导入
240 |
241 | ## 怎样运行当前方案
242 |
243 | 1. 克隆当前项目,进入`spring-boot-monitoring-actuator-prometheus-grafana`目录下
244 | 2. 将项目`spring-boot-monitoring-actuator-prometheus-grafana`进行打包:`mvn clean package -Dmaven.test.skip=true`
245 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-actuator-prometheus-grafana:1.0.0-SNAPSHOT .`
246 | 4. 启动:`docker compose up -d`
247 | 5. 访问prometheus:`http://localhost:9090`
248 | 5. 访问grafana:`http://localhost:3000`,grafana的默认用户名密码:`admin/admin`
249 | 6. 在grafana创建数据源,选择Prometheus后填写信息即可
250 | 7. 创建完数据源后,在Dashboards中选择Import,然后选择`spring-boot-monitoring-actuator-prometheus-grafana/grafana/SpringBoot监控.json`文件进行导入
251 |
252 | ## `docker-compose.yml`文件内容
253 |
254 | ```yaml
255 | version: "3.8"
256 |
257 | # 定义网络:local_net
258 | networks:
259 | local_net:
260 | name: local_net
261 |
262 | # 定义服务
263 | services:
264 | # prometheus服务
265 | prometheus:
266 | image: prom/prometheus:latest
267 | ports:
268 | - 9090:9090
269 | networks:
270 | - local_net
271 | volumes:
272 | - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
273 |
274 | # grafana服务
275 | grafana:
276 | image: grafana/grafana:latest
277 | ports:
278 | - 3000:3000
279 | networks:
280 | - local_net
281 |
282 | # 示例项目服务
283 | spring-boot-monitoring-actuator-prometheus-grafana:
284 | image: local_test/spring-boot-monitoring-actuator-prometheus-grafana:1.0.0-SNAPSHOT
285 | ports:
286 | - 8080:8080
287 | networks:
288 | - local_net
289 | ```
290 |
291 | # Spring Boot Actuator介绍
292 |
293 | ## 可用的endpoints
294 |
295 | | ID | 描述 | JXM默认暴露 | Web默认暴露 |
296 | | ------------------ | --------------------------------------------------------------------------------------- | ------- | ------- |
297 | | `auditevents` | 暴露审计事件,比如登录相关的事件信息等等,需要容器中存在`AuditEventRepository`类型的` Bean` | Yes | No |
298 | | `beans` | 显示所有的Spring的`Bean` | Yes | No |
299 | | `caches` | 暴露可用的缓存 | Yes | No |
300 | | `conditions` | 显示在配置类和自动配置类上的评估条件,并且显示他们匹配或者不匹配的原因 | Yes | No |
301 | | `configprops` | 显示所有`@ConfigurationProperties`列表 | Yes | No |
302 | | `env` | 暴露`ConfigurableEnvironment`中的环境属性,包括:配置文件中的内容、系统变量等 | Yes | No |
303 | | `flyway` | 显示Flyway数据库迁移,需要容器中存在`Flyway`类型的`Bean` | Yes | No |
304 | | `health` | 显示应用健康信息、运行状态 | Yes | Yes |
305 | | `httptrace` | 显示HTTP跟踪信息(默认情况下显示最近的100条信息),需要容器中存在`HttpTraceRepository`类型的`Bean` | Yes | No |
306 | | `info` | 显示配置文件中`info`开头的配置信息 | Yes | No |
307 | | `integrationgraph` | 显示`Spring Integration`图,需要有`spring-integration-core`的依赖 | Yes | No |
308 | | `loggers` | 显示和修改日志的配置信息 | Yes | No |
309 | | `liquibase` | 显示`Liquibase`数据库迁移,需要容器中存在`Liquibase`类型的`Bean` | Yes | No |
310 | | `metrics` | 显示引用的指标信息,比如:内存、线程、垃圾回收、数据库连接池等 | Yes | No |
311 | | `mappings` | 显示`@RequestMapping`的所有URI路径列表 | Yes | No |
312 | | `quartz` | 显示`Quartz Scheduler`的任务 | Yes | No |
313 | | `scheduledtasks` | 显示应用中的定时任务信息 | Yes | No |
314 | | `sessions` | 允许获取或删除用户的`session`,需要是基于`Spring Session`存储并且是基于`Servlet`的web应用 | Yes | No |
315 | | `shutdown` | 可以优雅关闭应用,默认禁用 | Yes | No |
316 | | `startup` | 显示`ApplicationStartup`收集的有关启动的数据,需要将`SpringApplication`配置为`BufferingApplicationStartup` | Yes | No |
317 | | `threaddump` | 执行线程转储 | Yes | No |
318 |
319 | ### web应用专用的endpoints
320 |
321 | | ID | 描述 | JMX默认暴露 | HTTP默认暴露 |
322 | | ------------ | ---------------------------------------------------------------------------------------- | ------- | -------- |
323 | | `heapdump` | 返回一个堆转储文件 | N/A | No |
324 | | `jolokia` | 将JMX通过HTTP暴露出去,需要添加依赖`jolokia-core` | N/A | No |
325 | | `logfile` | 如果`logging.file.name`或者`logging.file.path`设置了,则可以获取到日志文件内容,支持使用Http的请求头的`Range`来部分获取日志内容 | N/A | No |
326 | | `prometheus` | 支持将指标暴露为`Prometheus`可识别的格式,需要添加依赖`micrometer-registry-prometheus` | N/A | No |
--------------------------------------------------------------------------------
/grafana/sample.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pulllock/spring-boot-monitoring/271a61ff83d56d35cbc57a61dc957e17e22ed91f/grafana/sample.png
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | fun.pullock
8 | spring-boot-monitoring
9 | 1.0.0-SNAPSHOT
10 |
11 | spring-boot-monitoring-actuator-telegraf-influxdb-grafana
12 | spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana
13 | spring-boot-monitoring-actuator-prometheus-grafana
14 | spring-boot-monitoring-admin
15 | spring-boot-monitoring-skywalking
16 | spring-boot-monitoring-sleuth-zipkin
17 |
18 | pom
19 |
20 | spring-boot-monitoring
21 | Monitoring for Spring Boot
22 |
23 |
24 |
25 | UTF-8
26 | UTF-8
27 | 1.8
28 | 1.8
29 | 1.8
30 | 2.7.3
31 | 2.7.4
32 | 2021.0.4
33 |
34 |
35 |
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-dependencies
40 | ${spring-boot.version}
41 | pom
42 | import
43 |
44 |
45 |
46 | de.codecentric
47 | spring-boot-admin-dependencies
48 | ${spring-boot-admin.version}
49 | pom
50 | import
51 |
52 |
53 |
54 | org.springframework.cloud
55 | spring-cloud-dependencies
56 | ${spring-cloud.version}
57 | pom
58 | import
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | org.springframework.boot
68 | spring-boot-maven-plugin
69 | ${spring-boot.version}
70 |
71 |
72 |
73 | repackage
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-prometheus-grafana/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jre-alpine
2 | WORKDIR /app
3 |
4 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
5 | apk update
6 |
7 | COPY target/spring-boot-monitoring-actuator-prometheus-grafana-1.0.0-SNAPSHOT.jar spring-boot-monitoring-actuator-prometheus-grafana.jar
8 | EXPOSE 8080
9 | ENTRYPOINT ["java", "-jar", "spring-boot-monitoring-actuator-prometheus-grafana.jar"]
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-prometheus-grafana/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | # 定义网络:local_net
4 | networks:
5 | local_net:
6 | name: local_net
7 |
8 | # 定义服务
9 | services:
10 | # prometheus服务
11 | prometheus:
12 | image: prom/prometheus:latest
13 | ports:
14 | - 9090:9090
15 | networks:
16 | - local_net
17 | volumes:
18 | - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
19 |
20 | # grafana服务
21 | grafana:
22 | image: grafana/grafana:latest
23 | ports:
24 | - 3000:3000
25 | networks:
26 | - local_net
27 |
28 | # 示例项目服务
29 | spring-boot-monitoring-actuator-prometheus-grafana:
30 | image: local_test/spring-boot-monitoring-actuator-prometheus-grafana:1.0.0-SNAPSHOT
31 | ports:
32 | - 8080:8080
33 | networks:
34 | - local_net
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-prometheus-grafana/grafana/Spring Boot监控.json:
--------------------------------------------------------------------------------
1 | {
2 | "annotations": {
3 | "list": [
4 | {
5 | "builtIn": 1,
6 | "datasource": {
7 | "type": "datasource",
8 | "uid": "grafana"
9 | },
10 | "enable": true,
11 | "hide": true,
12 | "iconColor": "rgba(0, 211, 255, 1)",
13 | "name": "Annotations & Alerts",
14 | "target": {
15 | "limit": 100,
16 | "matchAny": false,
17 | "tags": [],
18 | "type": "dashboard"
19 | },
20 | "type": "dashboard"
21 | }
22 | ]
23 | },
24 | "editable": true,
25 | "fiscalYearStartMonth": 0,
26 | "graphTooltip": 0,
27 | "id": 1,
28 | "links": [],
29 | "liveNow": false,
30 | "panels": [
31 | {
32 | "datasource": {
33 | "type": "prometheus",
34 | "uid": "-05XguMVk"
35 | },
36 | "fieldConfig": {
37 | "defaults": {
38 | "color": {
39 | "mode": "palette-classic"
40 | },
41 | "custom": {
42 | "axisCenteredZero": false,
43 | "axisColorMode": "text",
44 | "axisLabel": "",
45 | "axisPlacement": "auto",
46 | "barAlignment": 0,
47 | "drawStyle": "line",
48 | "fillOpacity": 10,
49 | "gradientMode": "none",
50 | "hideFrom": {
51 | "legend": false,
52 | "tooltip": false,
53 | "viz": false
54 | },
55 | "lineInterpolation": "linear",
56 | "lineWidth": 1,
57 | "pointSize": 5,
58 | "scaleDistribution": {
59 | "type": "linear"
60 | },
61 | "showPoints": "never",
62 | "spanNulls": false,
63 | "stacking": {
64 | "group": "A",
65 | "mode": "none"
66 | },
67 | "thresholdsStyle": {
68 | "mode": "off"
69 | }
70 | },
71 | "mappings": [],
72 | "thresholds": {
73 | "mode": "absolute",
74 | "steps": [
75 | {
76 | "color": "green",
77 | "value": null
78 | },
79 | {
80 | "color": "red",
81 | "value": 80
82 | }
83 | ]
84 | },
85 | "unit": "short"
86 | },
87 | "overrides": []
88 | },
89 | "gridPos": {
90 | "h": 5,
91 | "w": 24,
92 | "x": 0,
93 | "y": 0
94 | },
95 | "id": 1,
96 | "links": [],
97 | "options": {
98 | "legend": {
99 | "calcs": [],
100 | "displayMode": "list",
101 | "placement": "bottom",
102 | "showLegend": false
103 | },
104 | "tooltip": {
105 | "mode": "multi",
106 | "sort": "none"
107 | }
108 | },
109 | "pluginVersion": "9.1.1",
110 | "targets": [
111 | {
112 | "alias": "类加载总量",
113 | "datasource": {
114 | "type": "influxdb",
115 | "uid": "fTAe5lWVk"
116 | },
117 | "dsType": "influxdb",
118 | "editorMode": "builder",
119 | "expr": "jvm_classes_loaded_classes{job=\"actuator\"}",
120 | "groupBy": [
121 | {
122 | "params": [
123 | "$__interval"
124 | ],
125 | "type": "time"
126 | },
127 | {
128 | "params": [
129 | "null"
130 | ],
131 | "type": "fill"
132 | }
133 | ],
134 | "legendFormat": "__auto",
135 | "measurement": "jolokia",
136 | "orderByTime": "ASC",
137 | "policy": "default",
138 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"jolokia\" and\n r._field == \"class_count_LoadedClassCount\"\n )",
139 | "range": true,
140 | "refId": "Load Class Count",
141 | "resultFormat": "time_series",
142 | "select": [
143 | [
144 | {
145 | "params": [
146 | "class_count_TotalLoadedClassCount"
147 | ],
148 | "type": "field"
149 | },
150 | {
151 | "params": [],
152 | "type": "mean"
153 | }
154 | ]
155 | ],
156 | "tags": []
157 | },
158 | {
159 | "alias": "类加载量",
160 | "datasource": {
161 | "type": "influxdb",
162 | "uid": "fTAe5lWVk"
163 | },
164 | "dsType": "influxdb",
165 | "editorMode": "builder",
166 | "expr": "jvm_classes_loaded_classes{job=\"actuator\"}",
167 | "groupBy": [
168 | {
169 | "params": [
170 | "$__interval"
171 | ],
172 | "type": "time"
173 | },
174 | {
175 | "params": [
176 | "null"
177 | ],
178 | "type": "fill"
179 | }
180 | ],
181 | "legendFormat": "__auto",
182 | "measurement": "jolokia",
183 | "orderByTime": "ASC",
184 | "policy": "default",
185 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"jolokia\" and\n r._field == \"class_count_TotalLoadedClassCount\"\n )",
186 | "range": true,
187 | "refId": "Total Loaded Class Count",
188 | "resultFormat": "time_series",
189 | "select": [
190 | [
191 | {
192 | "params": [
193 | "class_count_LoadedClassCount"
194 | ],
195 | "type": "field"
196 | },
197 | {
198 | "params": [],
199 | "type": "mean"
200 | }
201 | ]
202 | ],
203 | "tags": []
204 | },
205 | {
206 | "datasource": {
207 | "type": "influxdb",
208 | "uid": "fTAe5lWVk"
209 | },
210 | "editorMode": "builder",
211 | "expr": "jvm_classes_unloaded_classes_total{job=\"actuator\"}",
212 | "hide": false,
213 | "legendFormat": "__auto",
214 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"jolokia\" and\n r._field == \"class_count_UnloadedClassCount\"\n )",
215 | "range": true,
216 | "refId": "Unloaded Class Count"
217 | }
218 | ],
219 | "timeFrom": "1h",
220 | "title": "类加载",
221 | "type": "timeseries"
222 | },
223 | {
224 | "datasource": {
225 | "type": "prometheus",
226 | "uid": "-05XguMVk"
227 | },
228 | "fieldConfig": {
229 | "defaults": {
230 | "color": {
231 | "mode": "palette-classic"
232 | },
233 | "custom": {
234 | "axisCenteredZero": false,
235 | "axisColorMode": "text",
236 | "axisLabel": "",
237 | "axisPlacement": "auto",
238 | "barAlignment": 0,
239 | "drawStyle": "line",
240 | "fillOpacity": 10,
241 | "gradientMode": "none",
242 | "hideFrom": {
243 | "legend": false,
244 | "tooltip": false,
245 | "viz": false
246 | },
247 | "lineInterpolation": "linear",
248 | "lineWidth": 1,
249 | "pointSize": 5,
250 | "scaleDistribution": {
251 | "type": "linear"
252 | },
253 | "showPoints": "never",
254 | "spanNulls": false,
255 | "stacking": {
256 | "group": "A",
257 | "mode": "none"
258 | },
259 | "thresholdsStyle": {
260 | "mode": "off"
261 | }
262 | },
263 | "mappings": [],
264 | "thresholds": {
265 | "mode": "absolute",
266 | "steps": [
267 | {
268 | "color": "green",
269 | "value": null
270 | },
271 | {
272 | "color": "red",
273 | "value": 80
274 | }
275 | ]
276 | },
277 | "unit": "decbytes"
278 | },
279 | "overrides": []
280 | },
281 | "gridPos": {
282 | "h": 6,
283 | "w": 18,
284 | "x": 0,
285 | "y": 5
286 | },
287 | "id": 5,
288 | "links": [],
289 | "options": {
290 | "legend": {
291 | "calcs": [],
292 | "displayMode": "list",
293 | "placement": "bottom",
294 | "showLegend": false
295 | },
296 | "tooltip": {
297 | "mode": "multi",
298 | "sort": "none"
299 | }
300 | },
301 | "pluginVersion": "9.1.1",
302 | "targets": [
303 | {
304 | "alias": "堆内存使用量",
305 | "datasource": {
306 | "type": "influxdb",
307 | "uid": "fTAe5lWVk"
308 | },
309 | "dsType": "influxdb",
310 | "editorMode": "builder",
311 | "expr": "jvm_memory_used_bytes{job=\"actuator\"}",
312 | "groupBy": [
313 | {
314 | "params": [
315 | "$__interval"
316 | ],
317 | "type": "time"
318 | },
319 | {
320 | "params": [
321 | "null"
322 | ],
323 | "type": "fill"
324 | }
325 | ],
326 | "legendFormat": "__auto",
327 | "measurement": "jolokia",
328 | "orderByTime": "ASC",
329 | "policy": "default",
330 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"jolokia\" and\n r._field == \"heap_memory_usage_used\"\n )",
331 | "range": true,
332 | "refId": "A",
333 | "resultFormat": "time_series",
334 | "select": [
335 | [
336 | {
337 | "params": [
338 | "heap_memory_usage_used"
339 | ],
340 | "type": "field"
341 | },
342 | {
343 | "params": [],
344 | "type": "mean"
345 | }
346 | ]
347 | ],
348 | "tags": []
349 | }
350 | ],
351 | "timeFrom": "1h",
352 | "title": "堆内存",
353 | "type": "timeseries"
354 | },
355 | {
356 | "datasource": {
357 | "type": "prometheus",
358 | "uid": "-05XguMVk"
359 | },
360 | "fieldConfig": {
361 | "defaults": {
362 | "color": {
363 | "mode": "thresholds"
364 | },
365 | "mappings": [
366 | {
367 | "options": {
368 | "match": "null",
369 | "result": {
370 | "text": "N/A"
371 | }
372 | },
373 | "type": "special"
374 | }
375 | ],
376 | "max": 100,
377 | "min": 0,
378 | "thresholds": {
379 | "mode": "absolute",
380 | "steps": [
381 | {
382 | "color": "#299c46",
383 | "value": null
384 | },
385 | {
386 | "color": "rgba(237, 129, 40, 0.89)",
387 | "value": 50
388 | },
389 | {
390 | "color": "#d44a3a",
391 | "value": 90
392 | }
393 | ]
394 | },
395 | "unit": "none"
396 | },
397 | "overrides": []
398 | },
399 | "gridPos": {
400 | "h": 6,
401 | "w": 6,
402 | "x": 18,
403 | "y": 5
404 | },
405 | "id": 6,
406 | "links": [],
407 | "maxDataPoints": 100,
408 | "options": {
409 | "orientation": "horizontal",
410 | "reduceOptions": {
411 | "calcs": [
412 | "lastNotNull"
413 | ],
414 | "fields": "",
415 | "values": false
416 | },
417 | "showThresholdLabels": false,
418 | "showThresholdMarkers": true
419 | },
420 | "pluginVersion": "9.1.1",
421 | "targets": [
422 | {
423 | "datasource": {
424 | "type": "influxdb",
425 | "uid": "fTAe5lWVk"
426 | },
427 | "dsType": "influxdb",
428 | "editorMode": "builder",
429 | "expr": "system_cpu_usage{job=\"actuator\"}",
430 | "groupBy": [
431 | {
432 | "params": [
433 | "$__interval"
434 | ],
435 | "type": "time"
436 | },
437 | {
438 | "params": [
439 | "null"
440 | ],
441 | "type": "fill"
442 | }
443 | ],
444 | "legendFormat": "__auto",
445 | "measurement": "cpu",
446 | "orderByTime": "ASC",
447 | "policy": "default",
448 | "query": "// v.windowPeriod is a variable referring to the current optimized window period (currently: $interval)\nfrom(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"cpu\" or r[\"_measurement\"] =~ /^.*?regex.*$/)\n |> filter(fn: (r) => r[\"_field\"] == \"usage_system\" or r[\"_field\"] =~ /^.*?regex.*$/)\n |> filter(fn: (r) => r[\"cpu\"] == \"cpu-total\" or r[\"_field\"] =~ /^.*?regex.*$/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean)",
449 | "range": true,
450 | "refId": "A",
451 | "resultFormat": "time_series",
452 | "select": [
453 | [
454 | {
455 | "params": [
456 | "usage_system"
457 | ],
458 | "type": "field"
459 | },
460 | {
461 | "params": [],
462 | "type": "mean"
463 | }
464 | ]
465 | ],
466 | "tags": []
467 | }
468 | ],
469 | "timeFrom": "1h",
470 | "title": "CPU",
471 | "type": "gauge"
472 | },
473 | {
474 | "datasource": {
475 | "type": "prometheus",
476 | "uid": "-05XguMVk"
477 | },
478 | "fieldConfig": {
479 | "defaults": {
480 | "color": {
481 | "mode": "palette-classic"
482 | },
483 | "custom": {
484 | "axisCenteredZero": false,
485 | "axisColorMode": "text",
486 | "axisLabel": "",
487 | "axisPlacement": "auto",
488 | "barAlignment": 0,
489 | "drawStyle": "line",
490 | "fillOpacity": 10,
491 | "gradientMode": "none",
492 | "hideFrom": {
493 | "legend": false,
494 | "tooltip": false,
495 | "viz": false
496 | },
497 | "lineInterpolation": "linear",
498 | "lineWidth": 1,
499 | "pointSize": 5,
500 | "scaleDistribution": {
501 | "type": "linear"
502 | },
503 | "showPoints": "never",
504 | "spanNulls": false,
505 | "stacking": {
506 | "group": "A",
507 | "mode": "none"
508 | },
509 | "thresholdsStyle": {
510 | "mode": "off"
511 | }
512 | },
513 | "mappings": [],
514 | "thresholds": {
515 | "mode": "absolute",
516 | "steps": [
517 | {
518 | "color": "green",
519 | "value": null
520 | },
521 | {
522 | "color": "red",
523 | "value": 80
524 | }
525 | ]
526 | },
527 | "unit": "decbytes"
528 | },
529 | "overrides": []
530 | },
531 | "gridPos": {
532 | "h": 7,
533 | "w": 24,
534 | "x": 0,
535 | "y": 11
536 | },
537 | "id": 4,
538 | "links": [],
539 | "options": {
540 | "legend": {
541 | "calcs": [],
542 | "displayMode": "list",
543 | "placement": "bottom",
544 | "showLegend": false
545 | },
546 | "tooltip": {
547 | "mode": "multi",
548 | "sort": "none"
549 | }
550 | },
551 | "pluginVersion": "9.1.1",
552 | "targets": [
553 | {
554 | "alias": "已使用内存",
555 | "datasource": {
556 | "type": "influxdb",
557 | "uid": "fTAe5lWVk"
558 | },
559 | "dsType": "influxdb",
560 | "editorMode": "builder",
561 | "expr": "jvm_memory_committed_bytes{job=\"actuator\"}",
562 | "groupBy": [
563 | {
564 | "params": [
565 | "$__interval"
566 | ],
567 | "type": "time"
568 | },
569 | {
570 | "params": [
571 | "null"
572 | ],
573 | "type": "fill"
574 | }
575 | ],
576 | "legendFormat": "__auto",
577 | "measurement": "mem",
578 | "orderByTime": "ASC",
579 | "policy": "default",
580 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"mem\" and\n r._field == \"used\"\n )",
581 | "range": true,
582 | "refId": "A",
583 | "resultFormat": "time_series",
584 | "select": [
585 | [
586 | {
587 | "params": [
588 | "used"
589 | ],
590 | "type": "field"
591 | },
592 | {
593 | "params": [],
594 | "type": "mean"
595 | }
596 | ]
597 | ],
598 | "tags": []
599 | }
600 | ],
601 | "timeFrom": "1h",
602 | "title": "内存使用",
603 | "type": "timeseries"
604 | }
605 | ],
606 | "refresh": "5s",
607 | "schemaVersion": 37,
608 | "style": "dark",
609 | "tags": [],
610 | "templating": {
611 | "list": []
612 | },
613 | "time": {
614 | "from": "now/d",
615 | "to": "now/d"
616 | },
617 | "timepicker": {
618 | "refresh_intervals": [
619 | "5s",
620 | "10s",
621 | "30s",
622 | "1m",
623 | "5m",
624 | "15m",
625 | "30m",
626 | "1h",
627 | "2h",
628 | "1d"
629 | ],
630 | "time_options": [
631 | "5m",
632 | "15m",
633 | "1h",
634 | "6h",
635 | "12h",
636 | "24h",
637 | "2d",
638 | "7d",
639 | "30d"
640 | ]
641 | },
642 | "timezone": "",
643 | "title": "Spring Boot监控",
644 | "uid": "nhpctlZVz",
645 | "version": 2,
646 | "weekStart": ""
647 | }
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-prometheus-grafana/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-monitoring
7 | fun.pullock
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-monitoring-actuator-prometheus-grafana
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-actuator
23 |
24 |
25 |
26 | io.micrometer
27 | micrometer-registry-prometheus
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-test
33 | test
34 |
35 |
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-maven-plugin
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-prometheus-grafana/prometheus/prometheus.yml:
--------------------------------------------------------------------------------
1 | global:
2 | scrape_interval: 15s
3 | evaluation_interval: 15s
4 |
5 | scrape_configs:
6 | - job_name: 'prometheus'
7 | static_configs:
8 | - targets: ['prometheus:9090']
9 |
10 | - job_name: 'actuator'
11 | metrics_path: '/actuator/prometheus'
12 | scrape_interval: 5s
13 | static_configs:
14 | - targets: ['spring-boot-monitoring-actuator-prometheus-grafana:8080']
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-prometheus-grafana/src/main/java/fun/pullock/monitoring/MonitoringActuatorPrometheusGrafanaApplication.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MonitoringActuatorPrometheusGrafanaApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(MonitoringActuatorPrometheusGrafanaApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-prometheus-grafana/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8080
3 | spring:
4 | jmx:
5 | enabled: true
6 | management:
7 | endpoints:
8 | # 启用所有端口
9 | enabled-by-default: true
10 | web:
11 | exposure:
12 | # 暴露所有端口
13 | include: "*"
14 | endpoint:
15 | health:
16 | show-details: always
17 | jolokia:
18 | enabled: true
19 | config:
20 | debug: true
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb-grafana/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jre-alpine
2 | WORKDIR /app
3 |
4 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
5 | apk update
6 |
7 | COPY target/spring-boot-monitoring-actuator-telegraf-influxdb-grafana-1.0.0-SNAPSHOT.jar spring-boot-monitoring-actuator-telegraf-influxdb-grafana.jar
8 | EXPOSE 8080
9 | ENTRYPOINT ["java", "-jar", "spring-boot-monitoring-actuator-telegraf-influxdb-grafana.jar"]
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb-grafana/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | # 定义网络:local_net
4 | networks:
5 | local_net:
6 | name: local_net
7 |
8 | # 定义服务
9 | services:
10 | # influxdb服务
11 | influxdb:
12 | image: influxdb:latest
13 | ports:
14 | - 8086:8086
15 | networks:
16 | - local_net
17 | environment:
18 | - DOCKER_INFLUXDB_INIT_MODE=setup
19 | - DOCKER_INFLUXDB_INIT_USERNAME=admin
20 | - DOCKER_INFLUXDB_INIT_PASSWORD=12345678
21 | - DOCKER_INFLUXDB_INIT_ORG=pullock
22 | - DOCKER_INFLUXDB_INIT_BUCKET=pullock-bucket
23 | - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=12345678
24 |
25 | # telegraf服务
26 | telegraf:
27 | image: telegraf:latest
28 | networks:
29 | - local_net
30 | depends_on:
31 | - influxdb
32 | volumes:
33 | - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
34 |
35 | # grafana服务
36 | grafana:
37 | image: grafana/grafana:latest
38 | ports:
39 | - 3000:3000
40 | networks:
41 | - local_net
42 |
43 | # 示例项目服务
44 | spring-boot-monitoring-actuator-telegraf-influxdb-grafana:
45 | image: local_test/spring-boot-monitoring-actuator-telegraf-influxdb-grafana:1.0.0-SNAPSHOT
46 | ports:
47 | - 8080:8080
48 | networks:
49 | - local_net
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb-grafana/grafana/Spring Boot监控.json:
--------------------------------------------------------------------------------
1 | {
2 | "annotations": {
3 | "list": [
4 | {
5 | "builtIn": 1,
6 | "datasource": {
7 | "type": "datasource",
8 | "uid": "grafana"
9 | },
10 | "enable": true,
11 | "hide": true,
12 | "iconColor": "rgba(0, 211, 255, 1)",
13 | "name": "Annotations & Alerts",
14 | "target": {
15 | "limit": 100,
16 | "matchAny": false,
17 | "tags": [],
18 | "type": "dashboard"
19 | },
20 | "type": "dashboard"
21 | }
22 | ]
23 | },
24 | "editable": true,
25 | "fiscalYearStartMonth": 0,
26 | "graphTooltip": 0,
27 | "id": 1,
28 | "links": [],
29 | "liveNow": false,
30 | "panels": [
31 | {
32 | "datasource": {
33 | "type": "influxdb",
34 | "uid": "fTAe5lWVk"
35 | },
36 | "fieldConfig": {
37 | "defaults": {
38 | "color": {
39 | "mode": "palette-classic"
40 | },
41 | "custom": {
42 | "axisCenteredZero": false,
43 | "axisColorMode": "text",
44 | "axisLabel": "",
45 | "axisPlacement": "auto",
46 | "barAlignment": 0,
47 | "drawStyle": "line",
48 | "fillOpacity": 10,
49 | "gradientMode": "none",
50 | "hideFrom": {
51 | "legend": false,
52 | "tooltip": false,
53 | "viz": false
54 | },
55 | "lineInterpolation": "linear",
56 | "lineWidth": 1,
57 | "pointSize": 5,
58 | "scaleDistribution": {
59 | "type": "linear"
60 | },
61 | "showPoints": "never",
62 | "spanNulls": false,
63 | "stacking": {
64 | "group": "A",
65 | "mode": "none"
66 | },
67 | "thresholdsStyle": {
68 | "mode": "off"
69 | }
70 | },
71 | "mappings": [],
72 | "thresholds": {
73 | "mode": "absolute",
74 | "steps": [
75 | {
76 | "color": "green",
77 | "value": null
78 | },
79 | {
80 | "color": "red",
81 | "value": 80
82 | }
83 | ]
84 | },
85 | "unit": "short"
86 | },
87 | "overrides": []
88 | },
89 | "gridPos": {
90 | "h": 5,
91 | "w": 24,
92 | "x": 0,
93 | "y": 0
94 | },
95 | "id": 1,
96 | "links": [],
97 | "options": {
98 | "legend": {
99 | "calcs": [],
100 | "displayMode": "list",
101 | "placement": "bottom",
102 | "showLegend": false
103 | },
104 | "tooltip": {
105 | "mode": "multi",
106 | "sort": "none"
107 | }
108 | },
109 | "pluginVersion": "9.1.1",
110 | "targets": [
111 | {
112 | "alias": "类加载总量",
113 | "datasource": {
114 | "type": "influxdb",
115 | "uid": "fTAe5lWVk"
116 | },
117 | "dsType": "influxdb",
118 | "groupBy": [
119 | {
120 | "params": [
121 | "$__interval"
122 | ],
123 | "type": "time"
124 | },
125 | {
126 | "params": [
127 | "null"
128 | ],
129 | "type": "fill"
130 | }
131 | ],
132 | "measurement": "jolokia",
133 | "orderByTime": "ASC",
134 | "policy": "default",
135 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"jolokia\" and\n r._field == \"class_count_LoadedClassCount\"\n )",
136 | "refId": "Load Class Count",
137 | "resultFormat": "time_series",
138 | "select": [
139 | [
140 | {
141 | "params": [
142 | "class_count_TotalLoadedClassCount"
143 | ],
144 | "type": "field"
145 | },
146 | {
147 | "params": [],
148 | "type": "mean"
149 | }
150 | ]
151 | ],
152 | "tags": []
153 | },
154 | {
155 | "alias": "类加载量",
156 | "datasource": {
157 | "type": "influxdb",
158 | "uid": "fTAe5lWVk"
159 | },
160 | "dsType": "influxdb",
161 | "groupBy": [
162 | {
163 | "params": [
164 | "$__interval"
165 | ],
166 | "type": "time"
167 | },
168 | {
169 | "params": [
170 | "null"
171 | ],
172 | "type": "fill"
173 | }
174 | ],
175 | "measurement": "jolokia",
176 | "orderByTime": "ASC",
177 | "policy": "default",
178 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"jolokia\" and\n r._field == \"class_count_TotalLoadedClassCount\"\n )",
179 | "refId": "Total Loaded Class Count",
180 | "resultFormat": "time_series",
181 | "select": [
182 | [
183 | {
184 | "params": [
185 | "class_count_LoadedClassCount"
186 | ],
187 | "type": "field"
188 | },
189 | {
190 | "params": [],
191 | "type": "mean"
192 | }
193 | ]
194 | ],
195 | "tags": []
196 | },
197 | {
198 | "datasource": {
199 | "type": "influxdb",
200 | "uid": "fTAe5lWVk"
201 | },
202 | "hide": false,
203 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"jolokia\" and\n r._field == \"class_count_UnloadedClassCount\"\n )",
204 | "refId": "Unloaded Class Count"
205 | }
206 | ],
207 | "timeFrom": "1h",
208 | "title": "类加载",
209 | "type": "timeseries"
210 | },
211 | {
212 | "datasource": {
213 | "type": "influxdb",
214 | "uid": "fTAe5lWVk"
215 | },
216 | "fieldConfig": {
217 | "defaults": {
218 | "color": {
219 | "mode": "palette-classic"
220 | },
221 | "custom": {
222 | "axisCenteredZero": false,
223 | "axisColorMode": "text",
224 | "axisLabel": "",
225 | "axisPlacement": "auto",
226 | "barAlignment": 0,
227 | "drawStyle": "line",
228 | "fillOpacity": 10,
229 | "gradientMode": "none",
230 | "hideFrom": {
231 | "legend": false,
232 | "tooltip": false,
233 | "viz": false
234 | },
235 | "lineInterpolation": "linear",
236 | "lineWidth": 1,
237 | "pointSize": 5,
238 | "scaleDistribution": {
239 | "type": "linear"
240 | },
241 | "showPoints": "never",
242 | "spanNulls": false,
243 | "stacking": {
244 | "group": "A",
245 | "mode": "none"
246 | },
247 | "thresholdsStyle": {
248 | "mode": "off"
249 | }
250 | },
251 | "mappings": [],
252 | "thresholds": {
253 | "mode": "absolute",
254 | "steps": [
255 | {
256 | "color": "green",
257 | "value": null
258 | },
259 | {
260 | "color": "red",
261 | "value": 80
262 | }
263 | ]
264 | },
265 | "unit": "decbytes"
266 | },
267 | "overrides": []
268 | },
269 | "gridPos": {
270 | "h": 6,
271 | "w": 18,
272 | "x": 0,
273 | "y": 5
274 | },
275 | "id": 5,
276 | "links": [],
277 | "options": {
278 | "legend": {
279 | "calcs": [],
280 | "displayMode": "list",
281 | "placement": "bottom",
282 | "showLegend": false
283 | },
284 | "tooltip": {
285 | "mode": "multi",
286 | "sort": "none"
287 | }
288 | },
289 | "pluginVersion": "9.1.1",
290 | "targets": [
291 | {
292 | "alias": "堆内存使用量",
293 | "datasource": {
294 | "type": "influxdb",
295 | "uid": "fTAe5lWVk"
296 | },
297 | "dsType": "influxdb",
298 | "groupBy": [
299 | {
300 | "params": [
301 | "$__interval"
302 | ],
303 | "type": "time"
304 | },
305 | {
306 | "params": [
307 | "null"
308 | ],
309 | "type": "fill"
310 | }
311 | ],
312 | "measurement": "jolokia",
313 | "orderByTime": "ASC",
314 | "policy": "default",
315 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"jolokia\" and\n r._field == \"heap_memory_usage_used\"\n )",
316 | "refId": "A",
317 | "resultFormat": "time_series",
318 | "select": [
319 | [
320 | {
321 | "params": [
322 | "heap_memory_usage_used"
323 | ],
324 | "type": "field"
325 | },
326 | {
327 | "params": [],
328 | "type": "mean"
329 | }
330 | ]
331 | ],
332 | "tags": []
333 | }
334 | ],
335 | "timeFrom": "1h",
336 | "title": "堆内存",
337 | "type": "timeseries"
338 | },
339 | {
340 | "datasource": {
341 | "type": "influxdb",
342 | "uid": "fTAe5lWVk"
343 | },
344 | "fieldConfig": {
345 | "defaults": {
346 | "color": {
347 | "mode": "thresholds"
348 | },
349 | "mappings": [
350 | {
351 | "options": {
352 | "match": "null",
353 | "result": {
354 | "text": "N/A"
355 | }
356 | },
357 | "type": "special"
358 | }
359 | ],
360 | "max": 100,
361 | "min": 0,
362 | "thresholds": {
363 | "mode": "absolute",
364 | "steps": [
365 | {
366 | "color": "#299c46",
367 | "value": null
368 | },
369 | {
370 | "color": "rgba(237, 129, 40, 0.89)",
371 | "value": 50
372 | },
373 | {
374 | "color": "#d44a3a",
375 | "value": 90
376 | }
377 | ]
378 | },
379 | "unit": "none"
380 | },
381 | "overrides": []
382 | },
383 | "gridPos": {
384 | "h": 6,
385 | "w": 6,
386 | "x": 18,
387 | "y": 5
388 | },
389 | "id": 6,
390 | "links": [],
391 | "maxDataPoints": 100,
392 | "options": {
393 | "orientation": "horizontal",
394 | "reduceOptions": {
395 | "calcs": [
396 | "lastNotNull"
397 | ],
398 | "fields": "",
399 | "values": false
400 | },
401 | "showThresholdLabels": false,
402 | "showThresholdMarkers": true
403 | },
404 | "pluginVersion": "9.1.1",
405 | "targets": [
406 | {
407 | "datasource": {
408 | "type": "influxdb",
409 | "uid": "fTAe5lWVk"
410 | },
411 | "dsType": "influxdb",
412 | "groupBy": [
413 | {
414 | "params": [
415 | "$__interval"
416 | ],
417 | "type": "time"
418 | },
419 | {
420 | "params": [
421 | "null"
422 | ],
423 | "type": "fill"
424 | }
425 | ],
426 | "measurement": "cpu",
427 | "orderByTime": "ASC",
428 | "policy": "default",
429 | "query": "// v.windowPeriod is a variable referring to the current optimized window period (currently: $interval)\nfrom(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"cpu\" or r[\"_measurement\"] =~ /^.*?regex.*$/)\n |> filter(fn: (r) => r[\"_field\"] == \"usage_system\" or r[\"_field\"] =~ /^.*?regex.*$/)\n |> filter(fn: (r) => r[\"cpu\"] == \"cpu-total\" or r[\"_field\"] =~ /^.*?regex.*$/)\n |> aggregateWindow(every: v.windowPeriod, fn: mean)",
430 | "refId": "A",
431 | "resultFormat": "time_series",
432 | "select": [
433 | [
434 | {
435 | "params": [
436 | "usage_system"
437 | ],
438 | "type": "field"
439 | },
440 | {
441 | "params": [],
442 | "type": "mean"
443 | }
444 | ]
445 | ],
446 | "tags": []
447 | }
448 | ],
449 | "timeFrom": "1h",
450 | "title": "CPU",
451 | "type": "gauge"
452 | },
453 | {
454 | "datasource": {
455 | "type": "influxdb",
456 | "uid": "fTAe5lWVk"
457 | },
458 | "fieldConfig": {
459 | "defaults": {
460 | "color": {
461 | "mode": "palette-classic"
462 | },
463 | "custom": {
464 | "axisCenteredZero": false,
465 | "axisColorMode": "text",
466 | "axisLabel": "",
467 | "axisPlacement": "auto",
468 | "barAlignment": 0,
469 | "drawStyle": "line",
470 | "fillOpacity": 10,
471 | "gradientMode": "none",
472 | "hideFrom": {
473 | "legend": false,
474 | "tooltip": false,
475 | "viz": false
476 | },
477 | "lineInterpolation": "linear",
478 | "lineWidth": 1,
479 | "pointSize": 5,
480 | "scaleDistribution": {
481 | "type": "linear"
482 | },
483 | "showPoints": "never",
484 | "spanNulls": false,
485 | "stacking": {
486 | "group": "A",
487 | "mode": "none"
488 | },
489 | "thresholdsStyle": {
490 | "mode": "off"
491 | }
492 | },
493 | "mappings": [],
494 | "thresholds": {
495 | "mode": "absolute",
496 | "steps": [
497 | {
498 | "color": "green",
499 | "value": null
500 | },
501 | {
502 | "color": "red",
503 | "value": 80
504 | }
505 | ]
506 | },
507 | "unit": "decbytes"
508 | },
509 | "overrides": []
510 | },
511 | "gridPos": {
512 | "h": 7,
513 | "w": 24,
514 | "x": 0,
515 | "y": 11
516 | },
517 | "id": 4,
518 | "links": [],
519 | "options": {
520 | "legend": {
521 | "calcs": [],
522 | "displayMode": "list",
523 | "placement": "bottom",
524 | "showLegend": false
525 | },
526 | "tooltip": {
527 | "mode": "multi",
528 | "sort": "none"
529 | }
530 | },
531 | "pluginVersion": "9.1.1",
532 | "targets": [
533 | {
534 | "alias": "已使用内存",
535 | "datasource": {
536 | "type": "influxdb",
537 | "uid": "fTAe5lWVk"
538 | },
539 | "dsType": "influxdb",
540 | "groupBy": [
541 | {
542 | "params": [
543 | "$__interval"
544 | ],
545 | "type": "time"
546 | },
547 | {
548 | "params": [
549 | "null"
550 | ],
551 | "type": "fill"
552 | }
553 | ],
554 | "measurement": "mem",
555 | "orderByTime": "ASC",
556 | "policy": "default",
557 | "query": "from(bucket: \"pullock-bucket\")\n |> range(start: v.timeRangeStart, stop:v.timeRangeStop)\n |> filter(fn: (r) =>\n r._measurement == \"mem\" and\n r._field == \"used\"\n )",
558 | "refId": "A",
559 | "resultFormat": "time_series",
560 | "select": [
561 | [
562 | {
563 | "params": [
564 | "used"
565 | ],
566 | "type": "field"
567 | },
568 | {
569 | "params": [],
570 | "type": "mean"
571 | }
572 | ]
573 | ],
574 | "tags": []
575 | }
576 | ],
577 | "timeFrom": "1h",
578 | "title": "内存使用",
579 | "type": "timeseries"
580 | }
581 | ],
582 | "refresh": "5s",
583 | "schemaVersion": 37,
584 | "style": "dark",
585 | "tags": [],
586 | "templating": {
587 | "list": []
588 | },
589 | "time": {
590 | "from": "now/d",
591 | "to": "now/d"
592 | },
593 | "timepicker": {
594 | "refresh_intervals": [
595 | "5s",
596 | "10s",
597 | "30s",
598 | "1m",
599 | "5m",
600 | "15m",
601 | "30m",
602 | "1h",
603 | "2h",
604 | "1d"
605 | ],
606 | "time_options": [
607 | "5m",
608 | "15m",
609 | "1h",
610 | "6h",
611 | "12h",
612 | "24h",
613 | "2d",
614 | "7d",
615 | "30d"
616 | ]
617 | },
618 | "timezone": "",
619 | "title": "Spring Boot监控",
620 | "uid": "nhpctlZVz",
621 | "version": 5,
622 | "weekStart": ""
623 | }
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb-grafana/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-monitoring
7 | fun.pullock
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-monitoring-actuator-telegraf-influxdb-grafana
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-actuator
23 |
24 |
25 |
26 | org.jolokia
27 | jolokia-core
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-test
33 | test
34 |
35 |
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-maven-plugin
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb-grafana/src/main/java/fun/pullock/monitoring/MonitoringActuatorTelegrafInfluxdbGrafanaApplication.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MonitoringActuatorTelegrafInfluxdbGrafanaApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(MonitoringActuatorTelegrafInfluxdbGrafanaApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb-grafana/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8080
3 | spring:
4 | jmx:
5 | enabled: true
6 | management:
7 | endpoints:
8 | # 启用所有端口
9 | enabled-by-default: true
10 | web:
11 | exposure:
12 | # 暴露所有端口
13 | include: "*"
14 | endpoint:
15 | health:
16 | show-details: always
17 | jolokia:
18 | enabled: true
19 | config:
20 | debug: true
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb-grafana/telegraf/telegraf.conf:
--------------------------------------------------------------------------------
1 | [global_tags]
2 |
3 | [agent]
4 | interval = "10s"
5 | round_interval = true
6 | metric_batch_size = 1000
7 | metric_buffer_limit = 10000
8 | collection_jitter = "0s"
9 | flush_interval = "10s"
10 | flush_jitter = "0s"
11 | precision = "0s"
12 | hostname = ""
13 | omit_hostname = false
14 |
15 | [[outputs.influxdb_v2]]
16 | urls = ["http://influxdb:8086"]
17 | token = "12345678"
18 | organization = "pullock"
19 | bucket = "pullock-bucket"
20 |
21 | [[inputs.cpu]]
22 | percpu = true
23 | totalcpu = true
24 | collect_cpu_time = false
25 | report_active = false
26 | core_tags = false
27 | [[inputs.disk]]
28 | ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
29 | [[inputs.diskio]]
30 |
31 | [[inputs.kernel]]
32 |
33 | [[inputs.mem]]
34 |
35 | [[inputs.processes]]
36 |
37 | [[inputs.swap]]
38 |
39 | [[inputs.system]]
40 |
41 | # ## DEPRECATED: The 'jolokia' plugin is deprecated in version 1.5.0, use 'inputs.jolokia2' instead.
42 | # # Read JMX metrics through Jolokia
43 | [[inputs.jolokia]]
44 | context = "/actuator/jolokia/"
45 | [[inputs.jolokia.servers]]
46 | name = "spring-boot-monitoring-actuator-telegraf-influxdb-grafana"
47 | host = "spring-boot-monitoring-actuator-telegraf-influxdb-grafana"
48 | port = "8080"
49 | [[inputs.jolokia.metrics]]
50 | name = "heap_memory_usage"
51 | mbean = "java.lang:type=Memory"
52 | attribute = "HeapMemoryUsage"
53 | [[inputs.jolokia.metrics]]
54 | name = "thread_count"
55 | mbean = "java.lang:type=Threading"
56 | attribute = "TotalStartedThreadCount,ThreadCount,DaemonThreadCount,PeakThreadCount"
57 | [[inputs.jolokia.metrics]]
58 | name = "class_count"
59 | mbean = "java.lang:type=ClassLoading"
60 | attribute = "LoadedClassCount,UnloadedClassCount,TotalLoadedClassCount"
61 |
62 |
63 | # # Read JMX metrics from a Jolokia REST agent endpoint
64 | # [[inputs.jolokia2_agent]]
65 | # # default_tag_prefix = ""
66 | # # default_field_prefix = ""
67 | # # default_field_separator = "."
68 | #
69 | # # Add agents URLs to query
70 | # urls = ["http://localhost:8080/jolokia"]
71 | # # username = ""
72 | # # password = ""
73 | # # response_timeout = "5s"
74 | #
75 | # ## Optional TLS config
76 | # # tls_ca = "/var/private/ca.pem"
77 | # # tls_cert = "/var/private/client.pem"
78 | # # tls_key = "/var/private/client-key.pem"
79 | # # insecure_skip_verify = false
80 | #
81 | # ## Add metrics to read
82 | # [[inputs.jolokia2_agent.metric]]
83 | # name = "java_runtime"
84 | # mbean = "java.lang:type=Runtime"
85 | # paths = ["Uptime"]
86 |
87 |
88 | # # Read JMX metrics from a Jolokia REST proxy endpoint
89 | # [[inputs.jolokia2_proxy]]
90 | # # default_tag_prefix = ""
91 | # # default_field_prefix = ""
92 | # # default_field_separator = "."
93 | #
94 | # ## Proxy agent
95 | # url = "http://localhost:8080/jolokia"
96 | # # username = ""
97 | # # password = ""
98 | # # response_timeout = "5s"
99 | #
100 | # ## Optional TLS config
101 | # # tls_ca = "/var/private/ca.pem"
102 | # # tls_cert = "/var/private/client.pem"
103 | # # tls_key = "/var/private/client-key.pem"
104 | # # insecure_skip_verify = false
105 | #
106 | # ## Add proxy targets to query
107 | # # default_target_username = ""
108 | # # default_target_password = ""
109 | # [[inputs.jolokia2_proxy.target]]
110 | # url = "service:jmx:rmi:///jndi/rmi://targethost:9999/jmxrmi"
111 | # # username = ""
112 | # # password = ""
113 | #
114 | # ## Add metrics to read
115 | # [[inputs.jolokia2_proxy.metric]]
116 | # name = "java_runtime"
117 | # mbean = "java.lang:type=Runtime"
118 | # paths = ["Uptime"]
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jre-alpine
2 | WORKDIR /app
3 |
4 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
5 | apk update
6 |
7 | COPY target/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana-1.0.0-SNAPSHOT.jar spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana.jar
8 | EXPOSE 8080
9 | ENTRYPOINT ["java", "-jar", "spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana.jar"]
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | # 定义网络:local_net
4 | networks:
5 | local_net:
6 | name: local_net
7 |
8 | # 定义服务
9 | services:
10 | # influxdb服务
11 | influxdb:
12 | image: influxdb:1.8
13 | ports:
14 | - 8086:8086
15 | networks:
16 | - local_net
17 | environment:
18 | - INFLUXDB_DB=telegraf
19 | - INFLUXDB_ADMIN_USER=admin
20 | - INFLUXDB_ADMIN_PASSWORD=12345678
21 | - INFLUXDB_USER=telegraf
22 | - INFLUXDB_USER_PASSWORD=12345678
23 |
24 | # telegraf服务
25 | telegraf:
26 | image: telegraf:latest
27 | networks:
28 | - local_net
29 | depends_on:
30 | - influxdb
31 | volumes:
32 | - ./telegraf/telegraf.conf:/etc/telegraf/telegraf.conf:ro
33 |
34 | # grafana服务
35 | grafana:
36 | image: grafana/grafana:latest
37 | ports:
38 | - 3000:3000
39 | networks:
40 | - local_net
41 |
42 | # 示例项目服务
43 | spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana:
44 | image: local_test/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana:1.0.0-SNAPSHOT
45 | ports:
46 | - 8080:8080
47 | networks:
48 | - local_net
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana/grafana/Spring Boot监控.json:
--------------------------------------------------------------------------------
1 | {
2 | "annotations": {
3 | "list": [
4 | {
5 | "builtIn": 1,
6 | "datasource": {
7 | "type": "datasource",
8 | "uid": "grafana"
9 | },
10 | "enable": true,
11 | "hide": true,
12 | "iconColor": "rgba(0, 211, 255, 1)",
13 | "name": "Annotations & Alerts",
14 | "target": {
15 | "limit": 100,
16 | "matchAny": false,
17 | "tags": [],
18 | "type": "dashboard"
19 | },
20 | "type": "dashboard"
21 | }
22 | ]
23 | },
24 | "editable": true,
25 | "fiscalYearStartMonth": 0,
26 | "graphTooltip": 0,
27 | "id": 1,
28 | "links": [],
29 | "liveNow": false,
30 | "panels": [
31 | {
32 | "aliasColors": {},
33 | "bars": false,
34 | "dashLength": 10,
35 | "dashes": false,
36 | "datasource": {
37 | "type": "influxdb",
38 | "uid": "upeJ1cMVz"
39 | },
40 | "fill": 1,
41 | "fillGradient": 0,
42 | "gridPos": {
43 | "h": 5,
44 | "w": 24,
45 | "x": 0,
46 | "y": 0
47 | },
48 | "hiddenSeries": false,
49 | "id": 1,
50 | "legend": {
51 | "avg": false,
52 | "current": false,
53 | "max": false,
54 | "min": false,
55 | "show": true,
56 | "total": false,
57 | "values": false
58 | },
59 | "lines": true,
60 | "linewidth": 1,
61 | "links": [],
62 | "nullPointMode": "null",
63 | "options": {
64 | "alertThreshold": true
65 | },
66 | "percentage": false,
67 | "pluginVersion": "9.1.1",
68 | "pointradius": 5,
69 | "points": false,
70 | "renderer": "flot",
71 | "seriesOverrides": [
72 | {
73 | "alias": "类加载总量",
74 | "yaxis": 2
75 | }
76 | ],
77 | "spaceLength": 10,
78 | "stack": false,
79 | "steppedLine": false,
80 | "targets": [
81 | {
82 | "alias": "类加载总量",
83 | "datasource": {
84 | "type": "influxdb",
85 | "uid": "upeJ1cMVz"
86 | },
87 | "dsType": "influxdb",
88 | "groupBy": [
89 | {
90 | "params": [
91 | "$__interval"
92 | ],
93 | "type": "time"
94 | },
95 | {
96 | "params": [
97 | "null"
98 | ],
99 | "type": "fill"
100 | }
101 | ],
102 | "measurement": "jolokia",
103 | "orderByTime": "ASC",
104 | "policy": "default",
105 | "refId": "A",
106 | "resultFormat": "time_series",
107 | "select": [
108 | [
109 | {
110 | "params": [
111 | "class_count_TotalLoadedClassCount"
112 | ],
113 | "type": "field"
114 | },
115 | {
116 | "params": [],
117 | "type": "mean"
118 | }
119 | ]
120 | ],
121 | "tags": []
122 | },
123 | {
124 | "alias": "类加载量",
125 | "datasource": {
126 | "type": "influxdb",
127 | "uid": "upeJ1cMVz"
128 | },
129 | "dsType": "influxdb",
130 | "groupBy": [
131 | {
132 | "params": [
133 | "$__interval"
134 | ],
135 | "type": "time"
136 | },
137 | {
138 | "params": [
139 | "null"
140 | ],
141 | "type": "fill"
142 | }
143 | ],
144 | "measurement": "jolokia",
145 | "orderByTime": "ASC",
146 | "policy": "default",
147 | "refId": "B",
148 | "resultFormat": "time_series",
149 | "select": [
150 | [
151 | {
152 | "params": [
153 | "class_count_LoadedClassCount"
154 | ],
155 | "type": "field"
156 | },
157 | {
158 | "params": [],
159 | "type": "mean"
160 | }
161 | ]
162 | ],
163 | "tags": []
164 | },
165 | {
166 | "alias": "类卸载量",
167 | "datasource": {
168 | "type": "influxdb",
169 | "uid": "upeJ1cMVz"
170 | },
171 | "dsType": "influxdb",
172 | "groupBy": [
173 | {
174 | "params": [
175 | "$__interval"
176 | ],
177 | "type": "time"
178 | },
179 | {
180 | "params": [
181 | "null"
182 | ],
183 | "type": "fill"
184 | }
185 | ],
186 | "measurement": "jolokia",
187 | "orderByTime": "ASC",
188 | "policy": "default",
189 | "refId": "C",
190 | "resultFormat": "time_series",
191 | "select": [
192 | [
193 | {
194 | "params": [
195 | "class_count_UnloadedClassCount"
196 | ],
197 | "type": "field"
198 | },
199 | {
200 | "params": [],
201 | "type": "mean"
202 | }
203 | ]
204 | ],
205 | "tags": []
206 | }
207 | ],
208 | "thresholds": [],
209 | "timeRegions": [],
210 | "title": "类加载",
211 | "tooltip": {
212 | "shared": true,
213 | "sort": 0,
214 | "value_type": "individual"
215 | },
216 | "type": "graph",
217 | "xaxis": {
218 | "mode": "time",
219 | "show": true,
220 | "values": []
221 | },
222 | "yaxes": [
223 | {
224 | "format": "short",
225 | "logBase": 1,
226 | "show": true
227 | },
228 | {
229 | "format": "short",
230 | "logBase": 1,
231 | "show": true
232 | }
233 | ],
234 | "yaxis": {
235 | "align": false
236 | }
237 | },
238 | {
239 | "aliasColors": {},
240 | "bars": false,
241 | "dashLength": 10,
242 | "dashes": false,
243 | "datasource": {
244 | "type": "influxdb",
245 | "uid": "upeJ1cMVz"
246 | },
247 | "fill": 1,
248 | "fillGradient": 0,
249 | "gridPos": {
250 | "h": 6,
251 | "w": 18,
252 | "x": 0,
253 | "y": 5
254 | },
255 | "hiddenSeries": false,
256 | "id": 5,
257 | "legend": {
258 | "avg": false,
259 | "current": false,
260 | "max": false,
261 | "min": false,
262 | "show": true,
263 | "total": false,
264 | "values": false
265 | },
266 | "lines": true,
267 | "linewidth": 1,
268 | "links": [],
269 | "nullPointMode": "null",
270 | "options": {
271 | "alertThreshold": true
272 | },
273 | "percentage": false,
274 | "pluginVersion": "9.1.1",
275 | "pointradius": 5,
276 | "points": false,
277 | "renderer": "flot",
278 | "seriesOverrides": [],
279 | "spaceLength": 10,
280 | "stack": false,
281 | "steppedLine": false,
282 | "targets": [
283 | {
284 | "alias": "堆内存使用量",
285 | "datasource": {
286 | "type": "influxdb",
287 | "uid": "upeJ1cMVz"
288 | },
289 | "dsType": "influxdb",
290 | "groupBy": [
291 | {
292 | "params": [
293 | "$__interval"
294 | ],
295 | "type": "time"
296 | },
297 | {
298 | "params": [
299 | "null"
300 | ],
301 | "type": "fill"
302 | }
303 | ],
304 | "measurement": "jolokia",
305 | "orderByTime": "ASC",
306 | "policy": "default",
307 | "refId": "A",
308 | "resultFormat": "time_series",
309 | "select": [
310 | [
311 | {
312 | "params": [
313 | "heap_memory_usage_used"
314 | ],
315 | "type": "field"
316 | },
317 | {
318 | "params": [],
319 | "type": "mean"
320 | }
321 | ]
322 | ],
323 | "tags": []
324 | }
325 | ],
326 | "thresholds": [],
327 | "timeRegions": [],
328 | "title": "堆内存",
329 | "tooltip": {
330 | "shared": true,
331 | "sort": 0,
332 | "value_type": "individual"
333 | },
334 | "type": "graph",
335 | "xaxis": {
336 | "mode": "time",
337 | "show": true,
338 | "values": []
339 | },
340 | "yaxes": [
341 | {
342 | "format": "decbytes",
343 | "logBase": 1,
344 | "show": true
345 | },
346 | {
347 | "format": "short",
348 | "logBase": 1,
349 | "show": true
350 | }
351 | ],
352 | "yaxis": {
353 | "align": false
354 | }
355 | },
356 | {
357 | "datasource": {
358 | "type": "influxdb",
359 | "uid": "upeJ1cMVz"
360 | },
361 | "fieldConfig": {
362 | "defaults": {
363 | "color": {
364 | "mode": "thresholds"
365 | },
366 | "mappings": [
367 | {
368 | "options": {
369 | "match": "null",
370 | "result": {
371 | "text": "N/A"
372 | }
373 | },
374 | "type": "special"
375 | }
376 | ],
377 | "max": 100,
378 | "min": 0,
379 | "thresholds": {
380 | "mode": "absolute",
381 | "steps": [
382 | {
383 | "color": "#299c46",
384 | "value": null
385 | },
386 | {
387 | "color": "rgba(237, 129, 40, 0.89)",
388 | "value": 50
389 | },
390 | {
391 | "color": "#d44a3a",
392 | "value": 90
393 | }
394 | ]
395 | },
396 | "unit": "none"
397 | },
398 | "overrides": []
399 | },
400 | "gridPos": {
401 | "h": 6,
402 | "w": 6,
403 | "x": 18,
404 | "y": 5
405 | },
406 | "id": 6,
407 | "links": [],
408 | "maxDataPoints": 100,
409 | "options": {
410 | "orientation": "horizontal",
411 | "reduceOptions": {
412 | "calcs": [
413 | "lastNotNull"
414 | ],
415 | "fields": "",
416 | "values": false
417 | },
418 | "showThresholdLabels": false,
419 | "showThresholdMarkers": true
420 | },
421 | "pluginVersion": "9.1.1",
422 | "targets": [
423 | {
424 | "datasource": {
425 | "type": "influxdb",
426 | "uid": "upeJ1cMVz"
427 | },
428 | "dsType": "influxdb",
429 | "groupBy": [
430 | {
431 | "params": [
432 | "$__interval"
433 | ],
434 | "type": "time"
435 | },
436 | {
437 | "params": [
438 | "null"
439 | ],
440 | "type": "fill"
441 | }
442 | ],
443 | "measurement": "cpu",
444 | "orderByTime": "ASC",
445 | "policy": "default",
446 | "refId": "A",
447 | "resultFormat": "time_series",
448 | "select": [
449 | [
450 | {
451 | "params": [
452 | "usage_system"
453 | ],
454 | "type": "field"
455 | },
456 | {
457 | "params": [],
458 | "type": "mean"
459 | }
460 | ]
461 | ],
462 | "tags": []
463 | }
464 | ],
465 | "title": "CPU",
466 | "type": "gauge"
467 | },
468 | {
469 | "aliasColors": {},
470 | "bars": false,
471 | "dashLength": 10,
472 | "dashes": false,
473 | "datasource": {
474 | "type": "influxdb",
475 | "uid": "upeJ1cMVz"
476 | },
477 | "fill": 1,
478 | "fillGradient": 0,
479 | "gridPos": {
480 | "h": 7,
481 | "w": 24,
482 | "x": 0,
483 | "y": 11
484 | },
485 | "hiddenSeries": false,
486 | "id": 4,
487 | "legend": {
488 | "avg": false,
489 | "current": false,
490 | "max": false,
491 | "min": false,
492 | "show": true,
493 | "total": false,
494 | "values": false
495 | },
496 | "lines": true,
497 | "linewidth": 1,
498 | "links": [],
499 | "nullPointMode": "null",
500 | "options": {
501 | "alertThreshold": true
502 | },
503 | "percentage": false,
504 | "pluginVersion": "9.1.1",
505 | "pointradius": 5,
506 | "points": false,
507 | "renderer": "flot",
508 | "seriesOverrides": [],
509 | "spaceLength": 10,
510 | "stack": false,
511 | "steppedLine": false,
512 | "targets": [
513 | {
514 | "alias": "已使用内存",
515 | "datasource": {
516 | "type": "influxdb",
517 | "uid": "upeJ1cMVz"
518 | },
519 | "dsType": "influxdb",
520 | "groupBy": [
521 | {
522 | "params": [
523 | "$__interval"
524 | ],
525 | "type": "time"
526 | },
527 | {
528 | "params": [
529 | "null"
530 | ],
531 | "type": "fill"
532 | }
533 | ],
534 | "measurement": "mem",
535 | "orderByTime": "ASC",
536 | "policy": "default",
537 | "refId": "A",
538 | "resultFormat": "time_series",
539 | "select": [
540 | [
541 | {
542 | "params": [
543 | "used"
544 | ],
545 | "type": "field"
546 | },
547 | {
548 | "params": [],
549 | "type": "mean"
550 | }
551 | ]
552 | ],
553 | "tags": []
554 | }
555 | ],
556 | "thresholds": [],
557 | "timeRegions": [],
558 | "title": "内存使用",
559 | "tooltip": {
560 | "shared": true,
561 | "sort": 0,
562 | "value_type": "individual"
563 | },
564 | "type": "graph",
565 | "xaxis": {
566 | "mode": "time",
567 | "show": true,
568 | "values": []
569 | },
570 | "yaxes": [
571 | {
572 | "format": "decbytes",
573 | "logBase": 1,
574 | "show": true
575 | },
576 | {
577 | "format": "short",
578 | "logBase": 1,
579 | "show": true
580 | }
581 | ],
582 | "yaxis": {
583 | "align": false
584 | }
585 | }
586 | ],
587 | "refresh": "5s",
588 | "schemaVersion": 37,
589 | "style": "dark",
590 | "tags": [],
591 | "templating": {
592 | "list": []
593 | },
594 | "time": {
595 | "from": "now-1h",
596 | "to": "now"
597 | },
598 | "timepicker": {
599 | "refresh_intervals": [
600 | "5s",
601 | "10s",
602 | "30s",
603 | "1m",
604 | "5m",
605 | "15m",
606 | "30m",
607 | "1h",
608 | "2h",
609 | "1d"
610 | ],
611 | "time_options": [
612 | "5m",
613 | "15m",
614 | "1h",
615 | "6h",
616 | "12h",
617 | "24h",
618 | "2d",
619 | "7d",
620 | "30d"
621 | ]
622 | },
623 | "timezone": "",
624 | "title": "Spring Boot监控",
625 | "uid": "NQDL15M4k",
626 | "version": 1,
627 | "weekStart": ""
628 | }
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-monitoring
7 | fun.pullock
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-actuator
23 |
24 |
25 |
26 | org.jolokia
27 | jolokia-core
28 |
29 |
30 |
31 | org.springframework.boot
32 | spring-boot-starter-test
33 | test
34 |
35 |
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-maven-plugin
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana/src/main/java/fun/pullock/monitoring/MonitoringActuatorTelegrafInfluxdb1xGrafanaApplication.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MonitoringActuatorTelegrafInfluxdb1xGrafanaApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(MonitoringActuatorTelegrafInfluxdb1xGrafanaApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8080
3 | spring:
4 | jmx:
5 | enabled: true
6 | management:
7 | endpoints:
8 | # 启用所有端口
9 | enabled-by-default: true
10 | web:
11 | exposure:
12 | # 暴露所有端口
13 | include: "*"
14 | endpoint:
15 | health:
16 | show-details: always
17 | jolokia:
18 | enabled: true
19 | config:
20 | debug: true
--------------------------------------------------------------------------------
/spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana/telegraf/telegraf.conf:
--------------------------------------------------------------------------------
1 | [global_tags]
2 |
3 | [agent]
4 | interval = "10s"
5 | round_interval = true
6 | metric_batch_size = 1000
7 | metric_buffer_limit = 10000
8 | collection_jitter = "0s"
9 | flush_interval = "10s"
10 | flush_jitter = "0s"
11 | precision = "0s"
12 | hostname = ""
13 | omit_hostname = false
14 |
15 | [[outputs.influxdb]]
16 | urls = ["http://influxdb:8086"]
17 | database = "telegraf"
18 | retention_policy = ""
19 | write_consistency = "any"
20 | timeout = "5s"
21 | username = "telegraf"
22 | password = "12345678"
23 |
24 | [[inputs.cpu]]
25 | percpu = true
26 | totalcpu = true
27 | collect_cpu_time = false
28 | report_active = false
29 | core_tags = false
30 | [[inputs.disk]]
31 | ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]
32 | [[inputs.diskio]]
33 |
34 | [[inputs.kernel]]
35 |
36 | [[inputs.mem]]
37 |
38 | [[inputs.processes]]
39 |
40 | [[inputs.swap]]
41 |
42 | [[inputs.system]]
43 |
44 | # ## DEPRECATED: The 'jolokia' plugin is deprecated in version 1.5.0, use 'inputs.jolokia2' instead.
45 | # # Read JMX metrics through Jolokia
46 | [[inputs.jolokia]]
47 | context = "/actuator/jolokia/"
48 | [[inputs.jolokia.servers]]
49 | name = "spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana"
50 | host = "spring-boot-monitoring-actuator-telegraf-influxdb1x-grafana"
51 | port = "8080"
52 | [[inputs.jolokia.metrics]]
53 | name = "heap_memory_usage"
54 | mbean = "java.lang:type=Memory"
55 | attribute = "HeapMemoryUsage"
56 | [[inputs.jolokia.metrics]]
57 | name = "thread_count"
58 | mbean = "java.lang:type=Threading"
59 | attribute = "TotalStartedThreadCount,ThreadCount,DaemonThreadCount,PeakThreadCount"
60 | [[inputs.jolokia.metrics]]
61 | name = "class_count"
62 | mbean = "java.lang:type=ClassLoading"
63 | attribute = "LoadedClassCount,UnloadedClassCount,TotalLoadedClassCount"
64 |
65 |
66 | # # Read JMX metrics from a Jolokia REST agent endpoint
67 | # [[inputs.jolokia2_agent]]
68 | # # default_tag_prefix = ""
69 | # # default_field_prefix = ""
70 | # # default_field_separator = "."
71 | #
72 | # # Add agents URLs to query
73 | # urls = ["http://localhost:8080/jolokia"]
74 | # # username = ""
75 | # # password = ""
76 | # # response_timeout = "5s"
77 | #
78 | # ## Optional TLS config
79 | # # tls_ca = "/var/private/ca.pem"
80 | # # tls_cert = "/var/private/client.pem"
81 | # # tls_key = "/var/private/client-key.pem"
82 | # # insecure_skip_verify = false
83 | #
84 | # ## Add metrics to read
85 | # [[inputs.jolokia2_agent.metric]]
86 | # name = "java_runtime"
87 | # mbean = "java.lang:type=Runtime"
88 | # paths = ["Uptime"]
89 |
90 |
91 | # # Read JMX metrics from a Jolokia REST proxy endpoint
92 | # [[inputs.jolokia2_proxy]]
93 | # # default_tag_prefix = ""
94 | # # default_field_prefix = ""
95 | # # default_field_separator = "."
96 | #
97 | # ## Proxy agent
98 | # url = "http://localhost:8080/jolokia"
99 | # # username = ""
100 | # # password = ""
101 | # # response_timeout = "5s"
102 | #
103 | # ## Optional TLS config
104 | # # tls_ca = "/var/private/ca.pem"
105 | # # tls_cert = "/var/private/client.pem"
106 | # # tls_key = "/var/private/client-key.pem"
107 | # # insecure_skip_verify = false
108 | #
109 | # ## Add proxy targets to query
110 | # # default_target_username = ""
111 | # # default_target_password = ""
112 | # [[inputs.jolokia2_proxy.target]]
113 | # url = "service:jmx:rmi:///jndi/rmi://targethost:9999/jmxrmi"
114 | # # username = ""
115 | # # password = ""
116 | #
117 | # ## Add metrics to read
118 | # [[inputs.jolokia2_proxy.metric]]
119 | # name = "java_runtime"
120 | # mbean = "java.lang:type=Runtime"
121 | # paths = ["Uptime"]
--------------------------------------------------------------------------------
/spring-boot-monitoring-admin/README.md:
--------------------------------------------------------------------------------
1 | # 使用
2 |
3 | 1. 启动`spring-boot-monitoring-admin-server`项目
4 | 2. 启动`spring-boot-monitoring-admin-client`项目
5 | 3. 访问`spring-boot-monitoring-admin-server`:`http://localhost:8000`
--------------------------------------------------------------------------------
/spring-boot-monitoring-admin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-monitoring
7 | fun.pullock
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-monitoring-admin
13 | pom
14 |
15 | spring-boot-monitoring-admin-server
16 | spring-boot-monitoring-admin-client
17 |
18 |
19 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-admin/spring-boot-monitoring-admin-client/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-monitoring-admin
7 | fun.pullock
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-monitoring-admin-client
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 | de.codecentric
22 | spring-boot-admin-starter-client
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-test
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-maven-plugin
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-admin/spring-boot-monitoring-admin-client/src/main/java/fun/pullock/monitoring/MonitoringAdminClientApplication.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MonitoringAdminClientApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(MonitoringAdminClientApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-admin/spring-boot-monitoring-admin-client/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8080
3 | spring:
4 | application:
5 | name: spring-boot-monitoring-admin-client
6 | boot:
7 | admin:
8 | client:
9 | url: http://localhost:8000
10 | jmx:
11 | enabled: true
12 | management:
13 | endpoints:
14 | # 启用所有端口
15 | enabled-by-default: true
16 | web:
17 | exposure:
18 | # 暴露所有端口
19 | include: "*"
20 | endpoint:
21 | health:
22 | show-details: always
23 | jolokia:
24 | enabled: true
25 | config:
26 | debug: true
--------------------------------------------------------------------------------
/spring-boot-monitoring-admin/spring-boot-monitoring-admin-server/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-monitoring-admin
7 | fun.pullock
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-monitoring-admin-server
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 | de.codecentric
22 | spring-boot-admin-starter-server
23 |
24 |
25 |
26 | org.springframework.boot
27 | spring-boot-starter-test
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-maven-plugin
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-admin/spring-boot-monitoring-admin-server/src/main/java/fun/pullock/monitoring/AdminServerConfig.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring;
2 |
3 | import de.codecentric.boot.admin.server.config.EnableAdminServer;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | @Configuration
7 | @EnableAdminServer
8 | public class AdminServerConfig {
9 | }
10 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-admin/spring-boot-monitoring-admin-server/src/main/java/fun/pullock/monitoring/MonitoringAdminServerApplication.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MonitoringAdminServerApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(MonitoringAdminServerApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-admin/spring-boot-monitoring-admin-server/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | server:
2 | port: 8000
--------------------------------------------------------------------------------
/spring-boot-monitoring-skywalking/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM apache/skywalking-java-agent:8.12.0-java8
2 |
3 | WORKDIR /app
4 | COPY target/spring-boot-monitoring-skywalking-1.0.0-SNAPSHOT.jar spring-boot-monitoring-skywalking.jar
5 | EXPOSE 8080
6 | ENTRYPOINT ["java", \
7 | "-javaagent:/skywalking/agent/skywalking-agent.jar", \
8 | "-Dskywalking.agent.service_name=spring-boot-monitoring-skywalking", \
9 | "-Dskywalking.collector.backend_service=skywalking-oap-server:11800", \
10 | "-jar", "spring-boot-monitoring-skywalking.jar"]
--------------------------------------------------------------------------------
/spring-boot-monitoring-skywalking/README.md:
--------------------------------------------------------------------------------
1 | # Spring-boot-monitoring-skywalking
2 |
3 | ## 将当前项目打包为Docker镜像
4 |
5 | 1. 在`spring-boot-monitoring-skywalking`根目录下创建`Dockerfile`文件,文件内容如下:
6 |
7 | ```
8 | FROM apache/skywalking-java-agent:8.12.0-java8
9 |
10 | WORKDIR /app
11 | COPY target/spring-boot-monitoring-skywalking-1.0.0-SNAPSHOT.jar spring-boot-monitoring-skywalking.jar
12 | EXPOSE 8080
13 | ENTRYPOINT ["java", \
14 | "-javaagent:/skywalking/agent/skywalking-agent.jar", \
15 | "-Dskywalking.agent.service_name=spring-boot-monitoring-skywalking", \
16 | "-Dskywalking.collector.backend_service=skywalking-oap-server:11800", \
17 | "-jar", "spring-boot-monitoring-skywalking.jar"]
18 | ```
19 |
20 | 2. 将项目`spring-boot-monitoring-skywalking`进行打包:`mvn clean package -Dmaven.test.skip=true`
21 |
22 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-skywalking:1.0.0-SNAPSHOT .`
23 |
24 | ## 使用Docker启动skywalking server、skywalking ui以及示例项目
25 |
26 | 使用docker compose安装:
27 |
28 | 1. 先编写`docker-compose.yml`文件,内容参考下方的`docker-compose.yml`文件内容
29 | 2. 启动`docker compose up -d`
30 | 3. 访问:`http://localhost:18080`
31 |
32 | ## 怎样运行当前示例
33 |
34 | 1. 克隆当前项目,进入`spring-boot-monitoring-skywalking`目录下
35 | 2. 将项目`spring-boot-monitoring-skywalking`进行打包:`mvn clean package -Dmaven.test.skip=true`
36 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-skywalking:1.0.0-SNAPSHOT .`
37 | 4. 启动:`docker compose up -d`
38 | 5. 使用skywalking,访问:`http://localhost:18080`
39 |
40 | ## `docker-compose.yml`文件内容
41 |
42 | ```yaml
43 | version: "3.8"
44 |
45 | # 定义网络:local_net
46 | networks:
47 | local_net:
48 | name: local_net
49 |
50 | # 定义服务
51 | services:
52 | # es7服务
53 | es7:
54 | image: elasticsearch:7.17.5
55 | ports:
56 | - 9200:9200
57 | - 9300:9300
58 | networks:
59 | - local_net
60 | healthcheck:
61 | test: [ "CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1" ]
62 | interval: 30s
63 | timeout: 10s
64 | retries: 3
65 | start_period: 10s
66 | environment:
67 | - discovery.type=single-node
68 |
69 | # skywalking-oap-server服务
70 | skywalking-oap-server:
71 | image: apache/skywalking-oap-server:8.9.1
72 | ports:
73 | - 11800:11800
74 | - 12800:12800
75 | networks:
76 | - local_net
77 | depends_on:
78 | es7:
79 | condition: service_healthy
80 | healthcheck:
81 | test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
82 | interval: 30s
83 | timeout: 10s
84 | retries: 3
85 | start_period: 10s
86 | environment:
87 | - SW_STORAGE=elasticsearch
88 | - SW_STORAGE_ES_CLUSTER_NODES=es7:9200
89 |
90 | # skywalking-ui服务
91 | skywalking-ui:
92 | image: apache/skywalking-ui:8.9.1
93 | ports:
94 | - 18080:8080
95 | networks:
96 | - local_net
97 | depends_on:
98 | - skywalking-oap-server
99 | environment:
100 | - SW_OAP_ADDRESS=http://skywalking-oap-server:12800
101 |
102 | # 示例项目服务
103 | spring-boot-monitoring-skywalking:
104 | image: local_test/spring-boot-monitoring-skywalking:1.0.0-SNAPSHOT
105 | ports:
106 | - 8080:8080
107 | networks:
108 | - local_net
109 | depends_on:
110 | skywalking-oap-server:
111 | condition: service_healthy
112 | ```
--------------------------------------------------------------------------------
/spring-boot-monitoring-skywalking/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | # 定义网络:local_net
4 | networks:
5 | local_net:
6 | name: local_net
7 |
8 | # 定义服务
9 | services:
10 | # es7服务
11 | es7:
12 | image: elasticsearch:7.17.5
13 | ports:
14 | - 9200:9200
15 | - 9300:9300
16 | networks:
17 | - local_net
18 | healthcheck:
19 | test: [ "CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1" ]
20 | interval: 30s
21 | timeout: 10s
22 | retries: 3
23 | start_period: 10s
24 | environment:
25 | - discovery.type=single-node
26 |
27 | # skywalking-oap-server服务
28 | skywalking-oap-server:
29 | image: apache/skywalking-oap-server:8.9.1
30 | ports:
31 | - 11800:11800
32 | - 12800:12800
33 | networks:
34 | - local_net
35 | depends_on:
36 | es7:
37 | condition: service_healthy
38 | healthcheck:
39 | test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
40 | interval: 30s
41 | timeout: 10s
42 | retries: 3
43 | start_period: 10s
44 | environment:
45 | - SW_STORAGE=elasticsearch
46 | - SW_STORAGE_ES_CLUSTER_NODES=es7:9200
47 |
48 | # skywalking-ui服务
49 | skywalking-ui:
50 | image: apache/skywalking-ui:8.9.1
51 | ports:
52 | - 18080:8080
53 | networks:
54 | - local_net
55 | depends_on:
56 | - skywalking-oap-server
57 | environment:
58 | - SW_OAP_ADDRESS=http://skywalking-oap-server:12800
59 |
60 | # 示例项目服务
61 | spring-boot-monitoring-skywalking:
62 | image: local_test/spring-boot-monitoring-skywalking:1.0.0-SNAPSHOT
63 | ports:
64 | - 8080:8080
65 | networks:
66 | - local_net
67 | depends_on:
68 | skywalking-oap-server:
69 | condition: service_healthy
--------------------------------------------------------------------------------
/spring-boot-monitoring-skywalking/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-monitoring
7 | fun.pullock
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-monitoring-skywalking
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-test
23 | test
24 |
25 |
26 |
27 |
28 |
29 |
30 | org.springframework.boot
31 | spring-boot-maven-plugin
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-skywalking/src/main/java/fun/pullock/monitoring/MonitoringSkywalkingApplication.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MonitoringSkywalkingApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(MonitoringSkywalkingApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-skywalking/src/main/java/fun/pullock/monitoring/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring.controller;
2 |
3 | import fun.pullock.monitoring.service.UserService;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import javax.annotation.Resource;
10 | import java.util.Random;
11 |
12 | @RestController
13 | @RequestMapping("/user")
14 | public class UserController {
15 |
16 | @Resource
17 | private UserService userService;
18 |
19 | @GetMapping("/query")
20 | public String query(@RequestParam Long id) {
21 |
22 | return userService.query(id);
23 | }
24 |
25 | @GetMapping("/random")
26 | public String random(@RequestParam Long id) {
27 | Random random = new Random();
28 | try {
29 | Thread.sleep(random.nextInt(5000));
30 | } catch (InterruptedException e) {
31 | throw new RuntimeException(e);
32 | }
33 |
34 | return userService.query(id);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-skywalking/src/main/java/fun/pullock/monitoring/service/UserService.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring.service;
2 |
3 | import org.springframework.stereotype.Service;
4 |
5 | @Service
6 | public class UserService {
7 |
8 | public String query(Long id) {
9 | try {
10 | Thread.sleep(1100);
11 | } catch (InterruptedException e) {
12 | throw new RuntimeException(e);
13 | }
14 |
15 | return "user: " + id;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-sleuth-zipkin/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM openjdk:8-jre-alpine
2 | WORKDIR /app
3 |
4 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
5 | apk update
6 |
7 | COPY target/spring-boot-monitoring-sleuth-zipkin-1.0.0-SNAPSHOT.jar spring-boot-monitoring-sleuth-zipkin.jar
8 | EXPOSE 8080
9 | ENTRYPOINT ["java", "-jar", "spring-boot-monitoring-sleuth-zipkin.jar"]
--------------------------------------------------------------------------------
/spring-boot-monitoring-sleuth-zipkin/README.md:
--------------------------------------------------------------------------------
1 | # Spring-boot-monitoring-sleuth-zipkin
2 |
3 | ## 将当前项目打包为Docker镜像
4 |
5 | 1. 在`spring-boot-monitoring-sleuth-zipkin`根目录下创建`Dockerfile`文件,文件内容如下:
6 |
7 | ```
8 | FROM openjdk:8-jre-alpine
9 | WORKDIR /app
10 |
11 | RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
12 | apk update && \
13 | COPY target/spring-boot-monitoring-sleuth-zipkin-1.0.0-SNAPSHOT.jar spring-boot-monitoring-sleuth-zipkin.jar
14 | EXPOSE 8080
15 | ENTRYPOINT ["java", "-jar", "spring-boot-monitoring-sleuth-zipkin.jar"]
16 | ```
17 |
18 | 2. 将项目`spring-boot-monitoring-sleuth-zipkin`进行打包:`mvn clean package -Dmaven.test.skip=true`
19 |
20 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-sleuth-zipkin:1.0.0-SNAPSHOT .`
21 |
22 | ## 使用Docker启动es、zipkin以及示例项目
23 |
24 | 使用docker compose安装:
25 |
26 | 1. 先编写`docker-compose.yml`文件,内容参考下方的`docker-compose.yml`文件内容
27 | 2. 启动`docker compose up -d`
28 | 3. 访问:`http://localhost:9411`
29 |
30 | ## 怎样运行当前示例
31 |
32 | 1. 克隆当前项目,进入`spring-boot-monitoring-sleuth-zipkin`目录下
33 | 2. 将项目`spring-boot-monitoring-sleuth-zipkin`进行打包:`mvn clean package -Dmaven.test.skip=true`
34 | 3. 创建应用的镜像,执行命令:`docker build -t local_test/spring-boot-monitoring-sleuth-zipkin:1.0.0-SNAPSHOT .`
35 | 4. 启动:`docker compose up -d`
36 | 5. 使用zipkin,访问:`http://localhost:9411`
37 |
38 | ## `docker-compose.yml`文件内容
39 |
40 | ```yaml
41 | version: "3.8"
42 |
43 | # 定义网络:local_net
44 | networks:
45 | local_net:
46 | name: local_net
47 |
48 | # 定义服务
49 | services:
50 | # es7服务
51 | es7:
52 | image: elasticsearch:7.17.5
53 | ports:
54 | - 9200:9200
55 | - 9300:9300
56 | networks:
57 | - local_net
58 | healthcheck:
59 | test: [ "CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1" ]
60 | interval: 30s
61 | timeout: 10s
62 | retries: 3
63 | start_period: 10s
64 | environment:
65 | - discovery.type=single-node
66 |
67 | # zipkin服务
68 | zipkin:
69 | image: openzipkin/zipkin:2.23.18
70 | ports:
71 | - 9411:9411
72 | networks:
73 | - local_net
74 | depends_on:
75 | es7:
76 | condition: service_healthy
77 | healthcheck:
78 | test: [ "CMD-SHELL", "/skywalking/bin/swctl ch" ]
79 | interval: 30s
80 | timeout: 10s
81 | retries: 3
82 | start_period: 10s
83 | environment:
84 | - STORAGE_TYPE=elasticsearch
85 | - ES_HOSTS=es7:9200
86 |
87 | # 示例项目服务
88 | spring-boot-monitoring-sleuth-zipkin:
89 | image: local_test/spring-boot-monitoring-sleuth-zipkin:1.0.0-SNAPSHOT
90 | ports:
91 | - 8080:8080
92 | networks:
93 | - local_net
94 | depends_on:
95 | zipkin:
96 | condition: service_healthy
97 | ```
--------------------------------------------------------------------------------
/spring-boot-monitoring-sleuth-zipkin/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | # 定义网络:local_net
4 | networks:
5 | local_net:
6 | name: local_net
7 |
8 | # 定义服务
9 | services:
10 | # es7服务
11 | es7:
12 | image: elasticsearch:7.17.5
13 | ports:
14 | - 9200:9200
15 | - 9300:9300
16 | networks:
17 | - local_net
18 | healthcheck:
19 | test: [ "CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1" ]
20 | interval: 30s
21 | timeout: 10s
22 | retries: 3
23 | start_period: 10s
24 | environment:
25 | - discovery.type=single-node
26 |
27 | # zipkin服务
28 | zipkin:
29 | image: openzipkin/zipkin:2.23.18
30 | ports:
31 | - 9411:9411
32 | networks:
33 | - local_net
34 | depends_on:
35 | es7:
36 | condition: service_healthy
37 | environment:
38 | - STORAGE_TYPE=elasticsearch
39 | - ES_HOSTS=es7:9200
40 |
41 | # 示例项目服务
42 | spring-boot-monitoring-sleuth-zipkin:
43 | image: local_test/spring-boot-monitoring-sleuth-zipkin:1.0.0-SNAPSHOT
44 | ports:
45 | - 8080:8080
46 | networks:
47 | - local_net
48 | depends_on:
49 | - zipkin
--------------------------------------------------------------------------------
/spring-boot-monitoring-sleuth-zipkin/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | spring-boot-monitoring
7 | fun.pullock
8 | 1.0.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | spring-boot-monitoring-sleuth-zipkin
13 |
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-web
18 |
19 |
20 |
21 | org.springframework.boot
22 | spring-boot-starter-test
23 | test
24 |
25 |
26 |
27 | org.springframework.cloud
28 | spring-cloud-starter-sleuth
29 |
30 |
31 |
32 | org.springframework.cloud
33 | spring-cloud-sleuth-zipkin
34 |
35 |
36 |
37 |
38 |
39 |
40 | org.springframework.boot
41 | spring-boot-maven-plugin
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-sleuth-zipkin/src/main/java/fun/pullock/monitoring/MonitoringSleuthZipkinApplication.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class MonitoringSleuthZipkinApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(MonitoringSleuthZipkinApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-sleuth-zipkin/src/main/java/fun/pullock/monitoring/controller/UserController.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring.controller;
2 |
3 | import fun.pullock.monitoring.service.UserService;
4 | import org.springframework.web.bind.annotation.GetMapping;
5 | import org.springframework.web.bind.annotation.RequestMapping;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | import javax.annotation.Resource;
10 | import java.util.Random;
11 |
12 | @RestController
13 | @RequestMapping("/user")
14 | public class UserController {
15 |
16 | @Resource
17 | private UserService userService;
18 |
19 | @GetMapping("/query")
20 | public String query(@RequestParam Long id) {
21 |
22 | return userService.query(id);
23 | }
24 |
25 | @GetMapping("/random")
26 | public String random(@RequestParam Long id) {
27 | Random random = new Random();
28 | try {
29 | Thread.sleep(random.nextInt(5000));
30 | } catch (InterruptedException e) {
31 | throw new RuntimeException(e);
32 | }
33 |
34 | return userService.query(id);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-sleuth-zipkin/src/main/java/fun/pullock/monitoring/service/UserService.java:
--------------------------------------------------------------------------------
1 | package fun.pullock.monitoring.service;
2 |
3 | import org.springframework.stereotype.Service;
4 |
5 | @Service
6 | public class UserService {
7 |
8 | public String query(Long id) {
9 | try {
10 | Thread.sleep(1100);
11 | } catch (InterruptedException e) {
12 | throw new RuntimeException(e);
13 | }
14 |
15 | return "user: " + id;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/spring-boot-monitoring-sleuth-zipkin/src/main/resources/application.yml:
--------------------------------------------------------------------------------
1 | spring:
2 | zipkin:
3 | enabled: true
4 | base-url: http://zipkin:9411
5 | sleuth:
6 | sampler:
7 | probability: 1.0
--------------------------------------------------------------------------------