litestack 0.4.1 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +3 -0
- data/BENCHMARKS.md +23 -7
- data/CHANGELOG.md +35 -0
- data/Gemfile +1 -7
- data/README.md +124 -6
- data/ROADMAP.md +45 -0
- data/Rakefile +3 -1
- data/WHYLITESTACK.md +1 -1
- data/assets/litecache_metrics.png +0 -0
- data/assets/litedb_metrics.png +0 -0
- data/assets/litemetric_logo_teal.png +0 -0
- data/assets/litesearch_logo_teal.png +0 -0
- data/bench/bench.rb +17 -10
- data/bench/bench_cache_rails.rb +45 -14
- data/bench/bench_cache_raw.rb +44 -28
- data/bench/bench_jobs_rails.rb +18 -12
- data/bench/bench_jobs_raw.rb +17 -10
- data/bench/bench_queue.rb +4 -6
- data/bench/rails_job.rb +5 -7
- data/bench/skjob.rb +4 -4
- data/bench/uljob.rb +6 -6
- data/bin/liteboard +2 -1
- data/lib/action_cable/subscription_adapter/litecable.rb +5 -8
- data/lib/active_job/queue_adapters/litejob_adapter.rb +6 -8
- data/lib/active_record/connection_adapters/litedb_adapter.rb +72 -84
- data/lib/active_support/cache/litecache.rb +61 -41
- data/lib/generators/litestack/install/install_generator.rb +3 -3
- data/lib/generators/litestack/install/templates/cable.yml +0 -3
- data/lib/generators/litestack/install/templates/database.yml +7 -1
- data/lib/litestack/liteboard/liteboard.rb +269 -149
- data/lib/litestack/litecable.rb +41 -37
- data/lib/litestack/litecable.sql.yml +22 -11
- data/lib/litestack/litecache.rb +118 -93
- data/lib/litestack/litecache.sql.yml +83 -22
- data/lib/litestack/litecache.yml +1 -1
- data/lib/litestack/litedb.rb +35 -40
- data/lib/litestack/litejob.rb +30 -29
- data/lib/litestack/litejobqueue.rb +63 -65
- data/lib/litestack/litemetric.rb +80 -92
- data/lib/litestack/litemetric.sql.yml +244 -234
- data/lib/litestack/litemetric_collector.sql.yml +38 -41
- data/lib/litestack/litequeue.rb +39 -41
- data/lib/litestack/litequeue.sql.yml +39 -31
- data/lib/litestack/litescheduler.rb +24 -18
- data/lib/litestack/litesearch/index.rb +93 -63
- data/lib/litestack/litesearch/model.rb +66 -65
- data/lib/litestack/litesearch/schema.rb +53 -56
- data/lib/litestack/litesearch/schema_adapters/backed_adapter.rb +46 -50
- data/lib/litestack/litesearch/schema_adapters/basic_adapter.rb +44 -35
- data/lib/litestack/litesearch/schema_adapters/contentless_adapter.rb +3 -6
- data/lib/litestack/litesearch/schema_adapters/standalone_adapter.rb +7 -9
- data/lib/litestack/litesearch/schema_adapters.rb +4 -9
- data/lib/litestack/litesearch.rb +6 -9
- data/lib/litestack/litesupport.rb +78 -87
- data/lib/litestack/railtie.rb +1 -1
- data/lib/litestack/version.rb +2 -2
- data/lib/litestack.rb +6 -4
- data/lib/railties/rails/commands/dbconsole.rb +16 -20
- data/lib/sequel/adapters/litedb.rb +16 -21
- data/lib/sequel/adapters/shared/litedb.rb +168 -168
- data/scripts/build_metrics.rb +91 -0
- data/scripts/test_cable.rb +30 -0
- data/scripts/test_job_retry.rb +33 -0
- data/scripts/test_metrics.rb +60 -0
- data/template.rb +2 -2
- metadata +115 -7
@@ -5,335 +5,345 @@ schema:
|
|
5
5
|
name TEXT PRIMARY KEY NOT NULL,
|
6
6
|
state TEXT,
|
7
7
|
updated_at INTEGER
|
8
|
-
);
|
9
|
-
|
8
|
+
);
|
9
|
+
|
10
10
|
create_events: >
|
11
11
|
CREATE TABLE IF NOT EXISTS events(
|
12
|
-
topic TEXT NOT NULL references topics(name) ON DELETE CASCADE,
|
13
|
-
name TEXT DEFAULT('___') NOT NULL ON CONFLICT REPLACE,
|
14
|
-
key TEXT DEFAULT('___') NOT NULL ON CONFLICT REPLACE,
|
15
|
-
count INTEGER DEFAULT(0) NOT NULL ON CONFLICT REPLACE,
|
16
|
-
value REAL,
|
17
|
-
minimum REAL,
|
18
|
-
maximum REAL,
|
19
|
-
created_at INTEGER DEFAULT((unixepoch()/300*300)) NOT NULL,
|
20
|
-
resolution TEXT DEFAULT('minute') NOT NULL,
|
12
|
+
topic TEXT NOT NULL references topics(name) ON DELETE CASCADE,
|
13
|
+
name TEXT DEFAULT('___') NOT NULL ON CONFLICT REPLACE,
|
14
|
+
key TEXT DEFAULT('___') NOT NULL ON CONFLICT REPLACE,
|
15
|
+
count INTEGER DEFAULT(0) NOT NULL ON CONFLICT REPLACE,
|
16
|
+
value REAL,
|
17
|
+
minimum REAL,
|
18
|
+
maximum REAL,
|
19
|
+
created_at INTEGER DEFAULT((unixepoch()/300*300)) NOT NULL,
|
20
|
+
resolution TEXT DEFAULT('minute') NOT NULL,
|
21
21
|
PRIMARY KEY(resolution, created_at, topic, name, key)
|
22
|
-
)
|
22
|
+
);
|
23
23
|
|
24
|
-
create_topic_index_on_events:
|
25
|
-
|
24
|
+
create_topic_index_on_events: >
|
25
|
+
CREATE INDEX events_topic_index ON events (resolution, created_at, topic) WHERE name = '___';
|
26
|
+
create_event_index_on_events: >
|
27
|
+
CREATE INDEX events_event_index ON events (resolution, created_at , topic, name) WHERE key = '___';
|
26
28
|
|
27
29
|
create_events_search: >
|
28
30
|
CREATE VIRTUAL TABLE IF NOT EXISTS events_search USING fts5 (
|
29
|
-
topic,
|
30
|
-
name,
|
31
|
-
key,
|
32
|
-
resolution,
|
33
|
-
content=events,
|
31
|
+
topic,
|
32
|
+
name,
|
33
|
+
key,
|
34
|
+
resolution,
|
35
|
+
content=events,
|
34
36
|
tokeniz="trigram"
|
35
|
-
)
|
36
|
-
|
37
|
+
);
|
38
|
+
|
37
39
|
create_events_insert_trigger: >
|
38
|
-
CREATE TRIGGER events_insert AFTER INSERT ON events
|
40
|
+
CREATE TRIGGER events_insert AFTER INSERT ON events
|
39
41
|
BEGIN
|
40
|
-
INSERT INTO
|
41
|
-
events_search(rowid, topic, name, key, resolution)
|
42
|
+
INSERT INTO
|
43
|
+
events_search(rowid, topic, name, key, resolution)
|
42
44
|
VALUES
|
43
45
|
(new.rowid, new.topic, new.name, new.key, new.resolution);
|
44
46
|
END;
|
45
|
-
|
47
|
+
|
46
48
|
create_events_delete_trigger: >
|
47
|
-
CREATE TRIGGER events_delete AFTER DELETE ON events
|
49
|
+
CREATE TRIGGER events_delete AFTER DELETE ON events
|
48
50
|
BEGIN
|
49
51
|
INSERT INTO
|
50
|
-
events_search(events_search, rowid, topic, name, key, resolution)
|
52
|
+
events_search(events_search, rowid, topic, name, key, resolution)
|
51
53
|
VALUES
|
52
|
-
('delete', old.rowid, old.topic, old.name, old.key, old.resolution);
|
54
|
+
('delete', old.rowid, old.topic, old.name, old.key, old.resolution);
|
53
55
|
END;
|
54
56
|
|
55
57
|
create_events_update_trigger: >
|
56
|
-
CREATE TRIGGER events_update AFTER UPDATE ON events
|
58
|
+
CREATE TRIGGER events_update AFTER UPDATE ON events
|
57
59
|
BEGIN
|
58
60
|
INSERT INTO
|
59
|
-
events_search(events_search, rowid, topic, name, key, resolution)
|
61
|
+
events_search(events_search, rowid, topic, name, key, resolution)
|
60
62
|
VALUES
|
61
|
-
('delete', old.rowid, old.topic, old.name, old.key, old.resolution);
|
62
|
-
INSERT INTO
|
63
|
-
events_search(rowid, topic, name, key, resolution)
|
63
|
+
('delete', old.rowid, old.topic, old.name, old.key, old.resolution);
|
64
|
+
INSERT INTO
|
65
|
+
events_search(rowid, topic, name, key, resolution)
|
64
66
|
VALUES
|
65
67
|
(new.rowid, new.topic, new.name, new.key, new.resolution);
|
66
68
|
END;
|
67
69
|
|
68
70
|
rebuild_index: >
|
69
71
|
INSERT INTO events_search(events_search) VALUES ('rebuild');
|
70
|
-
|
71
|
-
|
72
|
-
|
73
72
|
|
74
73
|
stmts:
|
75
|
-
|
76
74
|
register_topic: >
|
77
|
-
INSERT INTO topics (name, updated_at) VALUES (?, unixepoch())
|
78
|
-
ON CONFLICT DO
|
79
|
-
|
80
|
-
|
75
|
+
INSERT INTO topics (name, updated_at) VALUES (?, unixepoch())
|
76
|
+
ON CONFLICT DO UPDATE
|
77
|
+
SET updated_at = unixepoch();
|
78
|
+
|
81
79
|
capture_state: >
|
82
|
-
UPDATE topics
|
83
|
-
SET state = ?2, updated_at = unixepoch()
|
84
|
-
WHERE name = ?1
|
80
|
+
UPDATE topics
|
81
|
+
SET state = ?2, updated_at = unixepoch()
|
82
|
+
WHERE name = ?1;
|
85
83
|
|
86
84
|
snapshot: >
|
87
85
|
SELECT state, datetime(updated_at, 'unixepoch')
|
88
|
-
FROM topics
|
89
|
-
WHERE name = ?1
|
86
|
+
FROM topics
|
87
|
+
WHERE name = ?1;
|
90
88
|
|
91
89
|
capture_event: >
|
92
|
-
INSERT INTO events(topic, name, key, created_at, count, value, minimum, maximum)
|
93
|
-
|
94
|
-
|
95
|
-
|
90
|
+
INSERT INTO events(topic, name, key, created_at, count, value, minimum, maximum)
|
91
|
+
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8)
|
92
|
+
ON CONFLICT DO UPDATE
|
93
|
+
SET
|
94
|
+
count = count + EXCLUDED.count,
|
95
|
+
value = value + EXCLUDED.value,
|
96
|
+
minimum = min(minimum, EXCLUDED.minimum),
|
97
|
+
maximum = max(maximum, EXCLUDED.maximum);
|
98
|
+
|
96
99
|
# requires an index on (resolution, created_at)
|
97
100
|
summarize_events: >
|
98
|
-
INSERT INTO
|
99
|
-
events (topic, name, key, count, value, minimum, maximum, created_at, resolution
|
100
|
-
SELECT
|
101
|
-
topic,
|
102
|
-
name,
|
103
|
-
key,
|
104
|
-
sum(count),
|
105
|
-
sum(value),
|
106
|
-
min(minimum),
|
107
|
-
max(maximum),
|
108
|
-
(created_at/(?1))*?1 as created,
|
109
|
-
?2
|
110
|
-
FROM events
|
111
|
-
WHERE resolution = ?3
|
101
|
+
INSERT INTO
|
102
|
+
events (topic, name, key, count, value, minimum, maximum, created_at, resolution)
|
103
|
+
SELECT
|
104
|
+
topic,
|
105
|
+
name,
|
106
|
+
key,
|
107
|
+
sum(count),
|
108
|
+
sum(value),
|
109
|
+
min(minimum),
|
110
|
+
max(maximum),
|
111
|
+
(created_at/(?1))*?1 as created,
|
112
|
+
?2
|
113
|
+
FROM events
|
114
|
+
WHERE resolution = ?3
|
112
115
|
GROUP BY topic, name, key, created
|
113
|
-
ON CONFLICT DO
|
114
|
-
|
116
|
+
ON CONFLICT DO UPDATE
|
117
|
+
SET
|
118
|
+
count = EXCLUDED.count,
|
119
|
+
value = EXCLUDED.value,
|
120
|
+
minimum = EXCLUDED.minimum,
|
121
|
+
maximum = EXCLUDED.maximum;
|
115
122
|
|
116
123
|
# requires an index on (resolution, created_at) #TODO: fix deletion boundary (use the date mapping)
|
117
|
-
delete_events:
|
124
|
+
delete_events: >
|
125
|
+
DELETE FROM events
|
126
|
+
WHERE resolution = ?1
|
127
|
+
AND (created_at /(?2)) * ?2 < ((unixepoch()/(?2)) * ?2 - ?2);
|
118
128
|
|
119
129
|
# select topics from the topics table
|
120
|
-
list_topics:
|
130
|
+
list_topics: >
|
131
|
+
SELECT name FROM topics ORDER BY name ASC;
|
121
132
|
|
122
|
-
# select topics, their event counts, total values, min and max values
|
133
|
+
# select topics, their event counts, total values, min and max values
|
123
134
|
topics_summaries: >
|
124
|
-
SELECT
|
125
|
-
topic,
|
126
|
-
count(distinct name) as events,
|
127
|
-
count(distinct key) as keys,
|
128
|
-
sum(count) as rcount
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
GROUP BY topic
|
136
|
-
ORDER BY
|
137
|
-
iif(?3 = 'events', events,
|
138
|
-
iif(?3 = 'keys', keys,
|
139
|
-
iif(?3 = 'rcount', rcount, topic)))
|
135
|
+
SELECT
|
136
|
+
topic,
|
137
|
+
count(distinct name) as events,
|
138
|
+
count(distinct key) as keys,
|
139
|
+
sum(count) as rcount
|
140
|
+
FROM events
|
141
|
+
WHERE resolution = ?1
|
142
|
+
AND created_at <= unixepoch()
|
143
|
+
AND created_at >= unixepoch() -?2
|
144
|
+
AND name = '___'
|
145
|
+
AND iif(length(?4) > 0, rowid IN (SELECT rowid FROM events_search WHERE topic LIKE ?4), TRUE)
|
146
|
+
GROUP BY topic
|
147
|
+
ORDER BY
|
148
|
+
iif(?3 = 'events', events,
|
149
|
+
iif(?3 = 'keys', keys,
|
150
|
+
iif(?3 = 'rcount', rcount, topic)))
|
140
151
|
DESC;
|
141
|
-
|
152
|
+
|
142
153
|
topics_summaries_asc: >
|
143
|
-
SELECT
|
144
|
-
topic,
|
145
|
-
count(distinct name) as events,
|
146
|
-
count(distinct key) as keys,
|
147
|
-
sum(count) as rcount
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
GROUP BY topic
|
155
|
-
ORDER BY
|
156
|
-
iif(?3 = 'events', events,
|
157
|
-
iif(?3 = 'keys', keys,
|
158
|
-
iif(?3 = 'rcount', rcount, topic)))
|
154
|
+
SELECT
|
155
|
+
topic,
|
156
|
+
count(distinct name) as events,
|
157
|
+
count(distinct key) as keys,
|
158
|
+
sum(count) as rcount
|
159
|
+
FROM events
|
160
|
+
WHERE resolution = ?1
|
161
|
+
AND created_at <= unixepoch()
|
162
|
+
AND created_at >= unixepoch() -?2
|
163
|
+
AND name = '___'
|
164
|
+
AND iif(length(?4) > 0, rowid IN (SELECT rowid FROM events_search WHERE topic LIKE ?4), TRUE)
|
165
|
+
GROUP BY topic
|
166
|
+
ORDER BY
|
167
|
+
iif(?3 = 'events', events,
|
168
|
+
iif(?3 = 'keys', keys,
|
169
|
+
iif(?3 = 'rcount', rcount, topic)))
|
159
170
|
ASC;
|
160
171
|
|
161
172
|
events_summaries: >
|
162
|
-
SELECT
|
163
|
-
name,
|
164
|
-
count(DISTINCT key) AS keys,
|
173
|
+
SELECT
|
174
|
+
name,
|
175
|
+
count(DISTINCT key) AS keys,
|
165
176
|
sum(count) as rcount,
|
166
|
-
cast(sum(value) as double) / sum(count) as ravg,
|
167
|
-
sum(value) AS rtotal,
|
168
|
-
min(minimum) AS rmin,
|
169
|
-
max(maximum) AS rmax
|
170
|
-
FROM events
|
171
|
-
WHERE topic = ?1 AND resolution = ?2
|
177
|
+
cast(sum(value) as double) / sum(count) as ravg,
|
178
|
+
sum(value) AS rtotal,
|
179
|
+
min(minimum) AS rmin,
|
180
|
+
max(maximum) AS rmax
|
181
|
+
FROM events
|
182
|
+
WHERE topic = ?1 AND resolution = ?2
|
172
183
|
AND created_at <= unixepoch()
|
173
|
-
AND created_at >= unixepoch() - ?5
|
184
|
+
AND created_at >= unixepoch() - ?5
|
174
185
|
AND name != '___'
|
175
186
|
AND key = '___'
|
176
187
|
AND iif(length(?4) > 0, rowid IN (SELECT rowid FROM events_search WHERE name LIKE ?4), TRUE)
|
177
|
-
GROUP BY name
|
178
|
-
ORDER BY
|
179
|
-
iif(?3 = 'rcount', rcount,
|
180
|
-
iif(?3 = 'ravg', ravg,
|
181
|
-
iif(?3 = 'rtotal', rtotal,
|
182
|
-
iif(?3 = 'rmin', rmin,
|
183
|
-
iif(?3 = 'rmax', rmax,
|
184
|
-
iif(?3 = 'keys', keys,
|
185
|
-
iif(?3 = 'name', name, rcount)))))))
|
186
|
-
|
188
|
+
GROUP BY name
|
189
|
+
ORDER BY
|
190
|
+
iif(?3 = 'rcount', rcount,
|
191
|
+
iif(?3 = 'ravg', ravg,
|
192
|
+
iif(?3 = 'rtotal', rtotal,
|
193
|
+
iif(?3 = 'rmin', rmin,
|
194
|
+
iif(?3 = 'rmax', rmax,
|
195
|
+
iif(?3 = 'keys', keys,
|
196
|
+
iif(?3 = 'name', name, rcount)))))))
|
197
|
+
DESC
|
187
198
|
LIMIT 20;
|
188
199
|
|
189
200
|
events_summaries_asc: >
|
190
|
-
SELECT
|
191
|
-
name,
|
192
|
-
count(DISTINCT key) AS keys,
|
201
|
+
SELECT
|
202
|
+
name,
|
203
|
+
count(DISTINCT key) AS keys,
|
193
204
|
sum(count) as rcount,
|
194
|
-
cast(sum(value) as double) / sum(count) as ravg,
|
195
|
-
sum(value) AS rtotal,
|
196
|
-
min(minimum) AS rmin,
|
197
|
-
max(maximum) AS rmax
|
198
|
-
FROM events
|
199
|
-
WHERE topic = ?1 AND resolution = ?2
|
205
|
+
cast(sum(value) as double) / sum(count) as ravg,
|
206
|
+
sum(value) AS rtotal,
|
207
|
+
min(minimum) AS rmin,
|
208
|
+
max(maximum) AS rmax
|
209
|
+
FROM events
|
210
|
+
WHERE topic = ?1 AND resolution = ?2
|
200
211
|
AND created_at <= unixepoch()
|
201
|
-
AND created_at >= unixepoch() -?5
|
212
|
+
AND created_at >= unixepoch() -?5
|
202
213
|
AND name != '___'
|
203
214
|
AND key = '___'
|
204
215
|
AND iif(length(?4) > 0, rowid IN (SELECT rowid FROM events_search WHERE name LIKE ?4), TRUE)
|
205
|
-
GROUP BY name
|
206
|
-
ORDER BY
|
207
|
-
iif(?3 = 'rcount', rcount,
|
208
|
-
iif(?3 = 'ravg', ravg,
|
209
|
-
iif(?3 = 'rtotal', rtotal,
|
210
|
-
iif(?3 = 'rmin', rmin,
|
211
|
-
iif(?3 = 'rmax', rmax,
|
212
|
-
iif(?3 = 'keys', keys,
|
213
|
-
iif(?3 = 'name', name, rcount)))))))
|
214
|
-
|
216
|
+
GROUP BY name
|
217
|
+
ORDER BY
|
218
|
+
iif(?3 = 'rcount', rcount,
|
219
|
+
iif(?3 = 'ravg', ravg,
|
220
|
+
iif(?3 = 'rtotal', rtotal,
|
221
|
+
iif(?3 = 'rmin', rmin,
|
222
|
+
iif(?3 = 'rmax', rmax,
|
223
|
+
iif(?3 = 'keys', keys,
|
224
|
+
iif(?3 = 'name', name, rcount)))))))
|
225
|
+
ASC
|
215
226
|
LIMIT 20;
|
216
227
|
|
217
|
-
|
218
228
|
keys_summaries: >
|
219
|
-
SELECT
|
220
|
-
key,
|
229
|
+
SELECT
|
230
|
+
key,
|
221
231
|
sum(count) AS rcount,
|
222
|
-
cast(sum(value) AS double) / sum(count) AS ravg,
|
223
|
-
sum(value) AS rtotal,
|
224
|
-
min(minimum) AS rmin,
|
225
|
-
max(maximum) AS rmax
|
226
|
-
FROM events
|
227
|
-
WHERE topic = ?1 AND name = ?2 AND resolution = ?3
|
232
|
+
cast(sum(value) AS double) / sum(count) AS ravg,
|
233
|
+
sum(value) AS rtotal,
|
234
|
+
min(minimum) AS rmin,
|
235
|
+
max(maximum) AS rmax
|
236
|
+
FROM events
|
237
|
+
WHERE topic = ?1 AND name = ?2 AND resolution = ?3
|
228
238
|
AND created_at <= unixepoch()
|
229
|
-
AND created_at >= unixepoch() - ?6
|
239
|
+
AND created_at >= unixepoch() - ?6
|
230
240
|
AND key != '___'
|
231
241
|
AND iif(length(?5) > 0, rowid IN (SELECT rowid FROM events_search WHERE key LIKE ?5), TRUE)
|
232
242
|
GROUP BY key
|
233
|
-
ORDER BY
|
234
|
-
iif(?4 = 'rcount', rcount,
|
235
|
-
iif(?4 = 'ravg', ravg,
|
236
|
-
iif(?4 = 'rtotal', rtotal,
|
237
|
-
iif(?4 = 'rmin', rmin,
|
238
|
-
iif(?4 = 'rmax', rmax,
|
239
|
-
iif(?4 = 'key', key, rcount))))))
|
243
|
+
ORDER BY
|
244
|
+
iif(?4 = 'rcount', rcount,
|
245
|
+
iif(?4 = 'ravg', ravg,
|
246
|
+
iif(?4 = 'rtotal', rtotal,
|
247
|
+
iif(?4 = 'rmin', rmin,
|
248
|
+
iif(?4 = 'rmax', rmax,
|
249
|
+
iif(?4 = 'key', key, rcount))))))
|
240
250
|
DESC
|
241
251
|
LIMIT 20;
|
242
252
|
|
243
253
|
keys_summaries_asc: >
|
244
|
-
SELECT
|
245
|
-
key,
|
254
|
+
SELECT
|
255
|
+
key,
|
246
256
|
sum(count) AS rcount,
|
247
|
-
cast(sum(value) AS double) / sum(count) AS ravg,
|
248
|
-
sum(value) AS rtotal,
|
249
|
-
min(minimum) AS rmin,
|
250
|
-
max(maximum) AS rmax
|
251
|
-
FROM events
|
252
|
-
WHERE topic = ?1 AND name = ?2 AND resolution = ?3
|
257
|
+
cast(sum(value) AS double) / sum(count) AS ravg,
|
258
|
+
sum(value) AS rtotal,
|
259
|
+
min(minimum) AS rmin,
|
260
|
+
max(maximum) AS rmax
|
261
|
+
FROM events
|
262
|
+
WHERE topic = ?1 AND name = ?2 AND resolution = ?3
|
253
263
|
AND created_at <= unixepoch()
|
254
|
-
AND created_at >= unixepoch() - ?6
|
264
|
+
AND created_at >= unixepoch() - ?6
|
255
265
|
AND key != '___'
|
256
266
|
AND iif(length(?5) > 0, rowid IN (SELECT rowid FROM events_search WHERE key LIKE ?5), TRUE)
|
257
267
|
GROUP BY key
|
258
|
-
ORDER BY
|
259
|
-
iif(?4 = 'rcount', rcount,
|
260
|
-
iif(?4 = 'ravg', ravg,
|
261
|
-
iif(?4 = 'rtotal', rtotal,
|
262
|
-
iif(?4 = 'rmin', rmin,
|
263
|
-
iif(?4 = 'rmax', rmax,
|
264
|
-
iif(?4 = 'key', key, rcount))))))
|
268
|
+
ORDER BY
|
269
|
+
iif(?4 = 'rcount', rcount,
|
270
|
+
iif(?4 = 'ravg', ravg,
|
271
|
+
iif(?4 = 'rtotal', rtotal,
|
272
|
+
iif(?4 = 'rmin', rmin,
|
273
|
+
iif(?4 = 'rmax', rmax,
|
274
|
+
iif(?4 = 'key', key, rcount))))))
|
265
275
|
ASC
|
266
276
|
LIMIT 20;
|
267
277
|
|
268
|
-
# list data points at the topic, event, or key level
|
269
|
-
# needs: duration, limit, resolution, topic, name (optional), key (optional)
|
278
|
+
# list data points at the topic, event, or key level
|
279
|
+
# needs: duration, limit, resolution, topic, name (optional), key (optional)
|
270
280
|
|
271
281
|
topic_data_points: >
|
272
|
-
SELECT
|
273
|
-
datetime(ts.slot, 'unixepoch') AS rtime,
|
274
|
-
ts.slot AS unixtime,
|
275
|
-
sum(events.count) AS rcount,
|
276
|
-
avg(events.value/events.count) AS ravg
|
282
|
+
SELECT
|
283
|
+
datetime(ts.slot, 'unixepoch') AS rtime,
|
284
|
+
ts.slot AS unixtime,
|
285
|
+
sum(events.count) AS rcount,
|
286
|
+
avg(events.value/events.count) AS ravg
|
277
287
|
FROM (
|
278
|
-
WITH RECURSIVE timeslot(x) AS (
|
279
|
-
SELECT (unixepoch()/(?1))*(?1)
|
280
|
-
UNION ALL
|
281
|
-
SELECT x - (?1) FROM timeslot LIMIT ?2
|
282
|
-
) SELECT x as slot FROM timeslot
|
283
|
-
) AS ts
|
284
|
-
LEFT OUTER JOIN events
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
288
|
+
WITH RECURSIVE timeslot(x) AS (
|
289
|
+
SELECT (unixepoch()/(?1))*(?1)
|
290
|
+
UNION ALL
|
291
|
+
SELECT x - (?1) FROM timeslot LIMIT ?2
|
292
|
+
) SELECT x as slot FROM timeslot
|
293
|
+
) AS ts
|
294
|
+
LEFT OUTER JOIN events
|
295
|
+
ON ts.slot = events.created_at
|
296
|
+
AND events.resolution = ?3
|
297
|
+
AND events.topic = ?4
|
298
|
+
AND events.created_at <= UNIXEPOCH()
|
299
|
+
AND events.name = '___'
|
290
300
|
GROUP BY ts.slot
|
291
301
|
ORDER BY ts.slot ASC;
|
292
|
-
|
302
|
+
|
293
303
|
event_data_points: >
|
294
|
-
SELECT
|
295
|
-
datetime(ts.slot, 'unixepoch') AS rtime,
|
296
|
-
ts.slot AS unixtime,
|
297
|
-
events.count AS rcount,
|
298
|
-
events.value / events.count AS ravg,
|
299
|
-
events.value AS rtotal
|
304
|
+
SELECT
|
305
|
+
datetime(ts.slot, 'unixepoch') AS rtime,
|
306
|
+
ts.slot AS unixtime,
|
307
|
+
events.count AS rcount,
|
308
|
+
events.value / events.count AS ravg,
|
309
|
+
events.value AS rtotal
|
300
310
|
FROM (
|
301
|
-
WITH RECURSIVE timeslot(x) AS (
|
302
|
-
SELECT (unixepoch()/(?1))*(?1)
|
303
|
-
UNION ALL
|
304
|
-
SELECT x - (?1) FROM timeslot LIMIT ?2
|
305
|
-
) SELECT x as slot FROM timeslot
|
306
|
-
) AS ts
|
307
|
-
LEFT OUTER JOIN events
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
311
|
+
WITH RECURSIVE timeslot(x) AS (
|
312
|
+
SELECT (unixepoch()/(?1))*(?1)
|
313
|
+
UNION ALL
|
314
|
+
SELECT x - (?1) FROM timeslot LIMIT ?2
|
315
|
+
) SELECT x as slot FROM timeslot
|
316
|
+
) AS ts
|
317
|
+
LEFT OUTER JOIN events
|
318
|
+
ON ts.slot = events.created_at
|
319
|
+
AND events.resolution = ?3
|
320
|
+
AND events.topic = ?4
|
321
|
+
AND events.name = ?5
|
322
|
+
AND events.key = '___'
|
323
|
+
AND events.created_at <= UNIXEPOCH()
|
314
324
|
GROUP BY ts.slot
|
315
325
|
ORDER BY ts.slot ASC;
|
316
|
-
|
326
|
+
|
317
327
|
key_data_points: >
|
318
|
-
SELECT
|
319
|
-
datetime(ts.slot, 'unixepoch') AS rtime,
|
320
|
-
ts.slot AS unixtime,
|
321
|
-
events.count AS rcount,
|
322
|
-
events.value / events.count AS ravg,
|
323
|
-
events.value AS rtotal
|
328
|
+
SELECT
|
329
|
+
datetime(ts.slot, 'unixepoch') AS rtime,
|
330
|
+
ts.slot AS unixtime,
|
331
|
+
events.count AS rcount,
|
332
|
+
events.value / events.count AS ravg,
|
333
|
+
events.value AS rtotal
|
324
334
|
FROM (
|
325
|
-
WITH RECURSIVE timeslot(x) AS (
|
326
|
-
SELECT (unixepoch()/(?1))*(?1)
|
327
|
-
UNION ALL
|
328
|
-
SELECT x - (?1) FROM timeslot LIMIT ?2
|
329
|
-
) SELECT x as slot FROM timeslot
|
330
|
-
) AS ts
|
331
|
-
LEFT OUTER JOIN events
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
335
|
+
WITH RECURSIVE timeslot(x) AS (
|
336
|
+
SELECT (unixepoch()/(?1))*(?1)
|
337
|
+
UNION ALL
|
338
|
+
SELECT x - (?1) FROM timeslot LIMIT ?2
|
339
|
+
) SELECT x as slot FROM timeslot
|
340
|
+
) AS ts
|
341
|
+
LEFT OUTER JOIN events
|
342
|
+
ON ts.slot = events.created_at
|
343
|
+
AND events.resolution = ?3
|
344
|
+
AND events.topic = ?4
|
345
|
+
AND events.name = ?5
|
346
|
+
AND events.key = ?6
|
347
|
+
AND events.created_at <= UNIXEPOCH()
|
338
348
|
GROUP BY ts.slot
|
339
349
|
ORDER BY ts.slot ASC;
|