我有一个 SpringBoot 应用程序,它在 AKS 中的 POD 中运行。我配置了 Application Insights 代理。对我来说一切看起来都不错。但我在 Application Insights 中看不到我期望的数据。例如堆空间。也许我太笨了,找不到这些信息。 问题:我的设置还好吗?
SpringBoot 3.3.3
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>applicationinsights-runtime-attach</artifactId>
<version>3.5.4</version>
</dependency>
我为我的 Pod 配置了以下环境变量 APPLICATIONINSIGHTS_CONNECTION_STRING APPLICATIONINSIGHTS_AUTHENTICATION_STRING
当 Pod 启动时,我会看到代理的以下输出:
WARNING: A Java agent has been loaded dynamically (/tmp/otel-agent3340747174827410017/agent.jar) │
│ WARNING: If a serviceability tool is in use, please run with -XX:+EnableDynamicAgentLoading to hide this warning │
│ WARNING: If a serviceability tool is not in use, please run with -Djdk.instrument.traceUsage for more information │
│ WARNING: Dynamic loading of agents will be disallowed by default in a future release │
│ OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended │
│ 2024-09-19 09:18:27.414Z INFO c.m.a.a.i.c.ConfigurationBuilder - Some telemetry may be sampled out because a default sampling configuration was added in version 3.4.0 to reduce the default billing cost. You can set the sampling configuration explicitly: https://learn.microsoft.com/azure/azure-monitor/app/ja │
│ 2024-09-19 09:18:29.791Z INFO c.m.applicationinsights.agent - Application Insights Java Agent 3.5.4 started successfully (PID 1, JVM running for 3.66 s) │
│ 2024-09-19 09:18:29.797Z INFO c.m.applicationinsights.agent - Java version: 21.0.4, vendor: Eclipse Adoptium, home: /opt/java/openjdk │
│ │
│ . ____ _ __ _ _ │
│ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ │
│ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ │
│ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) │
│ ' |____| .__|_| |_|_| |_\__, | / / / / │
│ =========|_|==============|___/=/_/_/_/ │
│ │
│ :: Spring Boot :: (v3.3.3)
为部署在 AKS 内的 Spring Boot 应用程序配置 Application Insights
创建应用程序洞察
az monitor app-insights component create --app springboot-appinsights --location eastus --resource-group arkorg --kind web --application-type java
检索连接字符串
az monitor app-insights component show --app springboot-appinsights --resource-group arkorg --query connectionString --output tsv
相应地更新您的 pom.xml。将 Spring Boot Docker 映像推送到 Azure 容器注册表,并在 aks 部署和服务 yaml 中使用相同的内容
apiVersion: apps/v1
kind: Deployment
metadata:
name: springboot-app
labels:
app: springboot-app
spec:
replicas: 1
selector:
matchLabels:
app: springboot-app
template:
metadata:
labels:
app: springboot-app
spec:
containers:
- name: springboot-app
image: arkoacr.azurecr.io/springboot-app:latest
ports:
- containerPort: 8080
env:
- name: APPLICATIONINSIGHTS_CONNECTION_STRING
value: "<Your-Application-Insights-Connection-String>"
- name: APPLICATIONINSIGHTS_JVM_METRICS
value: "true"
imagePullSecrets:
- name: acr-secret
服务
apiVersion: v1
kind: Service
metadata:
name: springboot-service
spec:
type: LoadBalancer
selector:
app: springboot-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
现在转到您的应用程序洞察,在实时指标下,您可以监控部署在 aks 内的 Spring Boot 应用程序
Azure Application Insights 现已配置为在 AKS pod 中运行的 Spring Boot 应用程序。从实时指标流中,您可以看到正在跟踪请求率,并且可以在遥测中看到成功 (
200 OK
) 和失败 (404
) 的 HTTP 请求。依赖项调用率和依赖项调用持续时间也受到监控,这意味着 Application Insights 正在捕获来自应用程序的传出调用。
您甚至可以在 aks 集群内验证相同的内容 -