Merge pull request #296 from Jigsaw-Code/fortuna-fix

Fix reported metrics
This commit is contained in:
Vinicius Fortuna 2018-10-31 16:51:42 -04:00 • committed by GitHub
commit 40ba2ef12d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -28,6 +28,9 @@ export class PrometheusManagerMetrics implements ManagerMetrics {
async get30DayByteTransfer(): Promise<DataUsageByUser> {
// 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=~"c<p|p>t|>p<"}[30d])) by (access_key)');
const usage = {} as {[userId: string]: number};

View file

@ -74,8 +74,10 @@ export class PrometheusUsageMetrics implements UsageMetrics {
async getUsage(): Promise<KeyUsage[]> {
const timeDeltaSecs = Math.round((Date.now() - this.resetTimeMs) / 1000);
const result =
await this.prometheusClient.query(`sum(increase(shadowsocks_data_bytes{dir=">p<"}[${
// 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|p<t"}[${
timeDeltaSecs}s])) by (location, access_key)`);
const usage = [] as KeyUsage[];
for (const entry of result.result) {