Git Product home page Git Product logo

pg-logs's Introduction

Synopsis

This project is for the Udacity Full Stack Web Developer Nanodegree program. It is a log analysis project that is meant to query a database giving the results of top authors, top articles and highest request errors. It is made with python using psycopg2.

Installation

To install this all you have to do is clone this repository via git clone https://github.com/Brian-Dennis/logs or download the zip file of this repo. You will also need virtualbox from https://www.virtualbox.org/wiki/Downloads, and make sure you have the Udacity fullstack-nanodegree-vm provided in this repo https://github.com/udacity/fullstack-nanodegree-vm. after that you need to pull up a terminal window and go to the vagrant directory and run vagrant up then after that run vagrant ssh upon that finishing you mush cd vagrant/ then to open the database you need to run psql news then hit enter and this should render a news=> prompt.

SQL CREATE VIEWS

Once you have the vagrant opened in the terminal you are going to want to run psql news then to create the views and run the queries against the database you are going to want to copy and paste or type yourself in the terminal these commands: create or replace view slug_path as select a.slug, a.author, count(a.slug) from articles a, log l where l.path = concat ('/article/',a.slug) group by a.slug, a.author; then press enter.

create view status_table as select date(time), count(l.status) as status_count from log l where l.status = '200 OK' group by date(time); then press enter.

create view error_table as select date(time), count(l.status) as error_count from log l where l.status != '200 OK' group by date(time); then press enter.

create view error_rates as select s.date, (sum(e.error_count)/(sum(s.status_count) + sum(e.error_count))) * 100.0 as percent from error_table e, status_table s where s.date = e.date group by s.date; then press enter.

To get Results

run python logs.py or for a better rendering view run python3 logs.py

Credits

I used this site as a reference to see the functions in action.

W3schools Create Views - https://www.w3schools.com/sql/sql_view.asp demonstrates how to create views
W3schools count function - https://www.w3schools.com/sql/func_mysql_count.asp demonstrates the count function
W3schools sum function - https://www.w3schools.com/sql/func_mysql_sum.asp demonstrates the sum function
W3schools date function - https://www.w3schools.com/sql/func_mysql_date.asp demonstrates the date function

I also used https://www.generatedata.com/ to generate some similar mock data to the project and imported the file into pgadmin4 to then test my queries with a GUI.

That brings me to my next tool that I used which was pgadmin 4 https://www.pgadmin.org/

pg-logs's People

Contributors

brian-dennis 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.