我正在 Azure Kubernetes 服务 (AKS) 上的 Kubernetes 集群内运行 Neo4j 数据库。 Neo4j pod 将其日志(包括
query.log
)写入容器内位于 /logs/query.log
的文件系统。
我想收集
query.log
(或来自 Log4j 的流)并使用 Azure Monitor Agent (AMA) 将其发送到 Azure Log Analytics 以进行集中日志记录和监视。
我已尝试以下步骤:
为容器启用 Azure Monitor:
kube-system
命名空间中的 DaemonSet。创建了 ConfigMap 来配置 AMA:
在
ConfigMap
命名空间中创建了一个名为 container-azm-ms-agentconfig
的 kube-system
,其中包含以下内容:
apiVersion: v1
kind: ConfigMap
metadata:
name: container-azm-ms-agentconfig
namespace: kube-system
data:
config.yaml: |
schema-version: v1
config-version: 1.0
logs:
- name: neo4j-query-log
enabled: true
namespace: graph
containerNames:
- neo4j
filePaths:
- /logs/query.log
应用了 ConfigMap:
kubectl apply -f ama-neo4j-config.yaml
应用配置。但是,经过等待和检查,我没有看到来自
query.log
的日志出现在Azure Log Analytics中。代理似乎正在工作,并且正在收集其他日志,但不是来自容器内部的日志。
我了解到 Azure Monitor 代理无法直接访问容器文件系统内的文件。
问题:
如何配置 Azure Monitor 代理以从 Neo4j 容器内的 Log4j 收集
query.log
或流日志并将其发送到 Azure Log Analytics?有推荐的方法来实现这一目标吗?
附加信息:
graph
命名空间中的容器中运行。neo4j
。query.log
文件位于容器内的 /logs/query.log
。正如评论中提到的,sidecar 容器可用于从 Neo4j 容器中读取 query.log 文件,并使其可供 AMA 访问,然后 AMA 可以从共享节点目录收集该文件。编辑 Neo4j 部署文件以添加一个 sidecar 容器,该容器读取 query.log 并将其输出到共享节点目录。
示例
apiVersion: apps/v1
kind: Deployment
metadata:
name: neo4j
namespace: graph
spec:
replicas: 1
selector:
matchLabels:
app: neo4j
template:
metadata:
labels:
app: neo4j
spec:
containers:
- name: neo4j
image: neo4j:latest
volumeMounts:
- name: logs
mountPath: /logs
- name: log-forwarder
image: busybox
command: ["/bin/sh", "-c", "tail -F /logs/query.log > /node-logs/query.log"]
volumeMounts:
- name: logs
mountPath: /logs # Neo4j log directory
- name: node-logs
mountPath: /node-logs # Shared directory on the node
readOnly: false
volumes:
- name: logs
emptyDir: {} # Log storage within the pod
- name: node-logs
hostPath:
path: /var/log/neo4j
type: DirectoryOrCreate
现在 sidecar 正在将
query.log
转发到主机节点上的 /var/log/neo4j
,配置 AMA 从该位置收集日志。
按如下方式更新您的 ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: container-azm-ms-agentconfig
namespace: kube-system
data:
config.yaml: |
schema-version: v1
config-version: 1.0
logs:
- name: neo4j-query-log
enabled: true
filePaths:
- /var/log/neo4j/query.log
namespace: graph
在集群上启用监视并将其链接到您的 Log Analytics 工作区
az aks enable-addons --resource-group arkorg --name Neo4jakscluster --addons monitoring --workspace-resource-id "/subscriptions/abcd-efg-hijk-lmnop-912345bc7d/resourceGroups/arkorg/providers/Microsoft.OperationalInsights/workspaces/Neo4jloganalytics"
此方法可确保将
query.log
摄取到 Azure Log Analytics 中以进行集中监控,而无需修改 Neo4j 容器映像。