Skip to content

Commit

Permalink
metrics: shorten backend name on TiDB Operator based clusters (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Mar 23, 2023
1 parent 45df1bc commit 645756a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ vendor
work
.vscode/
.cover*
grafonnet-lib
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ build:
go build ./...
cd lib && go build ./...

metrics:
go install github.com/google/go-jsonnet/cmd/jsonnet@latest
[ -e "grafonnet-lib" ] || git clone --depth=1 https://github.com/grafana/grafonnet-lib
JSONNET_PATH=grafonnet-lib jsonnet ./pkg/metrics/grafana/tiproxy_summary.jsonnet > ./pkg/metrics/grafana/tiproxy_summary.json

test: gocovmerge
rm -f .cover.*
go test -coverprofile=.cover.pkg ./...
Expand Down
22 changes: 0 additions & 22 deletions pkg/metrics/grafana/generate_json.sh

This file was deleted.

12 changes: 6 additions & 6 deletions pkg/metrics/grafana/tiproxy_summary.json
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
"thresholds": [ ],
"timeFrom": null,
"timeShift": null,
"title": "CPS By Instance",
"title": "CPS by Instance",
"tooltip": {
"shared": true,
"sort": 0,
Expand Down Expand Up @@ -638,7 +638,7 @@
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(tiproxy_session_query_total{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (backend)",
"expr": "label_replace(sum(rate(tiproxy_session_query_total{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (backend), \"backend\", \"$1\", \"backend\", \"(.+-tidb-[0-9]+).*peer.*.svc.*\")",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{backend}}",
Expand Down Expand Up @@ -830,10 +830,10 @@
"steppedLine": false,
"targets": [
{
"expr": "tiproxy_balance_b_conn{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}",
"expr": "label_replace(tiproxy_balance_b_conn{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\".*$tidb_cluster\", instance=~\"$instance\"}, \"backend\", \"$1\", \"backend\", \"(.+-tidb-[0-9]+).*peer.*.svc.*\")",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{backend}}",
"legendFormat": "{{instance}} | {{backend}}",
"refId": "A"
}
],
Expand Down Expand Up @@ -916,10 +916,10 @@
"steppedLine": false,
"targets": [
{
"expr": "sum(rate(tiproxy_balance_migrate_total{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\"$tidb_cluster\", instance=~\"$instance\"}[1m])) by (from, to, migrate_res)",
"expr": "sum(label_replace(label_replace(rate(tiproxy_balance_migrate_total{k8s_cluster=\"$k8s_cluster\", tidb_cluster=\".*$tidb_cluster\", instance=~\"$instance\"}[1m]), \"from\", \"$1\", \"from\", \"(.+-tidb-[0-9]+).*peer.*.svc.*\"), \"to\", \"$1\", \"to\", \"(.+-tidb-[0-9]+).*peer.*.svc.*\")) by (from, to, migrate_res)",
"format": "time_series",
"intervalFactor": 2,
"legendFormat": "{{from}}-{{to}}-{{migrate_res}}",
"legendFormat": "{{migrate_res}}: {{from}} => {{to}}",
"refId": "A"
}
],
Expand Down
12 changes: 6 additions & 6 deletions pkg/metrics/grafana/tiproxy_summary.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ local durationP = graphPanel.new(
);

local cpsByInstP = graphPanel.new(
title='CPS By Instance',
title='CPS by Instance',
datasource=myDS,
legend_rightSide=true,
description='TiProxy query total statistics including both successful and failed ones.',
Expand All @@ -207,7 +207,7 @@ local cpsByBackP = graphPanel.new(
)
.addTarget(
prometheus.target(
'sum(rate(tiproxy_session_query_total{k8s_cluster="$k8s_cluster", tidb_cluster="$tidb_cluster", instance=~"$instance"}[1m])) by (backend)',
'label_replace(sum(rate(tiproxy_session_query_total{k8s_cluster="$k8s_cluster", tidb_cluster="$tidb_cluster", instance=~"$instance"}[1m])) by (backend), "backend", "$1", "backend", "(.+-tidb-[0-9]+).*peer.*.svc.*")',
legendFormat='{{backend}}',
)
);
Expand Down Expand Up @@ -237,8 +237,8 @@ local bConnP = graphPanel.new(
)
.addTarget(
prometheus.target(
'tiproxy_balance_b_conn{k8s_cluster="$k8s_cluster", tidb_cluster="$tidb_cluster", instance=~"$instance"}',
legendFormat='{{backend}}',
'label_replace(tiproxy_balance_b_conn{k8s_cluster="$k8s_cluster", tidb_cluster=".*$tidb_cluster", instance=~"$instance"}, "backend", "$1", "backend", "(.+-tidb-[0-9]+).*peer.*.svc.*")',
legendFormat='{{instance}} | {{backend}}',
)
);

Expand All @@ -251,8 +251,8 @@ local bMigCounterP = graphPanel.new(
)
.addTarget(
prometheus.target(
'sum(rate(tiproxy_balance_migrate_total{k8s_cluster="$k8s_cluster", tidb_cluster="$tidb_cluster", instance=~"$instance"}[1m])) by (from, to, migrate_res)',
legendFormat='{{from}}-{{to}}-{{migrate_res}}',
'sum(label_replace(label_replace(rate(tiproxy_balance_migrate_total{k8s_cluster="$k8s_cluster", tidb_cluster=".*$tidb_cluster", instance=~"$instance"}[1m]), "from", "$1", "from", "(.+-tidb-[0-9]+).*peer.*.svc.*"), "to", "$1", "to", "(.+-tidb-[0-9]+).*peer.*.svc.*")) by (from, to, migrate_res)',
legendFormat='{{migrate_res}}: {{from}} => {{to}}',
)
);

Expand Down

0 comments on commit 645756a

Please sign in to comment.