[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] [metrics-db/master] Pre-calculate total advertised bandwidth.
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Tue, 21 Sep 2010 15:35:26 +0200
Subject: Pre-calculate total advertised bandwidth.
Commit: bc52c5256260a931ee6e2a0d0e9f5e0423adbb64
---
db/tordir.sql | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/db/tordir.sql b/db/tordir.sql
index 40b527e..504fd96 100644
--- a/db/tordir.sql
+++ b/db/tordir.sql
@@ -134,13 +134,12 @@ CREATE TABLE relay_versions (
-- TABLE total_bandwidth
-- Contains information for the whole network's total bandwidth which is
-- used in the bandwidth graphs.
--- TODO We should add bwadvertised as MIN(bwavg, bwobserved) which is used
--- by 0.2.0.x clients for path selection.
CREATE TABLE total_bandwidth (
date TIMESTAMP WITHOUT TIME ZONE NOT NULL,
bwavg BIGINT NOT NULL,
bwburst BIGINT NOT NULL,
bwobserved BIGINT NOT NULL,
+ bwadvertised BIGINT NOT NULL,
CONSTRAINT total_bandwidth_pkey PRIMARY KEY(date)
);
@@ -400,13 +399,15 @@ CREATE OR REPLACE FUNCTION refresh_total_bandwidth() RETURNS INTEGER AS $$
WHERE date IN (SELECT * FROM updates);
INSERT INTO total_bandwidth
- (bwavg, bwburst, bwobserved, date)
+ (bwavg, bwburst, bwobserved, bwadvertised, date)
SELECT (SUM(bandwidthavg)
/ relay_statuses_per_day.count)::BIGINT AS bwavg,
(SUM(bandwidthburst)
/ relay_statuses_per_day.count)::BIGINT AS bwburst,
(SUM(bandwidthobserved)
/ relay_statuses_per_day.count)::BIGINT AS bwobserved,
+ (SUM(LEAST(bandwidthavg, bandwidthobserved))
+ / relay_statuses_per_day.count)::BIGINT AS bwadvertised,
DATE(validafter)
FROM descriptor RIGHT JOIN statusentry
ON descriptor.descriptor = statusentry.descriptor
--
1.7.1