Giter VIP home page Giter VIP logo

nowke / realtime-dashboard-demo Goto Github PK

View Code? Open in Web Editor NEW
65.0 8.0 23.0 2.93 MB

A lightweight scalable real-time dashboard using React, GraphQL subscriptions and Redis PubSub

Home Page: https://dev.to/nowke/building-real-time-dashboard-using-react-graphql-subscriptions-and-redis-pubsub-2gip

JavaScript 92.21% HTML 6.69% CSS 1.10%
graphql-subscriptions redis-pubsub react apollo-subscription apollo-server-graphql

realtime-dashboard-demo's Introduction

A lightweight real-time dashboard using React, GraphQL subscriptions and Redis PubSub

Walkthrough: https://dev.to/nowke/building-real-time-dashboard-using-react-graphql-subscriptions-and-redis-pubsub-2gip

Preview

Preview

Setup

Prerequisites

  • Install NodeJS (LTS)
  • Install Redis (Server and Client)
    • MacOS - brew install redis
  • Install Yarn
    • MacOS - brew install yarn

Clone the repository

git clone https://github.com/nowke/realtime-dashboard-demo.git

(a) Setup server

Start Redis server

redis-server

Install dependencies

cd server
yarn install

Start the server

yarn start

Server will be running at http://localhost:4000/. The below UI will be rendered

GraphQL UI

(b) Setup worker

Install dependencies

cd worker
yarn install

Start the worker

yarn start

The following logs will be printed,

Starting worker
Scheduled Jobs for CPU, Traffic, distribution, messages
Fetched new results for MESSAGES
Fetched new results for CPU
Fetched new results for DISTRIBUTION
Fetched new results for CPU
Fetched new results for MESSAGES
Fetched new results for TRAFFIC
...

(c) Setup client

Install dependencies

cd client
yarn install

Start client

yarn start

Client will be running at http://localhost:3000. Dashboard picks up initial data from Redis, update itself at intervals.

Real-time dashboard

(d) Subscribe to Redis channels

Alternatively, subscribe to Redis channel directly using SUBSCRIBE <channel> command to get the feel of it!

For example, subscribe to CPU utilization channel - cpu. Observe values getting published to the channel while the worker is running.

$ redis-cli
127.0.0.1:6379> SUBSCRIBE cpu
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "cpu"
3) (integer) 1
4) "message"
5) "cpu"
6) "{\"cpu\":{\"percentage\":51}}"
7) "message"
8) "cpu"
9) "{\"cpu\":{\"percentage\":74}}"
10) "message"
11) "cpu"
12) "{\"cpu\":{\"percentage\":51}}"
13) "message"
14) "cpu"
15) "{\"cpu\":{\"percentage\":43}}"
...

(e) Publish to Redis channels

Kill the worker process to stop the dashboard from getting new values. Now, publish the values directly from Redis using PUBLISH <channel> <value> command.

Note: Provide a valid JSON String as value for the dashboard to render the value correctly.

Publish a 53% value as CPU percentage

$ redis-cli
127.0.0.1:6379> PUBLISH cpu "{\"cpu\":{\"percentage\":53}}"
(integer) 1
127.0.0.1:6379>

And, the dashboard's CPU panel shows 53% value immediately

Client CPU Value

Available channels in the example are,

  • cpu
  • traffic
  • distribution
  • messages

References

realtime-dashboard-demo's People

Contributors

dependabot[bot] avatar nowke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

realtime-dashboard-demo's Issues

Update setup procedures

Write setup and README for the following items

  • Setup server
  • Setup client
  • Setup worker
  • Main README

Write a walkthrough

The post should include the following:

  • Motivation - what is the purpose
  • Introduction about GraphQL subscription
  • Redis PubSub overview
  • Server setup
  • Client setup
  • How to trigger an event (using GraphQL mutation)
  • Mocking events using a simple worker
  • Note about scaling and diagram
  • Self review
  • External review

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.