Skip to content

Commit de0f6d7

Browse files
committed
running metric collection with read only connection.
The read only connection is set up with follower reads, to minimize contention.
1 parent 8c04ddb commit de0f6d7

File tree

10 files changed

+1200
-91
lines changed

10 files changed

+1200
-91
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@
1313

1414
# Dependency directories (remove the comment below to include it)
1515
# vendor/
16+
scripts/
17+
tmp/
18+
*.sh
19+
certs
20+
visus
21+
visus-*

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# visus
2+
23
Visus (latin for "the action of looking") enables users to collect metrics using arbitrary SQL queries and expose them in a Prometheus format. Optionally, it can be configured to filter the metrics CockroachDB available in the `/_status/vars` endpoint.
34

45
Visus runs as a sidecar on each node of a CockroachDB cluster, as shown in the diagram below.
@@ -29,11 +30,12 @@ LIMIT
2930

3031
The Prometheus collectors will add additional labels to track the cluster name as well as the instance where the metrics are coming from.
3132

32-
## Database Security
33+
## Database Security
34+
3335
It is recommended to use separate users for managing the configuration and to run the sidecar.
3436
The sidecar needs `SELECT ON TABLES` privileges on the `_visus` database to read the configuration. It also needs the `SELECT,INSERT,UPDATE` privileges on the `_visus.node` table, used to determine which node should collect cluster wide metrics.
3537

36-
To run many of the sample collections available in the examples directory,
38+
To run many of the sample collections available in the examples directory,
3739
the 'VIEWACTIVITY' option should be granted to the user.
3840
The `./visus init` command will provision a `visus` user with the minimal privileges to run the sidecar. Defining new collection may require additional privileges, depending on what data the SQL query associated to the collection has to access.
3941

@@ -172,8 +174,9 @@ $VISUS_USER start --bind-addr :8888 --insecure --endpoint "/_status/custom"
172174

173175
## Histogram rewriting
174176

175-
Visus can also act as a proxy to filter and rewrite CockroachDB histograms (v22.1 and earlier) from a log-2 linear format (HDR histograms) to a log-10 linear format.
177+
Visus can also act as a proxy to filter and rewrite CockroachDB histograms (v22.1 and earlier) from a log-2 linear format (HDR histograms) to a log-10 linear format.
176178
Users can specify which histograms to rewrite based on a regular expression. For instance to rewrite all the histograms that match "^sql_exec_latency$" and keep buckets between 1ms and 20sec, we specify in the configuration file `latency.yaml`:
179+
177180
```yaml
178181
name: latency
179182
regex: ^sql_exec_latency$

examples/cluster_sqlactivity.yaml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: cluster_sqlactivity
2+
enabled: true
3+
scope: node
4+
frequency: 20
5+
maxresults: 20
6+
labels: [statement,application,database]
7+
metrics:
8+
- name : exec_count
9+
kind : counter
10+
help : number of times the statement was executed.
11+
- name : net_bytes
12+
kind : gauge
13+
help : amount of data transferred over the network.
14+
- name : max_disk
15+
kind : gauge
16+
help : maximum data transferred from the disk.
17+
- name : run_lat
18+
kind : gauge
19+
help : average runtime.
20+
- name : rows_read
21+
kind : gauge
22+
help : average number of rows read from disk.
23+
- name : rows_avg
24+
kind : gauge
25+
help : average number of rows returned.
26+
- name : bytes_avg
27+
kind : gauge
28+
help : average number of bytes read from disk.
29+
- name : total_lat
30+
kind : gauge
31+
help : total runtime for the statement.
32+
- name : max_retries
33+
kind : gauge
34+
help : cumulative number of automatic retries.
35+
- name : max_mem
36+
kind : gauge
37+
help : maximum memory used by the statement.
38+
- name : cont_time
39+
kind : gauge
40+
help : number of times the statement was executed.
41+
query:
42+
WITH
43+
max AS (select max(aggregated_ts) from crdb_internal.statement_statistics),
44+
total AS (
45+
SELECT
46+
encode(fingerprint_id, 'hex') as statement,
47+
app_name as application,
48+
metadata->'db' as database,
49+
sum((statistics->'execution_statistics'->'cnt')::float8) AS exec_count,
50+
max((statistics->'execution_statistics'->'maxDiskUsage'->'mean')::float8) AS max_disk,
51+
sum((statistics->'execution_statistics'->'networkBytes'->'mean')::float8 * (statistics->'execution_statistics'->'cnt')::float8 ) AS net_bytes,
52+
sum((statistics->'statistics'->'runLat'->'mean')::float8 * (statistics->'execution_statistics'->'cnt')::float8 ) AS run_lat,
53+
sum((statistics->'statistics'->'rowsRead'->'mean')::float8 * (statistics->'execution_statistics'->'cnt')::float8 ) AS rows_read,
54+
sum((statistics->'statistics'->'numRows'->'mean')::float8 * (statistics->'execution_statistics'->'cnt')::float8) AS rows_num,
55+
sum((statistics->'statistics'->'bytesRead'->'mean')::float8 * (statistics->'execution_statistics'->'cnt')::float8) AS bytes_read,
56+
sum((statistics->'statistics'->'runLat'->'mean')::float8 * (statistics->'execution_statistics'->'cnt')::float8) AS total_lat,
57+
sum((statistics->'statistics'->'maxRetries'->'mean')::float8) AS max_retries,
58+
max((statistics->'execution_statistics'->'maxMemUsage'->'mean')::float8) AS max_mem,
59+
sum((statistics->'execution_statistics'->'contentionTime'->'mean')::float8 * (statistics->'execution_statistics'->'cnt')::float8) AS cont_time
60+
FROM
61+
crdb_internal.statement_statistics
62+
WHERE
63+
app_name NOT LIKE '$ internal-%'
64+
AND aggregated_ts = (select * from max)
65+
AND aggregation_interval = '1h'
66+
GROUP BY
67+
statement, application, database
68+
)
69+
select
70+
statement, application, database,
71+
exec_count,
72+
net_bytes / exec_count as net_bytes,
73+
max_disk,
74+
run_lat / exec_count as run_lat,
75+
rows_read / exec_count as rows_read,
76+
rows_num / exec_count as rows_avg,
77+
bytes_read / exec_count as bytes_avg,
78+
total_lat,
79+
max_retries,
80+
max_mem,
81+
cont_time / exec_count as cont_time
82+
FROM
83+
total
84+
WHERE exec_count > 0
85+
86+
ORDER BY
87+
total_lat DESC
88+
LIMIT
89+
$1;

examples/sqlactivity.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: sqlactivity
22
enabled: true
33
scope: node
4-
frequency: 10
5-
maxresults: 10
4+
frequency: 5
5+
maxresults: 20
66
labels: [statement,application,database]
77
metrics:
88
- name : exec_count

go.mod

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,55 @@ go 1.19
44

55
require (
66
github.com/NYTimes/gziphandler v1.1.1
7-
github.com/cockroachdb/crlfmt v0.0.0-20220610162206-024b567ce87b
8-
github.com/creasty/defaults v1.6.0
9-
github.com/go-co-op/gocron v1.32.1
7+
github.com/cockroachdb/crlfmt v0.0.0-20230505164321-461e8663b4b4
8+
github.com/creasty/defaults v1.7.0
9+
github.com/go-co-op/gocron v1.35.3
1010
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
11-
github.com/jackc/pgconn v1.14.0
11+
github.com/jackc/pgconn v1.14.1
1212
github.com/jackc/pgtype v1.14.0
1313
github.com/jackc/pgx/v4 v4.18.1
14-
github.com/joonix/log v0.0.0-20200409080653-9c1d2ceb5f1d
14+
github.com/joonix/log v0.0.0-20230221083239-7988383bab32
1515
github.com/pashagolub/pgxmock v1.8.0
1616
github.com/pkg/errors v0.9.1
17-
github.com/prometheus/client_golang v1.15.1
18-
github.com/prometheus/client_model v0.4.0
19-
github.com/prometheus/common v0.44.0
20-
github.com/sirupsen/logrus v1.9.0
21-
github.com/spf13/cobra v1.6.1
17+
github.com/prometheus/client_golang v1.17.0
18+
github.com/prometheus/client_model v0.5.0
19+
github.com/prometheus/common v0.45.0
20+
github.com/sirupsen/logrus v1.9.3
21+
github.com/spf13/cobra v1.8.0
2222
github.com/stretchr/testify v1.8.4
23-
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
24-
golang.org/x/tools v0.6.0
25-
google.golang.org/protobuf v1.30.0
23+
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
24+
golang.org/x/tools v0.14.0
25+
google.golang.org/protobuf v1.31.0
2626
gopkg.in/yaml.v3 v3.0.1
27-
honnef.co/go/tools v0.4.2
27+
honnef.co/go/tools v0.4.6
2828
)
2929

3030
require (
31-
github.com/BurntSushi/toml v1.2.1 // indirect
31+
github.com/BurntSushi/toml v1.3.2 // indirect
3232
github.com/beorn7/perks v1.0.1 // indirect
3333
github.com/cespare/xxhash/v2 v2.2.0 // indirect
34-
github.com/cockroachdb/gostdlib v1.13.0 // indirect
35-
github.com/cockroachdb/ttycolor v0.0.0-20180709150743-a1d5aaeb377d // indirect
34+
github.com/cockroachdb/gostdlib v1.19.0 // indirect
35+
github.com/cockroachdb/ttycolor v0.0.0-20210902133924-c7d7dcdde4e8 // indirect
3636
github.com/davecgh/go-spew v1.1.1 // indirect
3737
github.com/golang/protobuf v1.5.3 // indirect
38-
github.com/google/uuid v1.3.0 // indirect
39-
github.com/inconshreveable/mousetrap v1.0.1 // indirect
38+
github.com/google/uuid v1.4.0 // indirect
39+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
4040
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
4141
github.com/jackc/pgio v1.0.0 // indirect
4242
github.com/jackc/pgpassfile v1.0.0 // indirect
4343
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
4444
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
4545
github.com/jackc/puddle v1.3.0 // indirect
46-
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
46+
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
4747
github.com/pmezard/go-difflib v1.0.0 // indirect
48-
github.com/prometheus/procfs v0.9.0 // indirect
48+
github.com/prometheus/procfs v0.12.0 // indirect
4949
github.com/robfig/cron/v3 v3.0.1 // indirect
5050
github.com/spf13/pflag v1.0.5 // indirect
51-
go.uber.org/atomic v1.9.0 // indirect
52-
golang.org/x/crypto v0.6.0 // indirect
53-
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
54-
golang.org/x/mod v0.8.0 // indirect
55-
golang.org/x/sys v0.8.0 // indirect
56-
golang.org/x/text v0.9.0 // indirect
57-
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
51+
go.uber.org/atomic v1.11.0 // indirect
52+
golang.org/x/crypto v0.14.0 // indirect
53+
golang.org/x/exp/typeparams v0.0.0-20231006140011-7918f672742d // indirect
54+
golang.org/x/mod v0.14.0 // indirect
55+
golang.org/x/sys v0.14.0 // indirect
56+
golang.org/x/text v0.14.0 // indirect
57+
google.golang.org/genproto v0.0.0-20231030173426-d783a09b4405 // indirect
5858
)

0 commit comments

Comments
 (0)