Browse Source

packet stats per node

main
gsd 5 months ago
parent
commit
b21d28e39c
  1. 7
      ui/src/app/app.module.ts
  2. 105
      ui/src/app/components/packet/NetworkStatus.component.ts
  3. 8
      ui/src/app/entities/PacketSignalDTO.ts

7
ui/src/app/app.module.ts

@ -23,6 +23,8 @@ import {MatDividerModule} from "@angular/material/divider";
import {MatCardModule} from "@angular/material/card"; import {MatCardModule} from "@angular/material/card";
import {MatSelectModule} from "@angular/material/select"; import {MatSelectModule} from "@angular/material/select";
import {NetworkStatusComponent} from "./components/packet/NetworkStatus.component"; import {NetworkStatusComponent} from "./components/packet/NetworkStatus.component";
import {MatRadioModule} from "@angular/material/radio";
import {DatePipe} from "@angular/common";
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -53,13 +55,14 @@ import {NetworkStatusComponent} from "./components/packet/NetworkStatus.componen
MatCardModule, MatCardModule,
NodeDtoSortPipe, NodeDtoSortPipe,
MatSelectModule, MatSelectModule,
NodeDtoSearchPipe NodeDtoSearchPipe,
MatRadioModule
], ],
providers: [{ providers: [{
provide: HTTP_INTERCEPTORS, provide: HTTP_INTERCEPTORS,
useClass: AuthInterceptor, useClass: AuthInterceptor,
multi: true multi: true
}], }, DatePipe],
bootstrap: [AppComponent] bootstrap: [AppComponent]
}) })
export class AppModule { } export class AppModule { }

105
ui/src/app/components/packet/NetworkStatus.component.ts

@ -6,15 +6,33 @@ import {numToColor} from "../../utils/Utils";
import {KeyValueMap} from "../../entities/KeyValueMap"; import {KeyValueMap} from "../../entities/KeyValueMap";
import {NodeDTO} from "../../entities/NodeDTO"; import {NodeDTO} from "../../entities/NodeDTO";
import {ActivatedRoute} from "@angular/router"; import {ActivatedRoute} from "@angular/router";
import {PacketSignalDTO} from "../../entities/PacketSignalDTO";
import {DatePipe} from "@angular/common";
@Component({ @Component({
selector: "app-network-status", selector: "app-network-status",
template: ` template: `
<div style="width: 80%; padding: 0 10%;"> <div style="width: 80%; padding: 0 10%;">
<div [ngSwitch]="MODE"> <div [ngSwitch]="MODE">
<h1 *ngSwitchCase="'ALL'">Статистика всей сети</h1> <h1 *ngSwitchCase="'ALL'">Статистика всей сети (желательно нажать ф5 если до этого смотрели другую ноду)</h1>
<h1 *ngSwitchCase="'NODE'">Статистика ноды {{getNumName(NUM)}} в сети</h1> <h1 *ngSwitchCase="'NODE'">Статистика ноды {{getNumName(NUM)}} в сети</h1>
</div> </div>
<div *ngIf="MODE == 'NODE'">
<div>
<mat-card>
<mat-card-actions>
<mat-radio-group [(ngModel)]="signalMode" (ngModelChange)="this.updateSignalGraph()" aria-label="Select an option">
<mat-radio-button value="day">За день</mat-radio-button>
<mat-radio-button value="week">За неделю</mat-radio-button>
<mat-radio-button value="month">За месяц</mat-radio-button>
</mat-radio-group>
</mat-card-actions>
<mat-card-content>
<canvas [id]="signalCanvasId">{{signalChart}}</canvas>
</mat-card-content>
</mat-card>
</div>
</div>
<div *ngFor="let type of graphs" > <div *ngFor="let type of graphs" >
<div *ngIf="MODE == type.requestMode" class="card-wrapper-450" style="padding-top: 12px"> <div *ngIf="MODE == type.requestMode" class="card-wrapper-450" style="padding-top: 12px">
<mat-card *ngFor="let p1 of type.cards"> <mat-card *ngFor="let p1 of type.cards">
@ -34,13 +52,21 @@ export class NetworkStatusComponent implements OnInit {
MODE: "ALL"|"NODE" = "ALL" MODE: "ALL"|"NODE" = "ALL"
NUM:number = 0; NUM:number = 0;
signalMode:"day"|"month"|"week"|string = "day"
signalCanvasId = "signalCanvasId";
signalChart = {
chart: null as unknown as Chart,
config: this.generateConfigTChart("Проходимость сигнала", true, "line") as any
};
nodesNames: KeyValueMap<NodeDTO> = {} nodesNames: KeyValueMap<NodeDTO> = {}
//общая статичтика по perPortNum за день\неделю\месяц / ?= //общая статичтика по perPortNum за день\неделю\месяц / ?=
//top кто насрал пакетами всего за день\неделю\месяц / ?=packetsSumNode=true //top кто насрал пакетами всего за день\неделю\месяц / ?=packetsSumNode=true
graphs:any[] = this.generateGraps(); graphs:any[] = this.generateGraps();
constructor(private http: HttpClient, constructor(private http: HttpClient,
private route: ActivatedRoute) {} private route: ActivatedRoute,
private datepipe: DatePipe) {}
getNumName(num:number) { getNumName(num:number) {
if (`${num}` in this.nodesNames) if (`${num}` in this.nodesNames)
@ -54,22 +80,23 @@ export class NetworkStatusComponent implements OnInit {
header: "Cтатистика пакетов в сети", header: "Cтатистика пакетов в сети",
type: 'perPortNum', type: 'perPortNum',
requestMode: "ALL", requestMode: "ALL",
endpoint:"api/packet/stats",
cards:[{ cards:[{
chart: Chart, chart: null as unknown as Chart,
canvasId: "DayPerPB", canvasId: "DayPerPB",
params: "?=", params: "?=",
before: new Date().getTime()/1000, before: new Date().getTime()/1000,
after: (new Date().getTime()/1000) - this.DAY, after: (new Date().getTime()/1000) - this.DAY,
config: this.generateConfigTChart("Cтатистика по пакетам в сети за день") config: this.generateConfigTChart("Cтатистика по пакетам в сети за день")
},{ },{
chart: Chart, chart: null as unknown as Chart,
canvasId: "WeekPerPB", canvasId: "WeekPerPB",
params: "?=", params: "?=",
before: new Date().getTime()/1000, before: new Date().getTime()/1000,
after: (new Date().getTime()/1000) - this.WEEK, after: (new Date().getTime()/1000) - this.WEEK,
config: this.generateConfigTChart("Cтатистика по пакетам в сети за неделю") config: this.generateConfigTChart("Cтатистика по пакетам в сети за неделю")
},{ },{
chart: Chart, chart: null as unknown as Chart,
canvasId: "MonthPerPB", canvasId: "MonthPerPB",
params: "?=", params: "?=",
before: new Date().getTime()/1000, before: new Date().getTime()/1000,
@ -81,22 +108,23 @@ export class NetworkStatusComponent implements OnInit {
header: "Общая статистика пакетов в сети", header: "Общая статистика пакетов в сети",
type: 'perSumNode', type: 'perSumNode',
requestMode: "ALL", requestMode: "ALL",
endpoint:"api/packet/stats",
cards:[{ cards:[{
chart: Chart, chart: null as unknown as Chart,
canvasId: "DaySumPB", canvasId: "DaySumPB",
params: "?packetsSumNode=true", params: "?packetsSumNode=true",
before: new Date().getTime()/1000, before: new Date().getTime()/1000,
after: (new Date().getTime()/1000) - this.DAY, after: (new Date().getTime()/1000) - this.DAY,
config: this.generateConfigTChart("Количество пакетов от пользоватей за день", false) config: this.generateConfigTChart("Количество пакетов от пользоватей за день", false)
},{ },{
chart: Chart, chart: null as unknown as Chart,
canvasId: "WeekSumPB", canvasId: "WeekSumPB",
params: "?packetsSumNode=true", params: "?packetsSumNode=true",
before: new Date().getTime()/1000, before: new Date().getTime()/1000,
after: (new Date().getTime()/1000) - this.WEEK, after: (new Date().getTime()/1000) - this.WEEK,
config: this.generateConfigTChart("Количество пакетов от пользоватей за неделю", false) config: this.generateConfigTChart("Количество пакетов от пользоватей за неделю", false)
},{ },{
chart: Chart, chart: null as unknown as Chart,
canvasId: "MonthSumPB", canvasId: "MonthSumPB",
params: "?packetsSumNode=true", params: "?packetsSumNode=true",
before: new Date().getTime()/1000, before: new Date().getTime()/1000,
@ -107,22 +135,23 @@ export class NetworkStatusComponent implements OnInit {
header: "Cтатистика пакетов в сети", header: "Cтатистика пакетов в сети",
type: 'packetsPerNode', type: 'packetsPerNode',
requestMode: "NODE", requestMode: "NODE",
endpoint:"api/packet/stats",
cards:[{ cards:[{
chart: Chart, chart: null as unknown as Chart,
canvasId: "DayPerNodePB", canvasId: "DayPerNodePB",
params: "?packetsPerNode=true", params: "?packetsPerNode=true",
before: new Date().getTime()/1000, before: new Date().getTime()/1000,
after: (new Date().getTime()/1000) - this.DAY, after: (new Date().getTime()/1000) - this.DAY,
config: this.generateConfigTChart("Cтатистика по пакетам в сети за день") config: this.generateConfigTChart("Cтатистика по пакетам в сети за день")
},{ },{
chart: Chart, chart: null as unknown as Chart,
canvasId: "WeekPerNodePB", canvasId: "WeekPerNodePB",
params: "?packetsPerNode=true", params: "?packetsPerNode=true",
before: new Date().getTime()/1000, before: new Date().getTime()/1000,
after: (new Date().getTime()/1000) - this.WEEK, after: (new Date().getTime()/1000) - this.WEEK,
config: this.generateConfigTChart("Cтатистика по пакетам в сети за неделю") config: this.generateConfigTChart("Cтатистика по пакетам в сети за неделю")
},{ },{
chart: Chart, chart: null as unknown as Chart,
canvasId: "MonthPerNodePB", canvasId: "MonthPerNodePB",
params: "?packetsPerNode=true", params: "?packetsPerNode=true",
before: new Date().getTime()/1000, before: new Date().getTime()/1000,
@ -133,10 +162,13 @@ export class NetworkStatusComponent implements OnInit {
] ]
} }
generateConfigTChart(name: string, legend: boolean = true) { generateConfigTChart(name: string, legend: boolean = true, type: string = "pie") {
return { return {
type: 'pie', type: type,
data: {}, data: {
labels: [] as any[],
datasets: [] as any[]
},
options: { options: {
responsive: true, responsive: true,
plugins: { plugins: {
@ -157,7 +189,6 @@ export class NetworkStatusComponent implements OnInit {
this.route.params.subscribe( this.route.params.subscribe(
(params) => { (params) => {
const num: number = Number.parseInt(params["num"]); const num: number = Number.parseInt(params["num"]);
console.log(num);
switch (num) { switch (num) {
case 0: { case 0: {
this.MODE = "ALL"; this.MODE = "ALL";
@ -190,6 +221,7 @@ export class NetworkStatusComponent implements OnInit {
() => { () => {
this.graphs = this.generateGraps(); this.graphs = this.generateGraps();
this.updateGraphs(); this.updateGraphs();
this.updateSignalGraph();
} }
) )
break; break;
@ -198,12 +230,48 @@ export class NetworkStatusComponent implements OnInit {
}) })
} }
updateSignalGraph() {
const before = new Date().getTime() / 1000;
let after;
switch (this.signalMode) {
case "day": {
after = (new Date().getTime()/1000) - this.DAY;
break;
}
case "week": {
after = (new Date().getTime()/1000) - this.WEEK;
break;
}
case "month": {
after = (new Date().getTime()/1000) - this.MONTH;
break;
}
}
this.http.get(`api/packet/signal?before=${before}&after=${after}&nums=${this.NUM}`).subscribe(
(obj) => {
this.signalChart.config.data = {labels: [], datasets:[{label: "snr",data:[]},{label: "rssi",data:[]}]};
(obj as PacketSignalDTO[]).forEach(
(packet: PacketSignalDTO) => {
this.signalChart.config.data.labels.push(this.datepipe.transform(packet.ts*1000, 'HH:mm dd.MM.yyyy'))
this.signalChart.config.data.datasets[0].data.push(packet.rx_snr)
this.signalChart.config.data.datasets[1].data.push(packet.rx_rssi)
return;
}
)
if (this.signalChart.chart != null)
this.signalChart.chart.destroy()
this.signalChart.chart = new Chart(this.signalCanvasId, this.signalChart.config)
}
)
}
updateGraphs() { updateGraphs() {
this.graphs.forEach( this.graphs.forEach(
(graph) => { (graph) => {
graph.cards.forEach((settings:any) => { graph.cards.forEach((settings:any) => {
if (this.MODE != graph.requestMode) return; if (this.MODE != graph.requestMode) return;
this.http.get(`api/packet/stats${settings.params}&before=${settings.before}&after=${settings.after}&${this.NUM == 0?'':('&nums='+this.NUM)}`) this.http.get(`${graph.endpoint}${settings.params}&before=${settings.before}&after=${settings.after}&${this.NUM == 0?'':('&nums='+this.NUM)}`)
.subscribe((data) => { .subscribe((data) => {
settings.config.data = { settings.config.data = {
labels: [], labels: [],
@ -239,9 +307,8 @@ export class NetworkStatusComponent implements OnInit {
} }
} }
) )
//if (settings.chart) if (settings.chart)
// settings.chart.destroy() settings.chart.destroy()
settings.chart = new Chart(settings.canvasId, settings.config) settings.chart = new Chart(settings.canvasId, settings.config)
}) })
}) })

8
ui/src/app/entities/PacketSignalDTO.ts

@ -0,0 +1,8 @@
export interface PacketSignalDTO {
from: number,
rx_snr: number,
rx_rssi: number,
ts: number,
hop_start: number,
hop_limit: number
}
Loading…
Cancel
Save