Collecting Tomcat Access and Garbage Collector Logs

Overview

This documentation provides detailed instructions about configuring the OpenTelemetry Collector to read Tomcat Server Access and Garbage Collector logs and push them to SigNoz, enabling you to analyze them effectively.

Sample Log

Here is how the Tomcat Access logs and Garbage Collector logs look like:

Sample Access Log

0:0:0:0:0:0:0:1 - - [18/Apr/2024:13:45:29 +0530] "GET /demo1/add?num1=1&num2=2 HTTP/1.1" 200 11
0:0:0:0:0:0:0:1 - - [18/Apr/2024:13:45:30 +0530] "GET /demo1/add?num1=2&num2=3 HTTP/1.1" 200 11

Sample Garbage Collector log

[0.724s][info][gc] GC(3) Concurrent Mark Cycle 6.218ms
[0.772s][info][gc] GC(4) Pause Young (Prepare Mixed) (G1 Preventive Collection) 28M->8M(40M) 1.891ms
[591.215s][info][gc] GC(5) Pause Young (Mixed) (G1 Evacuation Pause) 10M->8M(40M) 8.173ms

Collect Logs in SigNoz Cloud

Prerequisite

Sending logs to SigNoz cloud can be achieved by following these simple steps:

  • Installing OpenTelemetry Collector
  • Configuring filelog receiver

Install OpenTelemetry Collector

The OpenTelemetry collector provides a vendor-neutral way to collect, process, and export your telemetry data such as logs, metrics, and traces.

You can install OpenTelemetry collector (OTel collector) as an agent by following this guide.

Configure Filelog receiver

Modify the config.yaml file that you created while installing OTel collector in the previous step to include the filelog receiver. This involves specifying the path to your access and garbage collector logs and setting the start_at parameter, which specifies where to start reading logs from the log file. For more fields that are available for filelog receiver please check this link.

receivers:
  ...
  filelog/access_logs:
    include: [ /<path_to_access_log>/localhost_access_log.*] #include the path to your access logs
    start_at: end
  filelog/gc_logs:
    include: [ /<path_to_garbage_collector_log>/garbage-collection.log.*] #include the path to your garbage collector logs
    start_at: end
...
📝 Note

The start_at: end configuration ensures that only newly added logs are transmitted. If you wish to include historical logs from the file, remember to modify start_at to beginning.

📝 Note

If you want to change the path of where your access logs are stored you can change it by adding the following in your server arguments -Dcatalina.base=<new_access_logs_path>

If you want to change the path of where your garbage collector logs are stored you can change it by -Xloggc:<new_garbage_collection_logs_path>

Update Pipelines Configuration

In the same config.yaml file, update the pipeline settings to include the new filelog receiver. This step is crucial for ensuring that the logs are correctly processed and sent to SigNoz.

service:
    ....
    logs:
        receivers: [otlp, filelog/access_logs, filelog/gc_logs]
        processors: [batch]
        exporters: [otlp]

Now restart the OTel collector so that new changes are applied. The steps to run the OTel collector can be found here

Verify Export

The logs will be exported to SigNoz and will be visible in SigNoz UI.

access logs visible in SigNoz
Sample tomcat access logs data shown in SigNoz Logs Explorer

garbage logs visible in SigNoz
Sample tomcat garbage collector logs data shown in SigNoz Logs Explorer

Collect logs in self-hosted SigNoz

Collecting Tomcat Access and Garbage Collector logs in Self-Hosted SigNoz can have two scenarios:

  • SigNoz running on the same host
  • SigNoz running on different host

Running on the same host

If your self-hosted SigNoz is running on the same host, then you can follow these steps to collect your application logs.

Install SigNoz

You can install Self-Hosted SigNoz using the instructions here.

Modify Docker Compose file

In your self-hosted SigNoz setup, locate and edit the docker-compose.yaml file found in the deploy/docker/clickhouse-setup directory. You'll need to mount the log file of your application to the tmp directory of SigNoz OTel collector.

  ...
  otel-collector:
  image: signoz/signoz-otel-collector:0.88.11
  command: ["--config=/etc/otel-collector-config.yaml"]
  volumes:
    - ~/<access_logs_path>/:/<access_logs_path>/
    - ~/<garbage_collector_logs_path>/:/<garbage_collector_logs_path>/
  ....

Replace <access_logs_path> , <garbage_collector_logs_path> with the path where your access log and garbage collector log files are present. Please ensure that the file path is correctly specified.

Add Filelog receiver

Add the filelog reciever to otel-collector-config.yaml which is present inside deploy/docker/clickhouse-setup directory in your self-hosted SigNoz setup. The configuration below tells the collector where to find your log file and how to start processing it.

receivers:
  ...
  filelog/access_logs:
    include: [ /<path>/localhost_access_log.*] #include the path to your access logs
    start_at: end
  filelog/gc_logs:
    include: [ /<path>/garbage-collection.log.*] #include the path to your garbage collector logs
    start_at: end
...
📝 Note

The start_at: end configuration ensures that only newly added logs are transmitted. If you wish to include historical logs from the file, remember to modify start_at to beginning.

📝 Note

If you want to change the path of where your access logs are stored you can change it by adding the following in your server arguments -Dcatalina.base=<new_access_logs_path>

If you want to change the path of where your garbage collector logs are stored you can change it by -Xloggc:<new_garbage_collection_logs_path>

For more fields that are available for filelog receiver please check this link.

Update Pipeline configuration

Modify the pipeline inside otel-collector-config.yaml to include the filelog receiver. This step is crucial for ensuring that the logs are correctly processed and sent to SigNoz.

service:
    ....
    logs:
        receivers: [otlp, filelog/access_logs, filelog/gc_logs]
        processors: [batch]
        exporters: [clickhouselogsexporter]

Now, restart the OTel collector so that new changes are applied. You can find instructions to run OTel collector here

Verify Export

The logs will be exported to SigNoz UI if there are no errors.

Access logs visible in SigNoz
Sample tomcat access logs data shown in SigNoz Logs Explorer

garbage collector logs visible in SigNoz
Sample tomcat garbage collector logs data shown in SigNoz Logs Explorer

Running on a different host

If you have a SigNoz running on a different host then you will have to run a OTel collector to export logs from your host to the host where SigNoz is running.

Create OTel collector configuration

You need to create an otel-collector-config.yaml file, this file defines how the OTel collector will process and forward logs to your SigNoz instance.

receivers:
  filelog/access_logs:
    include: [ /<path>/localhost_access_log.*] #include the path to your access logs
    start_at: end
  filelog/gc_logs:
    include: [ /<path>/garbage-collection.log.*] #include the path to your garbage collector logs
    start_at: end
processors:
  batch:
    send_batch_size: 10000
    send_batch_max_size: 11000
    timeout: 10s
exporters:
  otlp/log:
    endpoint: http://<host>:<port>
    tls:
      insecure: true
service:
  pipelines:
    logs:
      receivers: [filelog/access_logs, filelog/gc_logs]
      processors: [batch]
      exporters: [ otlp/log ]

The parsed logs are batched up using the batch processor and then exported to the host where SigNoz is deployed. For finding the right host and port for your SigNoz cluster please follow the guide here.

📝 Note

The otlp/log exporter in the above configuration file uses a http endpoint but if you want to use https you will have to provide the certificate and the key. You can read more about it here

Was this page helpful?