Skip to content

Commit 10a8524

Browse files
committed
feat(monitor): add storage monitor
1 parent 081fc7d commit 10a8524

5 files changed

Lines changed: 146 additions & 96 deletions

File tree

charts/monitor/templates/_helpers.tmpl

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,99 @@ env:
9292
- name: "REGISTRY_LOCATION"
9393
value: {{ .Values.global.registryLocation }}
9494
{{- end }}
95+
96+
{{/* Generate monitor telegraf deployment envs */}}
97+
{{- define "telegraf.deployment.envs" }}
98+
env:
99+
- name: POD_NAMESPACE
100+
valueFrom:
101+
fieldRef:
102+
fieldPath: metadata.namespace
103+
{{- if eq .Values.global.influxdbLocation "off-cluster" }}
104+
- name: "INFLUXDB_URLS_V2"
105+
valueFrom:
106+
secretKeyRef:
107+
name: influxdb-creds
108+
key: url
109+
{{- else }}
110+
- name: "INFLUXDB_URLS_V2"
111+
value: "\"http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT)\""
112+
- name: "INFLUXDB_V2_INPUT_URLS"
113+
value: "\"http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT)/metrics\""
114+
- name: "ENABLE_INFLUXDB_V2_INPUT"
115+
value: "true"
116+
{{- end }}
117+
- name: "INFLUXDB_BUCKET"
118+
valueFrom:
119+
secretKeyRef:
120+
name: influxdb-creds
121+
key: bucket
122+
- name: "INFLUXDB_ORG"
123+
valueFrom:
124+
secretKeyRef:
125+
name: influxdb-creds
126+
key: org
127+
- name: "INFLUXDB_TOKEN"
128+
valueFrom:
129+
secretKeyRef:
130+
name: influxdb-creds
131+
key: token
132+
- name: "AGENT_QUIET"
133+
value: "true"
134+
- name: "AGENT_BUFFER_LIMIT"
135+
value: "100000"
136+
{{- if eq .Values.global.redisLocation "on-cluster" }}
137+
- name: DRYCC_REDIS_ADDRS
138+
valueFrom:
139+
secretKeyRef:
140+
name: redis-creds
141+
key: addrs
142+
- name: DRYCC_REDIS_PASSWORD
143+
valueFrom:
144+
secretKeyRef:
145+
name: redis-creds
146+
key: password
147+
{{- end }}
148+
{{- if eq .Values.global.storageLocation "on-cluster" }}
149+
- name: DRYCC_STORAGE_LOOKUP
150+
valueFrom:
151+
secretKeyRef:
152+
name: storage-creds
153+
key: lookup
154+
- name: DRYCC_STORAGE_HEALTH
155+
valueFrom:
156+
secretKeyRef:
157+
name: storage-creds
158+
key: health
159+
- name: DRYCC_STORAGE_BUCKET
160+
valueFrom:
161+
secretKeyRef:
162+
name: storage-creds
163+
key: builder-bucket
164+
- name: DRYCC_STORAGE_ENDPOINT
165+
valueFrom:
166+
secretKeyRef:
167+
name: storage-creds
168+
key: endpoint
169+
- name: DRYCC_STORAGE_ACCESSKEY
170+
valueFrom:
171+
secretKeyRef:
172+
name: storage-creds
173+
key: accesskey
174+
- name: DRYCC_STORAGE_SECRETKEY
175+
valueFrom:
176+
secretKeyRef:
177+
name: storage-creds
178+
key: secretkey
179+
- name: DRYCC_STORAGE_PD_ADDRS
180+
valueFrom:
181+
secretKeyRef:
182+
name: storage-meta-creds
183+
key: pd-addrs
184+
- name: DRYCC_STORAGE_TIKV_ADDRS
185+
valueFrom:
186+
secretKeyRef:
187+
name: storage-meta-creds
188+
key: tikv-addrs
189+
{{- end }}
190+
{{- end }}

charts/monitor/templates/monitor-telegraf-deployment.yaml

Lines changed: 6 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,11 @@ spec:
3838
- -v
3939
- -u
4040
- $(INFLUXDB_URLS_V2)
41-
env:
42-
{{- if eq .Values.global.influxdbLocation "off-cluster" }}
43-
- name: "INFLUXDB_URLS_V2"
44-
valueFrom:
45-
secretKeyRef:
46-
name: influxdb-creds
47-
key: url
48-
{{- else }}
49-
- name: "INFLUXDB_URLS_V2"
50-
value: "\"http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT)\""
51-
- name: "INFLUXDB_V2_INPUT_URLS"
52-
value: "\"http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT)/metrics\""
53-
- name: "ENABLE_INFLUXDB_V2_INPUT"
54-
value: "true"
55-
{{- end }}
41+
- -g
42+
- $(DRYCC_STORAGE_HEALTH)
43+
- -a
44+
- $(DRYCC_REDIS_ADDRS),$(DRYCC_STORAGE_PD_ADDRS),$(DRYCC_STORAGE_TIKV_ADDRS)
45+
{{- include "telegraf.deployment.envs" . | indent 8 }}
5646
containers:
5747
- name: drycc-monitor-telegraf
5848
image: {{.Values.telegraf.imageRegistry}}/{{.Values.telegraf.imageOrg}}/telegraf:{{.Values.telegraf.imageTag}}
@@ -67,65 +57,4 @@ spec:
6757
memory: {{.Values.telegraf.limitsMemory}}
6858
{{- end}}
6959
{{- end}}
70-
env:
71-
- name: POD_NAMESPACE
72-
valueFrom:
73-
fieldRef:
74-
fieldPath: metadata.namespace
75-
{{- if eq .Values.global.influxdbLocation "off-cluster" }}
76-
- name: "INFLUXDB_URLS_V2"
77-
valueFrom:
78-
secretKeyRef:
79-
name: influxdb-creds
80-
key: url
81-
{{- else }}
82-
- name: "INFLUXDB_URLS_V2"
83-
value: "\"http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT)\""
84-
- name: "INFLUXDB_V2_INPUT_URLS"
85-
value: "\"http://$(DRYCC_INFLUXDB_SERVICE_HOST):$(DRYCC_INFLUXDB_SERVICE_PORT)/metrics\""
86-
- name: "ENABLE_INFLUXDB_V2_INPUT"
87-
value: "true"
88-
{{- end }}
89-
- name: "INFLUXDB_BUCKET"
90-
valueFrom:
91-
secretKeyRef:
92-
name: influxdb-creds
93-
key: bucket
94-
- name: "INFLUXDB_ORG"
95-
valueFrom:
96-
secretKeyRef:
97-
name: influxdb-creds
98-
key: org
99-
- name: "INFLUXDB_TOKEN"
100-
valueFrom:
101-
secretKeyRef:
102-
name: influxdb-creds
103-
key: token
104-
- name: "AGENT_QUIET"
105-
value: "true"
106-
- name: "AGENT_BUFFER_LIMIT"
107-
value: "100000"
108-
{{- if eq .Values.global.redisLocation "on-cluster" }}
109-
- name: DRYCC_REDIS_ADDRS
110-
valueFrom:
111-
secretKeyRef:
112-
name: redis-creds
113-
key: addrs
114-
- name: DRYCC_REDIS_PASSWORD
115-
valueFrom:
116-
secretKeyRef:
117-
name: redis-creds
118-
key: password
119-
{{- end }}
120-
{{- if eq .Values.global.storageLocation "on-cluster" }}
121-
- name: PD_ADDRS
122-
valueFrom:
123-
secretKeyRef:
124-
name: storage-meta-creds
125-
key: pd-addrs
126-
- name: TIKV_ADDRS
127-
valueFrom:
128-
secretKeyRef:
129-
name: storage-meta-creds
130-
key: tikv-addrs
131-
{{- end }}
60+
{{- include "telegraf.deployment.envs" . | indent 8 }}

telegraf/rootfs/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ FROM registry.drycc.cc/drycc/base:bullseye
33
ENV DRYCC_UID=1001 \
44
DRYCC_GID=1001 \
55
DRYCC_HOME_DIR=/home/telegraf \
6+
MC_VERSION="2022.04.01.23.44.48" \
67
TELEGRAF_VERSION="1.23.4" \
78
ENVTPL_VERSION="1.0.0" \
89
JQ_VERSION="1.6"
@@ -12,7 +13,8 @@ RUN groupadd drycc --gid ${DRYCC_GID} \
1213

1314
COPY . /
1415

15-
RUN install-stack telegraf ${TELEGRAF_VERSION} \
16+
RUN install-stack mc ${MC_VERSION} \
17+
&& install-stack telegraf ${TELEGRAF_VERSION} \
1618
&& install-stack envtpl ${ENVTPL_VERSION} \
1719
&& install-stack jq ${JQ_VERSION} \
1820
&& rm -rf \

telegraf/rootfs/home/telegraf/config.toml.tpl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,20 @@
176176
urls = [{{ .INFLUXDB_V2_INPUT_URLS }}]
177177
{{ end }}
178178

179-
{{- if .PD_SERVERS }}
179+
{{- if .DRYCC_STORAGE_METRICS }}
180180
[[inputs.prometheus]]
181-
urls = {{ .PD_SERVERS }}
181+
urls = {{ .DRYCC_STORAGE_METRICS }}
182+
bearer_token_string = {{ .DRYCC_STORAGE_BEARER_TOKEN | quote }}
182183
{{ end }}
183184

184-
{{- if .TIKV_SERVERS }}
185+
{{- if .DRYCC_STORAGE_PD_SERVERS }}
185186
[[inputs.prometheus]]
186-
urls = {{ .TIKV_SERVERS }}
187+
urls = {{ .DRYCC_STORAGE_PD_SERVERS }}
188+
{{ end }}
189+
190+
{{- if .DRYCC_STORAGE_TIKV_SERVERS }}
191+
[[inputs.prometheus]]
192+
urls = {{ .DRYCC_STORAGE_TIKV_SERVERS }}
187193
{{ end }}
188194

189195
{{- if and .KUBERNETES_URL .ENABLE_KUBERNETES }}

telegraf/rootfs/home/telegraf/start-telegraf

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,43 @@ if [ -n "$DRYCC_REDIS_ADDRS" ]; then
4040
export REDIS_SERVERS
4141
fi
4242

43-
# pd servers
44-
if [ -n "$PD_ADDRS" ]; then
45-
PD_SERVERS=""
46-
for ADDR in $(echo "${PD_ADDRS}" | tr "," "\n")
43+
# storage minio servers
44+
if [ -n "$DRYCC_STORAGE_ENDPOINT" ]; then
45+
mc config host add storage \
46+
"${DRYCC_STORAGE_ENDPOINT}" \
47+
"${DRYCC_STORAGE_ACCESSKEY}" \
48+
"${DRYCC_STORAGE_SECRETKEY}" \
49+
--lookup "${DRYCC_STORAGE_LOOKUP}" \
50+
--api s3v4
51+
mc admin prometheus generate storage --insecure --json > ~/.mc/prometheus.json
52+
# shellcheck disable=SC2089
53+
DRYCC_STORAGE_METRICS=\[\"$DRYCC_STORAGE_ENDPOINT$(jq -r .metricsPath < ~/.mc/prometheus.json)\"\]
54+
DRYCC_STORAGE_BEARER_TOKEN=$(jq -r .bearerToken < ~/.mc/prometheus.json)
55+
# shellcheck disable=SC2090
56+
export DRYCC_STORAGE_METRICS
57+
export DRYCC_STORAGE_BEARER_TOKEN
58+
fi
59+
60+
# storage pd servers
61+
if [ -n "$DRYCC_STORAGE_PD_ADDRS" ]; then
62+
DRYCC_STORAGE_PD_SERVERS=""
63+
for ADDR in $(echo "${DRYCC_STORAGE_PD_ADDRS}" | tr "," "\n")
4764
do
48-
PD_SERVERS="\"$ADDR\", ${PD_SERVERS}"
65+
DRYCC_STORAGE_PD_SERVERS="\"$ADDR\", ${DRYCC_STORAGE_PD_SERVERS}"
4966
done
50-
PD_SERVERS=\["${PD_SERVERS::-2}"\]
51-
export PD_SERVERS
67+
DRYCC_STORAGE_PD_SERVERS=\["${DRYCC_STORAGE_PD_SERVERS::-2}"\]
68+
export DRYCC_STORAGE_PD_SERVERS
5269
fi
5370

54-
#tikv servers
55-
if [ -n "$TIKV_ADDRS" ]; then
56-
TIKV_SERVERS=""
57-
for ADDR in $(echo "${TIKV_ADDRS}" | tr "," "\n")
71+
# storage tikv servers
72+
if [ -n "$DRYCC_STORAGE_TIKV_ADDRS" ]; then
73+
DRYCC_STORAGE_TIKV_SERVERS=""
74+
for ADDR in $(echo "${DRYCC_STORAGE_TIKV_ADDRS}" | tr "," "\n")
5875
do
59-
TIKV_SERVERS="\"$ADDR\", ${TIKV_SERVERS}"
76+
DRYCC_STORAGE_TIKV_SERVERS="\"$ADDR\", ${DRYCC_STORAGE_TIKV_SERVERS}"
6077
done
61-
TIKV_SERVERS=\["${TIKV_SERVERS::-2}"\]
62-
export TIKV_SERVERS
78+
DRYCC_STORAGE_TIKV_SERVERS=\["${DRYCC_STORAGE_TIKV_SERVERS::-2}"\]
79+
export DRYCC_STORAGE_TIKV_SERVERS
6380
fi
6481

6582
echo "Building config.toml!"

0 commit comments

Comments
 (0)