-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #109 from pinax-network/improve-queries
Add new health queries
- Loading branch information
Showing
12 changed files
with
162 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
-- view -- | ||
CREATE MATERIALIZED VIEW IF NOT EXISTS blocks_mv | ||
ENGINE = MergeTree | ||
ORDER BY (chain, timestamp, block_number) | ||
AS SELECT | ||
block_id, | ||
block_number, | ||
chain, | ||
timestamp | ||
FROM blocks; | ||
|
||
-- DROP TABLE IF EXISTS blocks_mv; | ||
|
||
-- OPTIMIZE TABLE blocks_mv FINAL; | ||
|
||
-- -- insert -- | ||
-- INSERT INTO blocks_mv SELECT | ||
-- block_id, | ||
-- block_number, | ||
-- chain, | ||
-- timestamp | ||
-- FROM blocks; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { join } from "path"; | ||
|
||
function file(path: string) { | ||
return Bun.file(join(import.meta.dirname, path)).text(); | ||
} | ||
|
||
const glob = new Bun.Glob("**/*.sql"); | ||
const tables: [string, string][] = []; | ||
|
||
for (const path of glob.scanSync(import.meta.dirname)) { | ||
tables.push([path.replace(".sql", ""), await file(path)]) | ||
} | ||
|
||
export default tables; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SELECT | ||
chain, | ||
COUNT() AS count, | ||
COUNTDISTINCT(block_number) AS count_distinct, | ||
MAX(block_number) AS max, | ||
MIN(block_number) AS min, | ||
max - min + 1 AS delta, | ||
delta - count_distinct AS missing | ||
FROM blocks | ||
GROUP BY chain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
SELECT | ||
table, | ||
sum(rows) AS rows, | ||
max(modification_time) AS latest_modification, | ||
formatReadableSize(sum(bytes)) AS data_size, | ||
formatReadableSize(sum(primary_key_bytes_in_memory)) AS primary_keys_size, | ||
any(engine) AS engine, | ||
sum(bytes) AS bytes_size | ||
FROM clusterAllReplicas(default, system.parts) | ||
WHERE active | ||
GROUP BY | ||
database, | ||
table | ||
ORDER BY bytes_size DESC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { z } from "zod"; | ||
import client from "../clickhouse/createClient.js"; | ||
|
||
export const ClusterSchema = z.object({ | ||
count: z.number(), | ||
distinctCount: z.number(), | ||
min: z.number(), | ||
max: z.number(), | ||
delta: z.number(), | ||
missing: z.number(), | ||
}); | ||
export type ClusterSchema = z.infer<typeof ClusterSchema>; | ||
|
||
export async function cluster() { | ||
const query = await Bun.file(import.meta.dirname + "/cluster.sql").text() | ||
const response = await client.query({ query, format: "JSONEachRow" }); | ||
return response.json(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters