Repository navigation
Expand file tree
/
Copy pathquery.sql
More file actions
95 lines (83 loc) · 2.14 KB
/
Copy pathquery.sql
File metadata and controls
95 lines (83 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
-- name: GetZoneStatsData :many
SELECT zc.date, z.name, zc.ip_version, count_active, count_registered, netspeed_active
FROM zone_server_counts zc
INNER JOIN zones z
ON(zc.zone_id=z.id)
WHERE date IN (SELECT max(date) from zone_server_counts)
ORDER BY name;
-- name: GetServerNetspeed :one
select netspeed from servers where ip = $1;
-- name: GetZoneStatsV2 :many
SELECT
z.name as zone_name,
CAST(SUM(
CASE WHEN deletion_on IS NULL AND score_raw > 10
THEN netspeed
ELSE 0
END
) AS bigint) AS netspeed_active
FROM
servers s
INNER JOIN server_zones sz ON (sz.server_id = s.id)
INNER JOIN zones z ON (z.id = sz.zone_id)
INNER JOIN (
select zone_id, s.ip_version
from server_zones sz
inner join servers s on (s.id=sz.server_id)
where s.ip=$1
) as srvz on (srvz.zone_id=z.id AND srvz.ip_version=s.ip_version)
WHERE
(deletion_on IS NULL OR deletion_on > NOW())
AND in_pool = 1
AND netspeed > 0
GROUP BY z.name;
-- name: GetServerByID :one
select * from servers
where
id = $1;
-- name: GetServerByIP :one
select * from servers
where
ip = sqlc.arg(ip);
-- name: GetMonitorByNameAndIPVersion :one
select * from monitors
where
tls_name like sqlc.arg('tls_name') AND
(ip_version = sqlc.arg('ip_version') OR (type = 'score' AND ip_version IS NULL)) AND
is_current = true
order by id
limit 1;
-- name: GetMonitorsByID :many
select * from monitors
where id = ANY(sqlc.arg('MonitorIDs')::bigint[]);
-- name: GetServerScores :many
select
m.id, m.hostname, m.tls_name, m.location, m.type,
ss.score_raw, ss.score_ts, ss.status
from server_scores ss
inner join monitors m
on (m.id=ss.monitor_id)
where
server_id = $1 AND
monitor_id = ANY(sqlc.arg('MonitorIDs')::bigint[]);
-- name: GetServerLogScores :many
select * from log_scores
where
server_id = $1
order by ts desc
limit $2;
-- name: GetServerLogScoresByMonitorID :many
select * from log_scores
where
server_id = $1 AND
monitor_id = $2
order by ts desc
limit $3;
-- name: GetZoneByName :one
select * from zones
where
name = sqlc.arg(name);
-- name: GetZoneCounts :many
select * from zone_server_counts
where zone_id = $1
order by date;