Giter Site home page Giter Site logo

smu-is459's Introduction

Assignment 4 Guide

In this assignment, the goal is to retrieve the top 10 users we got from Assignment 3 and display it on the dashboard. My approach is to use Kafka Streaming to stream the results we got previously from Assignment 3. So instead of writing the stream to the console like we did in Assignment 3, I will be writing it to another Kafka Stream and the topic is called "dashboard_author". This code can be found in kafka_wordcount.py line 109 to line 121.

I have also added another field to the PostCount model called "timestamp" which is what I will be using to get the top 10 users to display. I then modified the previous db.sqlite3 to match with this change.

I then created another a consumer.py file which will consume the messages from the topic "dashboard_author" and save it into db.sqlite3. On top of the user_name and post_count, I will also be saving the timestamp which I got from Assignment 3. This timestamp is something I generated in Assignment 3 as seen in line 98 of kafka_wordcount.py.

In the views.py file, the only thing I changed is seen in tne snippet below. Instead of pulling all the objects, I will be pulling only the latest 10 post according to the timestamp. So even if there is no consumer running, I will still be pulling the latest 10 post which is stored inside db.sqlite3.

queryset = PostCount.objects.all().order_by('-timestamp')[:10]

The Screenshot of the dashboard:

alt text

Setting up Environment

Start from the base repository folder which is /SMU-IS459. Open a terminal and run the following code below to create an environemnt and install the requirements

virtualenv .env && source .env/bin/activate && pip install -r requirements.txt

Running the Program

  1. Start hadoop with the following commands. May differ from system to system depending on location of folder and version.
sudo service ssh start
cd ~/hadoop/hadoop-3.3.0
sbin/start-dfs.sh
sbin/start-yarn.sh
  1. Start zookeeper and kafka in 2 separate terminals
# TERMINAL 1
cd ~/kafka_2.12-2.8.0/
bin/zookeeper-server-start.sh config/zookeeper.properties
# TERMINAL 2
cd ~/kafka_2.12-2.8.0/
bin/kafka-server-start.sh config/server.properties
  1. Start the spark streaming job with Kafka connector in another terminal with the environment activated (from /SMU-IS459 base folder)
# TERMINAL 3
source .env/bin/activate
cd spark
spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.1.2 kafka_wordcount.py
  1. Run Scrapy Spider in another terminal with environment activated (from /SMU-IS459 base folder)
# TERMINAL 4
source .env/bin/activate
cd Scrapy/hardwarezone
scrapy runspider hardwarezone/spiders/spider.py
  1. Run Kafka consumer in another terminal
# TERMINAL 5
source .env/bin/activate
cd django/hwz_monitor/
python3 consumer.py
  1. Run Django in another terminal
# TERMINAL 6
source .env/bin/activate
cd django/hwz_monitor/
python3 manage.py runserver
  1. Open Django Dashboard in a Browser at: http://localhost:8000/dashboard/barchart

Delete scrapy-output topic from kafka (zookeeper and kafka needs to be started)

cd ~/kafka_2.12-2.8.0/
bin/kafka-topics.sh --zookeeper 127.0.0.1:2181 --delete --topic dashboard_author

smu-is459's People

Contributors

zhangzhenjie avatar gerardtan2018 avatar alichel avatar sandramathew187 avatar tyh2312 avatar bryan-tay avatar qilinpo avatar rudeous avatar tohwangting avatar ruequanteo2017 avatar krystenng avatar juinquok avatar jerrielloo avatar h-lixuan avatar faitheng avatar denysetan avatar danteliew6 avatar ruipeng1 avatar fan-yang-2017 avatar verachua avatar wlwong2018 avatar wwweimin avatar xtemplate24 avatar yuenhuiqi avatar zentan2018 avatar andrewliew2018 avatar deborahlee2018 avatar bryanhuihy avatar izzkhairable avatar kinhouu 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.