Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/shadowbox/server/manager_metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
this.prunePrometheusCache();

const [
bandwidth,
bandwidthRange,
dataTransferredByLocation,
tunnelTimeByLocation,
Expand All @@ -124,9 +123,6 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
dataTransferredByAccessKeyRange,
tunnelTimeByAccessKeyRange,
] = await Promise.all([
this.cachedPrometheusClient.query(
`sum(rate(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[${PROMETHEUS_RANGE_QUERY_STEP_SECONDS}s]))`
),
this.cachedPrometheusClient.queryRange(
`sum(rate(shadowsocks_data_bytes_per_location{dir=~"c<p|p>t"}[${PROMETHEUS_RANGE_QUERY_STEP_SECONDS}s]))`,
start,
Expand Down Expand Up @@ -168,13 +164,15 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
},
locations: [],
};
for (const result of bandwidth.result) {
if (result.value) {
serverMetrics.bandwidth.current.data.bytes = parseFloat(result.value[1]);
serverMetrics.bandwidth.current.timestamp = result.value[0];
}
break; // There should only be one result.

const bandwidthRangeValues = bandwidthRange.result[0].values ?? [];
const currentBandwidth = bandwidthRangeValues[bandwidthRangeValues.length - 1];

if (currentBandwidth) {
serverMetrics.bandwidth.current.data.bytes = parseFloat(currentBandwidth[1]);
serverMetrics.bandwidth.current.timestamp = currentBandwidth[0];
}

for (const result of bandwidthRange.result) {
const peakDataTransferred = findPeak(result.values ?? []);
if (peakDataTransferred !== null) {
Expand Down
Loading