Giter Club home page Giter Club logo

logs_analysis's Introduction

Logs Analysis

=============

Setting up

3. Download the SQL data "newsdata.sql" (link: https://d17h27t6h515a5.cloudfront.net/topher/2016/August/57b5f748_newsdata/newsdata.zip), unzip it, and then put it inside the folder "vagrant".

4. Right click on the folder "vagrant", click on "Git Bash here", a git bash terminal is open.

5. On the git bash terminal, set up vagrant by first running command vagrant up, second vagrant ssh. A "Ubuntu 16.04.3 LTS" virtual machine is built up.

6. Run command cd /vagrant, and then ls.

7. Run command psql -d news -f newsdata.sql to load the SQL data "newsdata.sql".

8. After loading "newsdata.sql", run psql news to explore the data.

Exploring the data

1. Run \dt, it displays 3 tables: articles, authors, log.

2. Run \d articles, \d authors, \d log, respectively. Each command responds with the columns and their types of each table.

3. Run select * from articles;, select * from authors;, select count(*) from log;, respectively, to furthur explore the data.

4. Enter \q to exit from data exploration.

Create views for the database

1. To reduce the complexity of creating queries for the first two questions: CREATE VIEW top_articles_view AS SELECT title, count(*) AS views FROM log JOIN articles ON log.path = concat('/article/', articles.slug) GROUP BY articles.title ORDER BY views DESC;. This view is created for listing articles according to their popularity in descending order, based on this, the queries for finding the three most popular articles and the most popular authors are created.

2. To reduce the complexity of creating a query for the third question: CREATE VIEW error_log_view SELECT date(TIME), round(100.0 * sum(CASE log.status WHEN '200 OK' THEN 0 ELSE 1 END) / count(log.status), 2) AS \"Percent Error\" FROM log GROUP BY date(TIME) ORDER BY \"Percent Error\" DESC;. This view is created for finding the days with percent of errors in descending order, based on this, the query for finding the days on which percent of errors is more than 1% is created.

Run Python file and get the results

1. Place logs_analysis.py inside the folder "vagrant".

2. Run python logs_analysis.py.

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.