Skip to content

Commit 081fc7d

Browse files
authored
Merge pull request #28 from jianxiaoguo/main
chore(grafana): remove panel when component off-cluster
2 parents d56a7fb + 176564f commit 081fc7d

8 files changed

Lines changed: 117 additions & 429 deletions

File tree

charts/monitor/templates/_helpers.tmpl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{{/* Generate monitor grafana envs */}}
22
{{- define "grafana.envs" }}
33
env:
4+
- name: NAMESPACE
5+
valueFrom:
6+
fieldRef:
7+
fieldPath: metadata.namespace
48
{{- if eq .Values.global.influxdbLocation "off-cluster" }}
59
- name: "INFLUXDB_URL"
610
valueFrom:
@@ -73,4 +77,18 @@ env:
7377
- name: DRYCC_PASSPORT_SECRET
7478
value: "{{ .Values.grafana.passportSecret }}"
7579
{{- end }}
80+
- name: "INFLUXDB_LOCATION"
81+
value: {{ .Values.global.influxdbLocation }}
82+
- name: "REDIS_LOCATION"
83+
value: {{ .Values.global.redisLocation }}
84+
- name: "RABBITMQ_LOCATION"
85+
value: {{ .Values.global.rabbitmqLocation }}
86+
- name: "STORAGE_LOCATION"
87+
value: {{ .Values.global.storageLocation }}
88+
- name: "DATABASE_LOCATION"
89+
value: {{ .Values.global.databaseLocation }}
90+
- name: "PASSPORT_LOCATION"
91+
value: {{ .Values.global.passportLocation }}
92+
- name: "REGISTRY_LOCATION"
93+
value: {{ .Values.global.registryLocation }}
7694
{{- end }}

charts/monitor/values.yaml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,25 +72,19 @@ redis:
7272
port: "6379"
7373

7474
global:
75-
# Set the location of Workflow's influxdb cluster
75+
# Set the location of Workflow's component cluster
7676
#
7777
# Valid values are:
78-
# - on-cluster: Run Influxdb within the Kubernetes cluster
79-
# - off-cluster: Influxdb is running outside of the cluster and credentials and connection information will be provided.
78+
# - on-cluster: Run component within the Kubernetes cluster
79+
# - off-cluster: component is running outside of the cluster and credentials and connection information will be provided.
8080
influxdbLocation: "on-cluster"
81-
# Set the location of Workflow's grafana instance
82-
#
83-
# Valid values are:
84-
# - on-cluster: Run Grafana within the Kubernetes cluster
85-
# - off-cluster: Grafana is running outside of the cluster
8681
grafanaLocation: "on-cluster"
87-
# Set the location of Workflow's redis instance
88-
#
89-
# Valid values are:
90-
# - on-cluster: Run Redis within the Kubernetes cluster
91-
# - off-cluster: Run Redis outside the Kubernetes cluster (configure in redis section)
9282
redisLocation: "on-cluster"
83+
rabbitmqLocation: "on-cluster"
9384
storageLocation: "on-cluster"
85+
databaseLocation: "on-cluster"
86+
passportLocation: "on-cluster"
87+
registryLocation: "on-cluster"
9488
# Role-Based Access Control for Kubernetes >= 1.5
9589
rbac: false
9690
ingressClass: ""

grafana/rootfs/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ ENV DRYCC_UID=1001 \
44
DRYCC_GID=1001 \
55
DRYCC_HOME_DIR=/usr/share/grafana \
66
GRAFANA_VERSION="9.1.1" \
7-
ENVTPL_VERSION="1.0.0"
7+
ENVTPL_VERSION="1.0.0" \
8+
JQ_VERSION="1.6"
89

910
RUN groupadd drycc --gid ${DRYCC_GID} \
1011
&& useradd drycc -u ${DRYCC_UID} -g ${DRYCC_GID} -s /bin/bash -m -d ${DRYCC_HOME_DIR}
@@ -14,6 +15,7 @@ COPY . /
1415
RUN install-packages fontconfig curl \
1516
&& install-stack grafana ${GRAFANA_VERSION} \
1617
&& install-stack envtpl ${ENVTPL_VERSION} \
18+
&& install-stack jq ${JQ_VERSION} \
1719
&& rm -rf \
1820
/usr/share/doc \
1921
/usr/share/man \

grafana/rootfs/usr/share/grafana/api/dashboards/drycc_component_health.json

Lines changed: 36 additions & 270 deletions
Large diffs are not rendered by default.

grafana/rootfs/usr/share/grafana/api/dashboards/pd.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"editable": true,
2626
"fiscalYearStartMonth": 0,
2727
"graphTooltip": 0,
28-
"id": 5,
28+
"id": null,
2929
"links": [],
3030
"liveNow": false,
3131
"panels": [
@@ -1059,10 +1059,7 @@
10591059
},
10601060
"targets": [
10611061
{
1062-
"datasource": {
1063-
"type": "influxdb",
1064-
"uid": "6fcv2jV4z"
1065-
},
1062+
"datasource": null,
10661063
"query": "from(bucket: \"kubernetes\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"process_cpu_seconds_total\")\n |> filter(fn: (r) => r[\"url\"] =~ /pd/)\n |> toInt()\n |> map(fn: (r) => ({ r with _value: r._value / 1000 }))\n |> keep(columns: [\"_time\", \"_value\", \"url\"])\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n |> yield(name: \"mean\")\n ",
10671064
"refId": "A"
10681065
}
@@ -1162,11 +1159,6 @@
11621159
"templating": {
11631160
"list": [
11641161
{
1165-
"current": {
1166-
"selected": false,
1167-
"text": "http://drycc-storage-meta-pd-0.drycc-storage-meta-pd.drycc.svc.cluster.local:2379/metrics",
1168-
"value": "http://drycc-storage-meta-pd-0.drycc-storage-meta-pd.drycc.svc.cluster.local:2379/metrics"
1169-
},
11701162
"datasource": null,
11711163
"definition": "from(bucket: v.bucket)\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"pd_cluster_status\")\n |> duplicate(column: \"url\", as: \"_value\")\n |> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)\n |> yield(name: \"last\")",
11721164
"description": "pd_cluster_status url",

grafana/rootfs/usr/share/grafana/api/dashboards/redis.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"measurement": "kubernetes_pod_container",
101101
"orderByTime": "ASC",
102102
"policy": "default",
103-
"query": "from(bucket: v.bucket)\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_field\"] == \"cpu_usage_nanocores\")\n |> filter(fn: (r) => r[\"namespace\"] == \"drycc\")\n |> filter(fn: (r) => r[\"container_name\"] == \"drycc-redis\")\n |> keep(columns: [\"_time\", \"node_name\", \"pod_name\", \"container_name\", \"_value\"])\n |> movingAverage(n: 10)\n |> map(fn: (r) => ({\n r with\n _value: r._value / 1000000.0\n })\n )\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n |> yield(name: \"mean\")",
103+
"query": "from(bucket: v.bucket)\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_field\"] == \"cpu_usage_nanocores\")\n |> filter(fn: (r) => r[\"namespace\"] == \"drycc\")\n |> filter(fn: (r) => r[\"container_name\"] == \"drycc-redis\")\n |> keep(columns: [\"_time\", \"node_name\", \"namespace\", \"pod_name\", \"container_name\", \"_value\"])\n |> movingAverage(n: 10)\n |> map(fn: (r) => ({\n r with\n _value: r._value / 1000000.0\n })\n )\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n |> yield(name: \"mean\")",
104104
"refId": "A",
105105
"resultFormat": "time_series"
106106
}
@@ -209,7 +209,7 @@
209209
"measurement": "kubernetes_pod_container",
210210
"orderByTime": "ASC",
211211
"policy": "default",
212-
"query": "from(bucket: v.bucket)\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"container_name\"] == \"drycc-redis\")\n |> filter(fn: (r) => r[\"_field\"] == \"memory_usage_bytes\")\n |> keep(columns: [\"_time\", \"node_name\", \"pod_name\", \"container_name\", \"_value\"])\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n |> yield(name: \"mean\")",
212+
"query": "from(bucket: v.bucket)\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"namespace\"] == \"drycc\")\n |> filter(fn: (r) => r[\"container_name\"] == \"drycc-redis\")\n |> filter(fn: (r) => r[\"_field\"] == \"memory_usage_bytes\")\n |> keep(columns: [\"_time\", \"node_name\", \"namespace\", \"pod_name\", \"container_name\", \"_value\"])\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n |> yield(name: \"mean\")",
213213
"refId": "A",
214214
"resultFormat": "time_series"
215215
}

grafana/rootfs/usr/share/grafana/api/dashboards/tikv.json

Lines changed: 2 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"editable": true,
2626
"fiscalYearStartMonth": 0,
2727
"graphTooltip": 0,
28-
"id": 6,
28+
"id": null,
2929
"links": [],
3030
"liveNow": false,
3131
"panels": [
@@ -881,7 +881,7 @@
881881
"gridPos": {
882882
"h": 7,
883883
"w": 12,
884-
"x": 0,
884+
"x": 12,
885885
"y": 15
886886
},
887887
"id": 2781,
@@ -947,132 +947,6 @@
947947
],
948948
"title": "Memory",
949949
"type": "timeseries"
950-
},
951-
{
952-
"datasource": null,
953-
"description": "",
954-
"fieldConfig": {
955-
"defaults": {
956-
"color": {
957-
"mode": "palette-classic"
958-
},
959-
"custom": {
960-
"axisCenteredZero": false,
961-
"axisColorMode": "text",
962-
"axisLabel": "",
963-
"axisPlacement": "auto",
964-
"barAlignment": 0,
965-
"drawStyle": "line",
966-
"fillOpacity": 0,
967-
"gradientMode": "none",
968-
"hideFrom": {
969-
"legend": false,
970-
"tooltip": false,
971-
"viz": false
972-
},
973-
"lineInterpolation": "linear",
974-
"lineWidth": 1,
975-
"pointSize": 5,
976-
"scaleDistribution": {
977-
"type": "linear"
978-
},
979-
"showPoints": "auto",
980-
"spanNulls": false,
981-
"stacking": {
982-
"group": "A",
983-
"mode": "none"
984-
},
985-
"thresholdsStyle": {
986-
"mode": "off"
987-
}
988-
},
989-
"mappings": [],
990-
"thresholds": {
991-
"mode": "absolute",
992-
"steps": [
993-
{
994-
"color": "green",
995-
"value": null
996-
},
997-
{
998-
"color": "red",
999-
"value": 80
1000-
}
1001-
]
1002-
},
1003-
"unit": "milli-cores"
1004-
},
1005-
"overrides": []
1006-
},
1007-
"gridPos": {
1008-
"h": 7,
1009-
"w": 12,
1010-
"x": 12,
1011-
"y": 15
1012-
},
1013-
"id": 2788,
1014-
"links": [],
1015-
"options": {
1016-
"legend": {
1017-
"calcs": [],
1018-
"displayMode": "list",
1019-
"placement": "right",
1020-
"showLegend": true
1021-
},
1022-
"tooltip": {
1023-
"mode": "multi",
1024-
"sort": "none"
1025-
}
1026-
},
1027-
"pluginVersion": "9.1.1",
1028-
"targets": [
1029-
{
1030-
"datasource": null,
1031-
"editorMode": "code",
1032-
"format": "time_series",
1033-
"intervalFactor": 2,
1034-
"legendFormat": "scheduler-{{instance}}",
1035-
"metric": "",
1036-
"query": "from(bucket: v.bucket)\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"process_cpu_seconds_total\")\n |> filter(fn: (r) => r[\"url\"] =~ /tikv/)\n |> toInt()\n |> map(fn: (r) => ({ r with _value: r._value / 1000 }))\n |> keep(columns: [\"_time\", \"_value\", \"url\"])\n |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)\n |> yield(name: \"mean\")\n ",
1037-
"range": true,
1038-
"refId": "A",
1039-
"step": 4
1040-
},
1041-
{
1042-
"datasource": null,
1043-
"editorMode": "code",
1044-
"format": "time_series",
1045-
"intervalFactor": 2,
1046-
"legendFormat": "channelfull-{{instance}}-{{type}}",
1047-
"metric": "",
1048-
"query": "",
1049-
"range": true,
1050-
"refId": "B",
1051-
"step": 4
1052-
},
1053-
{
1054-
"datasource": null,
1055-
"editorMode": "code",
1056-
"format": "time_series",
1057-
"intervalFactor": 2,
1058-
"legendFormat": "coprocessor-{{instance}}",
1059-
"metric": "",
1060-
"range": true,
1061-
"refId": "C",
1062-
"step": 4
1063-
},
1064-
{
1065-
"datasource": null,
1066-
"editorMode": "code",
1067-
"format": "time_series",
1068-
"intervalFactor": 2,
1069-
"legendFormat": "stall-{{instance}}",
1070-
"range": true,
1071-
"refId": "D"
1072-
}
1073-
],
1074-
"title": "CPU",
1075-
"type": "timeseries"
1076950
}
1077951
],
1078952
"schemaVersion": 37,
@@ -1082,11 +956,6 @@
1082956
"list": [
1083957
{
1084958
"allValue": "",
1085-
"current": {
1086-
"selected": false,
1087-
"text": "http://drycc-storage-meta-tikv-0.drycc-storage-meta-tikv.drycc.svc.cluster.local:20180/metrics",
1088-
"value": "http://drycc-storage-meta-tikv-0.drycc-storage-meta-tikv.drycc.svc.cluster.local:20180/metrics"
1089-
},
1090959
"datasource": null,
1091960
"definition": "from(bucket: v.bucket)\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"_measurement\"] == \"tikv_engine_size_bytes\")\n |> filter(fn: (r) => r[\"_field\"] == \"gauge\")\n |> keyValues(keyColumns: [\"_value\"])\n |> duplicate(column: \"url\", as: \"_value\")\n |> group() \n |> keep(columns: [\"_value\"])\n ",
1092961
"hide": 0,

grafana/rootfs/usr/share/grafana/start-grafana

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
HEADER_CONTENT_TYPE="Content-Type: application/json"
55
HEADER_ACCEPT="Accept: application/json"
66

7+
NAMESPACE=${NAMESPACE:-drycc}
78
GRAFANA_USER=${DEFAULT_USER:-admin}
89
GRAFANA_PASSWD=${DEFAULT_USER_PASSWORD:-admin}
910
GRAFANA_PORT=${BIND_PORT:-3000}
@@ -102,6 +103,52 @@ curl -i -XPOST -H "${HEADER_ACCEPT}" -H "${HEADER_CONTENT_TYPE}" "http://${GRAFA
102103

103104
echo ""
104105
echo "Importing default dashboards..."
106+
# replace namespace
107+
# shellcheck disable=SC1003
108+
# shellcheck disable=SC2046
109+
sed -i 's@r\[\\"namespace\\\"\] == \\"drycc\\"@r\[\\"namespace\\"\] == \\"\'"${NAMESPACE}"'\\"@g' $(grep -F 'r[\"namespace\"] == \"drycc\"' -rl --include="*.json" "${DASHBOARD_LOCATION}")
110+
# drycc component dashboard
111+
DCD="${DASHBOARD_LOCATION}"/drycc_component_health.json
112+
113+
# remove off-cluster component panel
114+
if [ "on-cluster" != "${INFLUXDB_LOCATION}" ]; then
115+
rm -rf "${DASHBOARD_LOCATION}"/influx.json
116+
# shellcheck disable=SC2005
117+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "INFLUXDB"))')" > "${DCD}"
118+
fi
119+
if [ "on-cluster" != "${REDIS_LOCATION}" ]; then
120+
rm -rf "${DASHBOARD_LOCATION}"/redis.json
121+
# shellcheck disable=SC2005
122+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "REDIS"))')" > "${DCD}"
123+
fi
124+
if [ "on-cluster" != "${RABBITMQ_LOCATION}" ]; then
125+
# shellcheck disable=SC2005
126+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "RABBITMQ"))')" > "${DCD}"
127+
fi
128+
if [ "on-cluster" != "${DATABASE_LOCATION}" ]; then
129+
# shellcheck disable=SC2005
130+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "DATABASE"))')" > "${DCD}"
131+
fi
132+
if [ "on-cluster" != "${PASSPORT_LOCATION}" ]; then
133+
# shellcheck disable=SC2005
134+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "PASSPORT"))')" > "${DCD}"
135+
fi
136+
if [ "on-cluster" != "${REGISTRY_LOCATION}" ]; then
137+
# shellcheck disable=SC2005
138+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "REGISTRY"))')" > "${DCD}"
139+
# shellcheck disable=SC2005
140+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "REGISTRY-PROXY"))')" > "${DCD}"
141+
fi
142+
if [ "on-cluster" != "${STORAGE_LOCATION}" ]; then
143+
rm -rf "${DASHBOARD_LOCATION}"/pd.json "${DASHBOARD_LOCATION}"/tikv.json
144+
# shellcheck disable=SC2005
145+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "STORAGE-MINIO"))')" > "${DCD}"
146+
# shellcheck disable=SC2005
147+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "STORAGE-META-PD"))')" > "${DCD}"
148+
# shellcheck disable=SC2005
149+
echo "$(<"${DCD}" jq 'del(.dashboard.panels[] | select(.title == "STORAGE-META-TIKV"))')" > "${DCD}"
150+
fi
151+
105152
for filename in "${DASHBOARD_LOCATION}"/*.json; do
106153
echo "Importing ${filename} ..."
107154
curl -i -XPOST --data "@${filename}" -H "${HEADER_ACCEPT}" -H "${HEADER_CONTENT_TYPE}" "http://${GRAFANA_USER}:${GRAFANA_PASSWD}@localhost:${GRAFANA_PORT}/api/dashboards/db"

0 commit comments

Comments
 (0)