Git Product home page Git Product logo

fsnano_loganalysis's Introduction

Log analysys project

The main scope is to answer 3 questions about the news database:

  • What are the most popular three articles of all time?
  • Who are the most popular article authors of all time?
  • On which days did more than 1% of requests lead to errors?

Usage

To run the program you need python 3 (tested with version 3.5.2) and the new database from the Fullstack Nanodegree Virtual machine . Also you need to run the views.sql file.

psql -d news
\i views.sql

Inside the virtual machine running python3 logAnalysis.py will show usage message. There are 4 possible paramaters to pass:

  • -a : will print results for all the 3 questions
  • -getMostPopular3Articles : will print the 3 most popular articles of all time
  • -getMostPopularAuthors : will print authors ordered, most popular first
  • -getDaysWithMore1PercError : will print days on which more than 1% of request lead to error

To simplify python code various views has been created:

create view authorsarticles as
    SELECT authors.name,
            concat('/article/', articles.slug) AS path
    FROM articles,authors
    WHERE articles.author = authors.id
    GROUP BY articles.author, authors.name, articles.slug
    ORDER BY articles.author;

create view authorviews as
    SELECT ll.name, sum(ll.numviews) AS totalviews
    FROM ( SELECT authorsarticles.name,
                  count(log.path) AS numviews
           FROM log, authorsarticles
           WHERE log.path = authorsarticles.path
           GROUP BY log.path, authorsarticles.name
           ORDER BY authorsarticles.name) AS ll
    GROUP BY ll.name
    ORDER BY (sum(ll.numviews)) DESC;

create view errorrequest as
    SELECT date(log."time") AS data,
            count(*) AS totalrequest
    FROM log
    WHERE log.status <> '200 OK'::text
    GROUP BY (date(log."time"))
    ORDER BY (date(log."time"));

create view errorrequestperc as
	SELECT err.data,
    err.totalrequest::double precision / totreq.totalrequest::double precision * 100::double precision AS perc
    FROM errorrequest err, totalrequest totreq
    WHERE err.data = totreq.data;

create view mostviewedpath as 
	SELECT log.path, count(log.path) AS numviews
    FROM log, articles
    WHERE log.path = concat('/article/', articles.slug)
    GROUP BY log.path
    ORDER BY (count(log.path)) DESC
    LIMIT 3;


create view totalrequest as 
    SELECT date(log."time") AS data, count(*) AS totalrequest
    FROM log
    GROUP BY (date(log."time"))
    ORDER BY (date(log."time"));


fsnano_loganalysis's People

Contributors

snicholas avatar

Watchers

James Cloos avatar  avatar

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.