SkyWalking:
运行jar包前执行skywalking的准备方法,如果通过Dockerfile部署:
### 基础镜像,openjkd使用11.0.3-slim FROM harbor-t.vcredit.com.local/yunwei/openjdk:11.0.3-slim-sw8.1 #声明一个挂载点,容器内此路径会对应宿主机的某个文件夹 VOLUME /tmp #声明工作目录 WORKDIR /home #应用构建成功后的jar文件被复制到镜像的工作目录内,名字也改成了app.jar COPY target/*.jar /home/app.jar #添加运行权限 RUN chmod +x app.jar #设置时区,容器时间与主机时间保持一致 RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone #启动容器时的进程 ENTRYPOINT java -javaagent:/home/agent/skywalking-agent.jar -jar /home/app.jar $ARGS --spring.profiles.active=$PROFILE
Prometheus:
1.添加依赖
<!--prometheus监控服务--> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency>
2.添加配置(application.yml)
management:
metrics:
tags:
application: ${spring.application.name}
export:
prometheus:
enabled: true
jmx:
enabled: true
endpoints:
web:
exposure:
include: '*'
# base-path: /metrics # 默认:actuator
3.启动类添加Bean,来监控 JVM 性能指标信息
import io.micrometer.core.instrument.MeterRegistry; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.core.env.ConfigurableEnvironment; @EnableApolloConfig @SpringBootApplication(scanBasePackages = "com.vcredit.fts") @EnableEcmService @Slf4j public class FtsProcessApplication { @Bean MeterRegistryCustomizer<MeterRegistry> configurer( @Value("${spring.application.name}") String applicationName) { return registry -> registry.config().commonTags("application", applicationName); } public static void main(String[] args) { ConfigurableEnvironment environment = SpringApplication.run(FtsProcessApplication.class,args).getEnvironment(); MainShowInfoUtil.showApplicationSummary(environment); } }
4.查看程序信息输出
prometheus地址:http://localhost:{}/metrics/prometheus