Skip to content

Commit

Permalink
adding task for polling workers (I don't think we need this)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckablack committed Nov 3, 2020
1 parent d27a782 commit c461221
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 72 deletions.
5 changes: 4 additions & 1 deletion quokka-ui/src/components/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ServiceStatus from "./ServiceStatus";
import Events from "./Events";
import Capture from "./Capture";
import Workers from "./Workers";
import WorkerStatus from "./WorkerStatus"

class Dashboard extends Component {

Expand All @@ -26,7 +27,7 @@ class Dashboard extends Component {
}

render() {
const {deviceName, show, hostId, serviceId, ip, protocol, port} = this.state
const {deviceName, show, hostId, serviceId, workerId, ip, protocol, port} = this.state

let info;

Expand All @@ -50,6 +51,8 @@ class Dashboard extends Component {
info = <Capture ip={ip} protocol={protocol} port={port} dashboard={this}/>;
} else if (show === "workers") {
info = <Workers dashboard={this}/>;
} else if (show === "workerstatus") {
info = <WorkerStatus workerId={workerId} dashboard={this}/>;
}


Expand Down
4 changes: 2 additions & 2 deletions quokka-ui/src/components/DeviceStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {FlexibleXYPlot, HorizontalGridLines, LineMarkSeries, LineSeries, XAxis,
import React, {Component} from "react";
import Grid from "@material-ui/core/Grid";

class DeviceDashboard extends Component {
class DeviceStatus extends Component {

constructor(props) {
super(props);
Expand Down Expand Up @@ -166,5 +166,5 @@ class DeviceDashboard extends Component {
}
}

export default DeviceDashboard
export default DeviceStatus

170 changes: 170 additions & 0 deletions quokka-ui/src/components/WorkerStatus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
import {FlexibleXYPlot, HorizontalGridLines, LineMarkSeries, LineSeries, XAxis, YAxis} from 'react-vis'
import React, {Component} from "react";
import Grid from "@material-ui/core/Grid";

class WorkerStatus extends Component {

constructor(props) {
super(props);
this.state = {
workerId: props.workerId,
workerData: {worker_data: [], worker: {}},
dashboard: props.dashboard,
countdownValue: process.env.REACT_APP_REFRESH_RATE,
};

}

countdown() {
this.setState({countdownValue: this.state.countdownValue-1})
if (this.state.countdownValue === 0) {
this.fetchWorkerStatusData()
}
}

componentDidMount() {
this.fetchWorkerStatusData()
this.interval = setInterval(() => this.countdown(), 1000)
}

componentWillUnmount() {
clearInterval(this.interval)
}

fetchWorkerStatusData() {

const workerId = this.state.workerId;

let requestUrl = process.env.REACT_APP_QUOKKA_HOST + '/ui/worker/status?workerid='
+ workerId + '&datapoints=' + process.env.REACT_APP_NUM_DATAPOINTS

fetch(requestUrl)
.then(res => res.json())
.then((data) => {
console.log(data)
this.setState({workerData: data});
this.setState({countdownValue: process.env.REACT_APP_REFRESH_RATE})
})
.catch((e) => {
console.log(e)
this.setState({countdownValue: process.env.REACT_APP_REFRESH_RATE})
});

}

getTSData(measurement) {

let tsData = [];
let maxY = 0;
let yValue = 0;
const workerData = this.state.workerData.worker_data;

for (let i = 0; i < workerData.length; i++) {

if (measurement === "RSP_TIME") {
yValue = (workerData[i].response_time)/1000;
} else if (measurement === "AVAILABILITY") {
yValue = workerData[i].availability ? 100 : 0;
} else if (measurement === "CPU") {
yValue = workerData[i].cpu;
} else if (measurement === "MEMORY") {
yValue = workerData[i].memory;
}
else {
yValue = 0;
}

const tsDataItem = {x: new Date(workerData[i].timestamp), y: yValue};
tsData.push(tsDataItem);
if (tsDataItem.y > maxY) {
maxY = tsDataItem.y;
}
}

// console.log(tsData)
return {tsData: tsData, maxY: maxY};
}

render() {

let data = this.getTSData("RSP_TIME");
const tsRspTimeData = data.tsData;
const maxYRspTime = data.maxY;
data = this.getTSData("AVAILABILITY");
const tsAvailabilityData = data.tsData;
const maxYAvailability = data.maxY;
data = this.getTSData("CPU");
const tsCpuData = data.tsData;
const maxYCpu = data.maxY;
data = this.getTSData("MEMORY");
const tsMemoryData = data.tsData;
const maxYMemory = data.maxY;
return (
<Grid item style={{padding: '10px'}}>
<h6 align='right'>Time until refresh: {this.state.countdownValue} seconds</h6>
<Grid container direction="row">
<Grid item style={{width: '50%'}}>
<Grid item>
<h5>Response Time (establish connection)</h5>
<FlexibleXYPlot
height={300}
xType="time"
yDomain={[0,maxYRspTime+(maxYRspTime/5)]}>
<HorizontalGridLines />
<LineSeries
data={tsRspTimeData} />
<XAxis title="Time of Day"/>
<YAxis title="Response Time"/>
</FlexibleXYPlot>
</Grid>
<Grid item>
<h5>Availability</h5>
<FlexibleXYPlot
height={300}
xType="time"
yDomain={[0,maxYAvailability]}>
<HorizontalGridLines />
<LineMarkSeries
color="green"
data={tsAvailabilityData} />
<XAxis title="Time of Day"/>
<YAxis title="Availability"/>
</FlexibleXYPlot>
</Grid>
</Grid>
<Grid item style={{width: '50%'}}>
<Grid item>
<h5>CPU Utilization</h5>
<FlexibleXYPlot
height={300}
xType="time"
yDomain={[0,100]}>
<HorizontalGridLines />
<LineSeries
data={tsCpuData} />
<XAxis title="Time of Day"/>
<YAxis title="CPU"/>
</FlexibleXYPlot>
</Grid>
<Grid item>
<h5>Memory Utilization</h5>
<FlexibleXYPlot
height={300}
xType="time"
yDomain={[0,100]}>
<HorizontalGridLines />
<LineSeries
data={tsMemoryData} />
<XAxis title="Time of Day"/>
<YAxis title="Memory"/>
</FlexibleXYPlot>
</Grid>
</Grid>
</Grid>
</Grid>
);
}
}

export default WorkerStatus

14 changes: 7 additions & 7 deletions quokka-ui/src/components/Workers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Workers extends Component {
dashboard: props.dashboard,
countdownValue: process.env.REACT_APP_REFRESH_RATE,
openConfigDiffDialog: false,
deviceName: '',
workerId: '',
openTraceRouteDialog: false,
target: '',
traceRouteResults: {traceroute_output: ''},
Expand Down Expand Up @@ -90,8 +90,8 @@ class Workers extends Component {
clearInterval(this.interval)
}

renderWorkersStatus(deviceName) {
this.state.dashboard.setState({deviceName: deviceName, show: "workerstatus"})
renderWorkersStatus(workerId) {
this.state.dashboard.setState({workerId: workerId, show: "workerstatus"})
}

renderCapture(ip) {
Expand Down Expand Up @@ -166,21 +166,21 @@ class Workers extends Component {
actions={[
{
icon: 'dns',
tooltip: 'Display Workers Status',
tooltip: 'Display Worker Status',
onClick: (event, rowData) => {
this.renderWorkersStatus(rowData.name)
this.renderWorkersStatus(rowData.id)
}
},
{
icon: 'pageview',
tooltip: 'Capture packets for device',
tooltip: 'Capture packets for worker',
onClick: (event, rowData) => {
this.renderCapture(rowData.ip_address)
}
},
{
icon: AccountTreeTwoToneIcon,
tooltip: 'Trace-route to device',
tooltip: 'Trace-route to worker',
onClick: (event, rowData) => {
this.renderTraceRouteDialog(rowData.hostname)
}
Expand Down
8 changes: 8 additions & 0 deletions quokka/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
discovery_interval = max(10, int(interval))
else:
discovery_interval = 3600
interval = os.environ.get("WORKER_MONITOR_INTERVAL", default='60')
if interval.isnumeric():
worker_monitor_interval = max(10, int(interval))
else:
worker_monitor_interval = 60



from flask_sqlalchemy import SQLAlchemy
Expand Down Expand Up @@ -93,6 +99,7 @@
ThreadManager.start_discovery_thread(discovery_interval)
ThreadManager.start_host_thread(host_monitor_interval)
ThreadManager.start_summaries_thread()
# ThreadManager.start_worker_thread(worker_monitor_interval)

from quokka.controller.CaptureManager import CaptureManager
capture_manager = CaptureManager()
Expand All @@ -112,6 +119,7 @@ def shutdown():
ThreadManager.stop_host_thread()
ThreadManager.stop_service_thread()
ThreadManager.stop_summaries_thread()
# ThreadManager.stop_worker_thread()
ThreadManager.stop_device_threads()

log_console("\n---> all threads shut down, terminating.")
Expand Down
34 changes: 27 additions & 7 deletions quokka/controller/ThreadManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from quokka.controller.ServiceMonitorTask import ServiceMonitorTask
from quokka.controller.DiscoverTask import DiscoverTask
from quokka.controller.SummariesTask import SummariesTask
from quokka.controller.WorkerMonitorTask import WorkerMonitorTask
from quokka.controller.utils import log_console


Expand All @@ -26,8 +27,8 @@ class ThreadManager:
discovery_thread = None
summaries_task = None
summaries_thread = None

sniffing_processes = list()
worker_monitor_task = None
worker_monitor_thread = None

@staticmethod
def stop_device_threads():
Expand Down Expand Up @@ -165,6 +166,28 @@ def start_summaries_thread():
)
ThreadManager.summaries_thread.start()

@staticmethod
def stop_worker_thread():

log_console("--- ---> Shutting down worker monitoring thread")

if ThreadManager.worker_monitor_task and ThreadManager.worker_monitor_thread:
ThreadManager.worker_monitor_task.set_terminate()
ThreadManager.worker_monitor_thread.join()

ThreadManager.worker_monitor_task = None
ThreadManager.worker_monitor_thread = None

@staticmethod
def start_worker_thread(worker_monitor_interval=60):

ThreadManager.worker_monitor_task = WorkerMonitorTask()
ThreadManager.worker_monitor_thread = threading.Thread(
target=ThreadManager.worker_monitor_task.monitor,
args=(worker_monitor_interval,),
)
ThreadManager.worker_monitor_thread.start()

@staticmethod
def initiate_terminate_all_threads():

Expand All @@ -182,8 +205,5 @@ def initiate_terminate_all_threads():
ThreadManager.discovery_task.set_terminate()
if ThreadManager.summaries_task and ThreadManager.summaries_thread:
ThreadManager.summaries_task.set_terminate()

# Kill all outstanding sniffing processes, if any
for sniffing_process in ThreadManager.sniffing_processes:
if sniffing_process.is_alive():
sniffing_process.terminate()
if ThreadManager.worker_monitor_task and ThreadManager.worker_monitor_thread:
ThreadManager.worker_monitor_task.set_terminate()
Loading

0 comments on commit c461221

Please sign in to comment.