Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Python for analyzing the Logs

RahulG
Altocumulus
Altocumulus

We are having Tomcat memory issues on multiple F5 devices. We need to create a python script to analyze logs on multiple devices and find if there is a log "java.lang.OutOfMemoryError: " in /var/log/tomcat/catalina.out. Could someone please help me draft this script.

2 REPLIES 2

Dont you have a centralized logging, like splunk, syslog servers. I'm sure there will be.

Simply use splunk or your monitoring tool to search for the OOM log

Satoshi_Toyosa1
F5 Employee
F5 Employee

If I do not want to use an external logging service, I am in a hurry, and my boxes have adequate power and bandwidth, I would use iControl REST POST /mgmt/tm/util/bash to call "cat <file> | grep keywords". Run this against all the boxes one by one.

$ curl -sku $PASS https://$HOST/mgmt/tm/util/bash \
  -X POST -H "Content-type: application/json" \
 -d '{"command":"run", "utilCmdArgs": "-c \"cat /var/log/tomcat/catalina.out | grep \\\"Unknown version\\\"\""}' \
  | jq -r '.commandResult'
WARNING: Unknown version string [3.1]. Default version will be used.

(I chose "Unknow version" for grepping as my log presently does not have OutOfMemoryError".)

I chose jq for parsing. You can do the same using python, of course. Be careful with the double escaping for double-quotes. We can easily make mistakes (For the above call, I tried three times :-).

For a sophisticated method for deploying logging facility, check F5 Telemetry Streaming.