I’m running a Neo4j database inside a Kubernetes cluster on Azure Kubernetes Service (AKS). The Neo4j pod writes its logs, including query.log
, to the filesystem inside the container at /logs/query.log
.
I want to collect the query.log
(or stream from Log4j) and send it to Azure Log Analytics using the Azure Monitor Agent (AMA) for centralized logging and monitoring.
I’ve tried the following steps:
-
Enabled Azure Monitor for Containers:
- Enabled monitoring on my AKS cluster via the Azure Portal.
- Deployed the Azure Monitor Agent as a DaemonSet in the
kube-system
namespace.
-
Created a ConfigMap to Configure AMA:
-
Created a
ConfigMap
namedcontainer-azm-ms-agentconfig
in thekube-system
namespace with the following content: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
-
-
Applied the ConfigMap:
- Used
kubectl apply -f ama-neo4j-config.yaml
to apply the configuration.
- Used
However, after waiting and checking, I do not see the logs from query.log
appearing in Azure Log Analytics. The agent seems to be working, and other logs are being collected, but not the ones from inside the container.
I’ve learned that the Azure Monitor Agent cannot access files inside a container’s filesystem directly.
Question:
How can I configure the Azure Monitor Agent to collect the query.log
or stream logs from Log4j inside the Neo4j container and send them to Azure Log Analytics? Is there a recommended approach to achieve this?
Additional Information:
- Neo4j is running in a container in the
graph
namespace. - The container name is
neo4j
. - The
query.log
file is located at/logs/query.log
inside the container. - I prefer not to modify the Neo4j container image if possible.
- I’m open to using sidecar containers or other methods that align with best practices.
2
Answers
As mentioned in comment a sidecar container can be used to read the query.log file from within the Neo4j container and make it accessible to AMA, which can then collect it from a shared node directory. Edit your Neo4j deployment file to add a sidecar container that reads query.log and outputs it to a shared node directory.
Example
Now the sidecar is forwarding
query.log
to/var/log/neo4j
on the host node, configure AMA to collect logs from this location.Update your ConfigMap as below
Enable monitoring on the cluster and link it to your Log Analytics workspace
This approach ensures that
query.log
is ingested into Azure Log Analytics for centralized monitoring without modifying the Neo4j container image.An alternative is writing the logs to the container stream instead of on the filesystem.
Here is a log4j2 configuration that works well for us on EKS :