Giter VIP home page Giter VIP logo

lala's Introduction

alternate text


Travis CI build status https://coveralls.io/repos/github/Edinburgh-Genome-Foundry/lala/badge.svg?branch=master

Lala is a Python library for access log analysis. It provides a set of methods to retrieve, parse and analyze access logs (only from NGINX for now), and makes it easy to plot geo-localization or time-series data. Think of it as a simpler, Python-automatable version of Google Analytics, to make reports like this:

alternate text

Usage

from lala import WebLogs
weblogs, errored_lines = WebLogs.from_nginx_weblogs('access_logs.txt')

Similarly, to fetch logs on a distant server (for which you have access keys) you would write:

from lala import get_remote_file_content, WebLogs

logs= lala.get_remote_file_content(
    host="cuba.genomefoundry.org", user='root',
    filename='/var/log/nginx_cuba/access.log'
)
weblogs, errors = WebLogs.from_nginx_weblogs(logs.split('\n'))

Now weblogs is a scpecial kind of Pandas dataframe where each row is one server access, with fields such as IP, date, referrer, country_name, etc.

alternate text

The web logs can therefore be analyzed using any of Pandas' built-in filtering and plotting functions. The WebLogs class also provides additional methods which are particularly useful to analyse web logs, for instance to plot pie-charts:

ax, country_values = weblogs.plot_piechart('country_name')

alternate text

Next we plot the location (cities) providing the most connexions:

ax = weblogs.plot_geo_positions()

alternate text

We can also restrict the entries to the UK, and plot a timeline of connexions:

uk_entries = weblogs[weblogs.country_name == 'United Kingdom']
ax = uk_entries.plot_timeline(bins_per_day=2)

alternate text

Here is how to get the visitors a list of visitors and visits, sort out the most frequent visitors, find their locations, and plot it all:

visitors = weblogs.visitors_and_visits()
visitors_locations = weblogs.visitors_locations()
frequent_visitors = weblogs.most_frequent_visitors(n_visitors=5)
ax = weblogs.plot_most_frequent_visitors(n_visitors=5)

alternate text

Lala can do more, such as identifying the domain name of the visitors, which can be used to filter out the robots of search engines:

weblogs.identify_ips_domains()
filtered_entries = weblogs.filter_by_text_search(
    terms=['googlebot', 'spider.yandex', 'baidu', 'msnbot'],
    not_in='domain'
)

Lala also plays nicely with the PDF Reports library to let you define report templates such as this one (written in Pug), and then generate this PDF report with the following code:

weblogs.write_report(template_path="path/to/template.pug",
                     target="report_example.pdf")

Installation

You can install lala through PIP

sudo pip install python-lala

Alternatively, you can unzip the sources in a folder and type

sudo python setup.py install

For plotting maps you will need Cartopy which is not always easy to install - it may depend on your system. If you are on Ubuntu 16+, first install the dependencies with:

sudo apt-get install libproj-dev proj-bin proj-data libgeos-dev
sudo pip install cython

License = MIT

lala is an open-source software originally written at the Edinburgh Genome Foundry by Zulko and released on Github under the MIT licence (Copyright 2018 Edinburgh Genome Foundry).

Everyone is welcome to contribute!

lala's People

Contributors

veghp avatar zulko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lala's Issues

Cannot install

When trying to pip install, I get this:

$ pip install python-lala                                                 
Collecting python-lala
  Using cached python-lala-0.1.3.tar.gz (26 kB)
    ERROR: Command errored out with exit status 1:
     command: [redacted]/venv/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-wkmc6xu7/python-lala/setup.py'"'"'; __file__='"'"'/tmp/pip-install-wkmc6xu7/python-lala/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-asc7g9e6                     
         cwd: /tmp/pip-install-wkmc6xu7/python-lala/
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-wkmc6xu7/python-lala/setup.py", line 13, in <module>                                     
        long_description=open('pypi-readme.rst').read(),
    FileNotFoundError: [Errno 2] No such file or directory: 'pypi-readme.rst'                                         
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.  

This is probably because you haven't included pypi-readme.rst in the release .. or similar.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.