【发布时间】:2021-06-03 09:51:36
【问题描述】:
我已成功配置我的服务监视器以监视提供在 kubernetes pod 中运行的指标的 API。但是,我也想将外部服务添加到我的服务监视器目标中。此外部服务是 arangoDB oasis 导出器指标 (https://www.youtube.com/watch?v=c8i7K4HUPF4&t=554s)。并且此服务未在 kubernetes 容器中运行。以下是我关心的配置文件:
/helm/charts/prometheus-xxx/templates/service_monitor.tpl
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "jobs-manager-servicemonitor.fullname" . }}
# Change this to the namespace the jobs-manager-servicemonitor instance is running in
namespace: {{ .Values.serviceMonitor.namespace }}
labels:
serviceapp: {{ template "jobs-manager-servicemonitor.name" . }}
release: "{{ .Release.Name }}"
spec:
selector:
matchLabels:
# Targets jobs-manager service
app.kubernetes.io/instance: {{ .Values.instance.name }}
endpoints:
- port: {{ .Values.service.metricsPort.name }}
interval: {{ .Values.serviceMonitor.interval }}
{{- if .Values.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
{{- end }}
namespaceSelector:
matchNames:
- {{ .Values.Namespace }}
/helm/charts/prometheus-xxx/Chart.yaml
apiVersion: v1
appVersion: "1.0.0"
description: Prometheus Service monitor, customized
name: jobs-manager-servicemonitor
version: 1.0.1
/helm/charts/prometheus-xxx/templates/_helpers.tpl
{{/*
Expand the name of the chart.
*/}}
{{- define "jobs-manager-servicemonitor.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "jobs-manager-servicemonitor.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
/helm/charts/prometheus-xxx/values.yaml
serviceMonitor:
enabled: false
namespace: prometheus
interval: 10s
scrapeTimeout: 10s
service:
metricsPort:
name: http
instance:
name: jobs-manager
Namespace: test1
您对如何将不在 kubernetes pod 中运行的外部服务添加到服务监视器的目标有什么建议吗?非常感谢您。
---------更新后---------
这是我在图表模板arangodb-servicemonitor中的新配置文件:
/helm/charts/arangodb-servicemonitor/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: arangodb
namespace: prometheus
labels:
app: arangodb
release: prometheus
spec:
type: ClusterIP
externalName: xxxxx.arangodb.cloud:xxxx
ports:
- name: metrics
port: 9000
targetPort: 9000
protocol: TCP
- bearer_token: [ARANGODB_TOKEN]
type: ExternalName
/helm/charts/arangodb-servicemonitor/templates/endpoints.yaml
kind: Endpoints
apiVersion: v1
metadata:
name: arangodb
labels:
app: arangodb
subsets:
- addresses:
- ip: xxxxx.arangodb.cloud:xxxx
ports:
- name: metrics
port: 9000
protocol: TCP
/helm/charts/arangodb-servicemonitor/templates/service_monitor.tpl
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: arangodb-servicemonitor
# Change this to the namespace the arangodb-servicemonitor instance is running in
namespace: prometheus
labels:
serviceapp: arangodb-servicemonitor
release: prometheus
spec:
selector:
# Targets arangodb service
app: arangodb
endpoints:
# TO DO: use an array (List) of endpoints to monitor many endpoints
- port: metrics
interval: 30s
namespaceSelector:
matchNames:
# TO DO: use an array (List) of endpoints to monitor many endpoints
- default
但是当我执行terraform apply 时,我收到关于我添加的bearer_token 的错误消息:
有关信息,我需要添加此令牌以连接到 ArangoDB 外部服务:
【问题讨论】:
标签: service kubernetes-helm monitor prometheus-operator