Skip to content

Commit

Permalink
Add total data transferred a separate top-level metric so we don't ha…
Browse files Browse the repository at this point in the history
…ve to calculate it client-side.
  • Loading branch information
sbruens committed Feb 12, 2025
1 parent 8f13b90 commit 535d5fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/shadowbox/server/manager_metrics.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ describe('PrometheusManagerMetrics', () => {
"tunnelTime": {
"seconds": 1000
},
"dataTransferred": {
"bytes": 1000
},
"bandwidth": {
"current": {
"data": {
Expand Down Expand Up @@ -334,6 +337,9 @@ describe('PrometheusManagerMetrics', () => {
"tunnelTime": {
"seconds": 1000
},
"dataTransferred": {
"bytes": 1000
},
"bandwidth": {
"current": {
"data": {
Expand Down
6 changes: 5 additions & 1 deletion src/shadowbox/server/manager_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ interface BandwidthStats {

interface ServerMetricsServerEntry {
tunnelTime: Duration;
dataTransferred: Data;
bandwidth: BandwidthStats;
locations: ServerMetricsLocationEntry[];
}
Expand Down Expand Up @@ -158,6 +159,7 @@ export class PrometheusManagerMetrics implements ManagerMetrics {

const serverMetrics: ServerMetricsServerEntry = {
tunnelTime: {seconds: 0},
dataTransferred: {bytes: 0},
bandwidth: {
current: {data: {bytes: 0}, timestamp: null},
peak: {data: {bytes: 0}, timestamp: null},
Expand Down Expand Up @@ -192,7 +194,9 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
}
for (const result of dataTransferredByLocation.result) {
const entry = getServerMetricsLocationEntry(locationMap, result.metric);
entry.dataTransferred.bytes = result.value ? parseFloat(result.value[1]) : 0;
const bytes = result.value ? parseFloat(result.value[1]) : 0;
entry.dataTransferred.bytes = bytes;
serverMetrics.dataTransferred.bytes += bytes;
}
serverMetrics.locations = Array.from(locationMap.values());

Expand Down

0 comments on commit 535d5fa

Please sign in to comment.