Coder Social home page Coder Social logo

irisb1701 / logs-analysis Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 10 KB

Builds an informative summary from logs using reporting tool that retrieves from database the 3 most popular articles, 3 most popular authors, and and which days more than 1% of requests lead to errors.

Python 100.00%

logs-analysis's Introduction

Function

This project uses PostgreSQL and DB-API code to create a reporting tool that answers the following questions by querying a databse:

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

In this project we use a Linux-based Virtual Machine and the Psycopg2 Python Module

Requirements

User must have virtual environment(Vagrant) running and a copy of database file

Get Vagrant file here: https://github.com/udacity/fullstack-nanodegree-vm/blob/master/vagrant/Vagrantfile Download database here: https://d17h27t6h515a5.cloudfront.net/topher/2016/August/57b5f748_newsdata/newsdata.zip

Place logsproject.py and newsdata.sql in vagrant directory

If psycopg2 is not already installed, use command pip install psycopg2

How to run

Open terminal and make FSND-Virtual-Machine/vagrant current directory

Then run:

`vagrant up` and `vagrant ssh`

use following command to open database:

`psql news`

enter the following queries to create required views:

CREATE VIEW shortened2 AS SELECT path, COUNT(id) AS x FROM log GROUP BY path ORDER BY x DESC LIMIT 3 OFFSET 1;

CREATE VIEW articles4 AS SELECT *, CONCAT('/article/', slug) FROM articles;

CREATE VIEW z AS SELECT concat, title, name FROM articles4, authors WHERE articles4.author = authors.id;

CREATE VIEW y AS SELECT path, count(path) AS number_of_views FROM log GROUP BY path ORDER BY number_of_views desc;

CREATE VIEW ok AS SELECT time::date AS date, COUNT(status) AS no_error FROM log WHERE status = '200 OK' GROUP BY date;

CREATE VIEW error AS SELECT time::date AS date, COUNT(status) AS error FROM log WHERE status = '404 NOT FOUND' GROUP BY date;

CREATE VIEW together AS SELECT ok.date, error, no_error FROM ok, error WHERE ok.date = error.date;

CREATE VIEW divide AS SELECT date, 100*(error::decimal / no_error) AS percentage FROM together;

exit psql using CTRL + D and run command: python logsproject.py

logs-analysis's People

Contributors

irisb1701 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.