This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
318 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
modules/portmaster/src/app/pages/app-view/app-insights/app-insights.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="grid grid-cols-2 gap-2"> | ||
<app-dashboard-widget label="Connections" style="min-height: 400px;"> | ||
<sfng-netquery-line-chart [data]="connectionChart"></sfng-netquery-line-chart> | ||
</app-dashboard-widget> | ||
|
||
<app-dashboard-widget label="Data Usage" beta="true" style="min-height: 400px;"> | ||
<sfng-netquery-line-chart [config]="bwChartConfig" [data]="bandwidthChart"></sfng-netquery-line-chart> | ||
</app-dashboard-widget> | ||
|
||
<app-dashboard-widget label="Countries" beta="true" style="min-height: 400px"> | ||
<sfng-netquery-circular-bar-chart class="block w-full h-full" [data]="countryData" [config]="countryBarConfig"></sfng-netquery-circular-bar-chart> | ||
</app-dashboard-widget> | ||
</div> |
96 changes: 96 additions & 0 deletions
96
modules/portmaster/src/app/pages/app-view/app-insights/app-insights.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, Input, OnInit, inject } from '@angular/core'; | ||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; | ||
import { AppProfile, BandwidthChartResult, ChartResult, Netquery } from '@safing/portmaster-api'; | ||
import { repeat } from 'rxjs'; | ||
import { CircularBarChartConfig, splitQueryResult } from 'src/app/shared/netquery/circular-bar-chart/circular-bar-chart.component'; | ||
import { DefaultBandwidthChartConfig } from 'src/app/shared/netquery/line-chart/line-chart'; | ||
|
||
interface CountryBarData { | ||
series: 'country'; | ||
value: number; | ||
country: string; | ||
} | ||
|
||
@Component({ | ||
selector: 'app-app-insights', | ||
templateUrl: './app-insights.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class AppInsightsComponent implements OnInit { | ||
private readonly netquery = inject(Netquery); | ||
private readonly destroyRef = inject(DestroyRef); | ||
private readonly cdr = inject(ChangeDetectorRef); | ||
|
||
@Input() | ||
profile!: AppProfile; | ||
|
||
connectionChart: ChartResult[] = []; | ||
|
||
bandwidthChart: BandwidthChartResult<any>[] = []; | ||
|
||
bwChartConfig = DefaultBandwidthChartConfig; | ||
|
||
countryData: CountryBarData[] = []; | ||
|
||
readonly countryBarConfig: CircularBarChartConfig<CountryBarData> = { | ||
stack: 'country', | ||
seriesKey: 'series', | ||
value: 'value', | ||
ticks: 3, | ||
colorAsClass: true, | ||
series: { | ||
'count': { | ||
color: 'text-green-300 text-opacity-50', | ||
}, | ||
}, | ||
} | ||
|
||
ngOnInit() { | ||
const key = `${this.profile.Source}/${this.profile.ID}` | ||
|
||
this.netquery.batch({ | ||
countryData: { | ||
select: [ | ||
'country', | ||
{ $count: { field: '*', as: 'count' } }, | ||
], | ||
query: { | ||
internal: { $eq: false }, | ||
country: { $ne: '' } | ||
}, | ||
groupBy: ['country'] | ||
} | ||
}) | ||
.pipe( | ||
repeat({ delay: 10000 }), | ||
takeUntilDestroyed(this.destroyRef) | ||
) | ||
.subscribe(result => { | ||
this.countryData = splitQueryResult(result.countryData, ['count']) as CountryBarData[]; | ||
console.log(this.countryData) | ||
this.cdr.markForCheck(); | ||
}) | ||
|
||
this.netquery.activeConnectionChart({ profile: key }) | ||
.pipe( | ||
repeat({ delay: 10000 }), | ||
takeUntilDestroyed(this.destroyRef) | ||
) | ||
.subscribe(data => { | ||
this.connectionChart = data; | ||
this.cdr.markForCheck(); | ||
}) | ||
|
||
this.netquery.bandwidthChart({ profile: key }, undefined, 60) | ||
.pipe( | ||
repeat({ delay: 10000 }), | ||
takeUntilDestroyed(this.destroyRef) | ||
) | ||
.subscribe(data => { | ||
this.bandwidthChart = data; | ||
this.cdr.markForCheck(); | ||
}) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.