Finology 大数据金融

通过大数据以量化金融

Spring Boot Actuator 是 Spring Boot 的一套监控系统。

依赖

1
2
3
4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

顺便提一句,spring boot 的官方依赖,一般是 spring-boot-starter-xxxx 这种格式的。非官方依赖则是 xxxx-spring-boot-starter 这种格式的。

启动项目。

访问 http://localhost:8080/actuator

可以看到有两个endpoints,一个是 health, 一个是 info。

访问 health:

http://localhost:8080/actuator/health

1
2
3
{
status: "UP"
}

访问 info:

http://localhost:8080/actuator/info

1
{ }

是一个空对象。

我们可以在 application.yml 配置文件中做如下配置:

1
2
3
4
5
6
7
8
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: metrics, health, info

management.endpoint.health.show-details=always 表示在访问 health 时,除了显示 UP 这个状态以外,还要显示更多的信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
status: "UP",
components: {
db: {
status: "UP",
details: {
database: "MySQL",
result: 1,
validationQuery: "/* ping */ SELECT 1"
}
},
diskSpace: {
status: "UP",
details: {
total: 250790436864,
free: 18968088576,
threshold: 10485760
}
},
ping: {
status: "UP"
}
}
}

endpoints.web.exposure.include=metrics, health, info 这个表示可以显示的endpoint。

这个值可以填写 *,但是,如果是yaml文件,必须是'*'',而 application.properties 可以直接写 *。这是 yaml 文件和 properties 文件的区别。

我们可以设置 info:

1
2
3
info:
app-name: springboot-mybatis-plus
author: simon

这样,在访问 info endpoint 时,就可以显示上面配置的信息了。

1
2
3
4
{
app-name: "springboot-mybatis-plus",
author: "simon"
}

如果 yaml 里面带了环境变量,在开发时,可以在 IDEA 里面设置。在控制台运行时,命令如下:

java -jar xxx.jar --SOME_ENV=certain_env

平时我们使用的时间时间戳一般都是13位带毫秒数和10位不带毫秒数的。.net有个 ticks 的概念,是18位的时间戳。

意义是从公元1月1日零点开始的,到现在有多少个100纳秒。

这个 ticks * 100 为纳秒数,然后除以 1000 变为微秒数。

1
2
3
4
5
6
7
from datetime import *
ticks = 637170897393060000
t = datetime(1, 1, 1) + timedelta(microseconds = ticks // 10)

print(datetime.strftime(t, '%Y-%m-%d %H:%M:%S'))

2020-02-12 07:35:39

我们使用 apache 的 pdfbox 工具,来处理 pdf。在把 pdf 转图片时,会遇到如下一些问题。

1
WARN 8776 --- [           main] o.a.pdfbox.pdmodel.font.PDType0Font      : No Unicode mapping for CID+3585 (3585) in font DJXXII+PingFangSC-Regular

这个应该是找不到字体,不过是 WARN 级别,在这里可以不用太在意。我找到很多方法,也没能解决掉这个警告。

处理字体时,需要加入以下依赖。

1
2
3
4
5
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>fontbox</artifactId>
<version>2.0.19</version>
</dependency>
1
ERROR 8776 --- [           main] o.a.p.contentstream.PDFStreamEngine      : Cannot read JBIG2 image: jbig2-imageio is not installed

需要添加如下依赖:

1
2
3
4
5
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>jbig2-imageio</artifactId>
<version>3.0.3</version>
</dependency>
1
ERROR 9074 --- [           main] o.a.p.contentstream.PDFStreamEngine      : Cannot read JPEG2000 image: Java Advanced Imaging (JAI) Image I/O Tools are not installed

需要添加如下依赖:

1
2
3
4
5
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-jpeg2000</artifactId>
<version>1.3.0</version>
</dependency>

jai-imageio-jpeg2000 会依赖相同版本的 jai-imageio-core,但我们可以使用最新版本的 jai-imageio-core

1
2
3
4
5
<dependency>
<groupId>com.github.jai-imageio</groupId>
<artifactId>jai-imageio-core</artifactId>
<version>1.4.0</version>
</dependency>
0%