From 67201b3ddb61c81fe06b1439088910e832ec3b69 Mon Sep 17 00:00:00 2001 From: fortuna Date: Wed, 31 Oct 2018 11:46:51 -0400 Subject: [PATCH 1/2] Fix reported metrics --- src/shadowbox/server/manager_metrics.ts | 3 +++ src/shadowbox/server/shared_metrics.ts | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/shadowbox/server/manager_metrics.ts b/src/shadowbox/server/manager_metrics.ts index c34c9e34..988e2d4f 100644 --- a/src/shadowbox/server/manager_metrics.ts +++ b/src/shadowbox/server/manager_metrics.ts @@ -28,6 +28,9 @@ export class PrometheusManagerMetrics implements ManagerMetrics { async get30DayByteTransfer(): Promise { // TODO(fortuna): Consider pre-computing this to save server's CPU. + // We measure only traffic leaving the server, since that's what DigitalOcean charges + // TODO: Display all directions to admin + // TODO: Remove >p< once ss-libev support is gone. const result = await this.prometheusClient.query( 'sum(increase(shadowsocks_data_bytes{dir=~"ct|>p<"}[30d])) by (access_key)'); const usage = {} as {[userId: string]: number}; diff --git a/src/shadowbox/server/shared_metrics.ts b/src/shadowbox/server/shared_metrics.ts index c41f5e28..732852c6 100644 --- a/src/shadowbox/server/shared_metrics.ts +++ b/src/shadowbox/server/shared_metrics.ts @@ -74,8 +74,10 @@ export class PrometheusUsageMetrics implements UsageMetrics { async getUsage(): Promise { const timeDeltaSecs = Math.round((Date.now() - this.resetTimeMs) / 1000); + // We mesure the traffic to and from the target, since that's what we are protecting. + // TODO: remove >p< once the ss-libev support is gone. const result = - await this.prometheusClient.query(`sum(increase(shadowsocks_data_bytes{dir=">p<"}[${ + await this.prometheusClient.query(`sum(increase(shadowsocks_data_bytes{dir=~">p<|p>t|p Date: Wed, 31 Oct 2018 14:54:56 -0400 Subject: [PATCH 2/2] Address comments --- src/shadowbox/server/manager_metrics.ts | 2 +- src/shadowbox/server/shared_metrics.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/shadowbox/server/manager_metrics.ts b/src/shadowbox/server/manager_metrics.ts index 988e2d4f..8995b68d 100644 --- a/src/shadowbox/server/manager_metrics.ts +++ b/src/shadowbox/server/manager_metrics.ts @@ -28,7 +28,7 @@ export class PrometheusManagerMetrics implements ManagerMetrics { async get30DayByteTransfer(): Promise { // TODO(fortuna): Consider pre-computing this to save server's CPU. - // We measure only traffic leaving the server, since that's what DigitalOcean charges + // We measure only traffic leaving the server, since that's what DigitalOcean charges. // TODO: Display all directions to admin // TODO: Remove >p< once ss-libev support is gone. const result = await this.prometheusClient.query( diff --git a/src/shadowbox/server/shared_metrics.ts b/src/shadowbox/server/shared_metrics.ts index 732852c6..15ebd995 100644 --- a/src/shadowbox/server/shared_metrics.ts +++ b/src/shadowbox/server/shared_metrics.ts @@ -74,10 +74,10 @@ export class PrometheusUsageMetrics implements UsageMetrics { async getUsage(): Promise { const timeDeltaSecs = Math.round((Date.now() - this.resetTimeMs) / 1000); - // We mesure the traffic to and from the target, since that's what we are protecting. + // We measure the traffic to and from the target, since that's what we are protecting. // TODO: remove >p< once the ss-libev support is gone. - const result = - await this.prometheusClient.query(`sum(increase(shadowsocks_data_bytes{dir=~">p<|p>t|pp<|p>t|p