简体   繁体   中英

Log Analysis in Python

For our internal monitoring process, I want to find out how many exceptions have taken place on a particular day. We want to extract the information from the log file of our application (Pylons project).

I want to do this in Python itself. I am aware that I can write a script which will do the offline processing on the log for counting the number of exceptions (and possibly other information related to the exception as well).

I want to ask whether there is already some library which I can use to do log file analysis in Python or what is the best way to do this?

I just had a similar situation and found the logtools Python package for the job. I used it for analyzing a Tomcat6/Solr log file.

Copy log from server and install logtools in a virtualenv:

mkdir /tmp/logwtf
cd /tmp/logwtf
scp server:/var/log/tomcat6/catalina.2012-02-03.log ./catalina.log
virtualenv --system-site-packages --distribute .
. bin/activate
pip install -e 'git+https://github.com/adamhadani/logtools.git#egg=logtools'

Summarize search request traffic:

qps -r'^(.*?) org\.apache\.solr\.core\.SolrCore execute' \
    -F '%b %d, %Y %I:%M:%S %p' \
    -W900 \
    --ignore \
    <catalina.log

All server activity between 1:10 and 1:20 PM:

qps -r'^(.*? 1:1.:.. PM) ' \
    -F '%b %d, %Y %I:%M:%S %p' \
    -W15 \
    --ignore \
    <catalina.log

logtools includes additional scripts for filtering bots, tagging log lines by country, log parsing, merging, joining, sampling and filtering, aggregation and plotting, URL parsing, summary statistics and computing percentiles. See the the package's GitHub page for more information.

Some additional info, like a sample log would be nice. Generally speaking you can always use the powerful re library that work with regular expressions.

Regular Expressions

re Library

So yeah for general problems re is always a good possibility...

If you post a sample log I can see if I find anything that fits better to ur problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM