如何使用头盔将自定义仪表板导入grafana

时间:2019-04-24 13:09:56

标签: kubernetes grafana kubernetes-helm configmap

我试图理解掌舵,我想知道是否有人可以向我提供一些帮助或帮助我。

所以我确实在下面跑了

helm repo add coreos https://s3-eu-west-1.amazonaws.com/coreos-charts/stable/

然后我使用以下命令安装了kube-prometheus:

helm install coreos/kube-prometheus --name kube-prometheus -f values.yaml --namespace monitoringtest

一切正常,但是我试图从json文件中添加一些自定义仪表板,而我正努力了解如何做到这一点。

我正在关注:https://blogcodevalue.wordpress.com/2018/09/16/automate-grafana-dashboard-import-process/

在我的values.yaml中,我在下面添加了

serverDashboardConfigmaps:
  - example-dashboards

我知道,如果我这样做:

helm upgrade --install kube-prometheus -f values.yaml --namespace monitoringtest coreos/kube-prometheus

这将导致grafana获取一个名为example-dashboards的配置文件,并从custom-dashboards文件夹中加载* .json文件。

apiVersion: v1
kind: ConfigMap
metadata:
  name: example-dashboards
data:
{{ (.Files.Glob "custom-dashboards/*.json").AsConfig | indent 2 }}

# Or
# 
# data:
#   custom-dashboard.json: |-
# {{ (.Files.Get "custom.json") | indent 4 }}
#
# The filename (and consequently the key under data) must be in the format `xxx-dashboard.json` or `xxx-datasource.json`
# for them to be picked up.

现在有两个问题:

如何将以上configmap添加到此头盔版本中?

custom-dashboards文件夹在哪里?是在我的笔记本电脑上,然后将其发送到grafana吗?

我需要将所有https://s3-eu-west-1.amazonaws.com/coreos-charts/stable/复制到笔记本电脑上吗?

很抱歉解释所有内容,但我只是想了解这一点。

3 个答案:

答案 0 :(得分:2)

我部分理解了。我可以从configmap加载仪表板。还没有来自单独的json文件,但这是一个进步。

对于感兴趣的人,我将其放在我的github页面上:https://github.com/tretos53/notes/blob/master/Grafana/Readme.MD

答案 1 :(得分:1)

您可以在此处为prometheus-operator的图表中找到如何执行此操作的好示例:

https://github.com/helm/charts/tree/master/stable/prometheus-operator/templates/grafana

这是一个ConfigMapList,可从给定目录中获取所有JSON,并将它们存储到由Grafana读取的ConfigMap中。

{{- $files := .Files.Glob "dashboards/*.json" }}
{{- if $files }}
apiVersion: v1
kind: ConfigMapList
items:
{{- range $path, $fileContents := $files }}
{{- $dashboardName := regexReplaceAll "(^.*/)(.*)\\.json$" $path "${2}" }}
- apiVersion: v1
  kind: ConfigMap
  metadata:
    name: {{ printf "%s-%s" (include "prometheus-operator.fullname" $) $dashboardName | trunc 63 | trimSuffix "-" }}
    namespace: {{ template "prometheus-operator.namespace" . }}
    labels:
      {{- if $.Values.grafana.sidecar.dashboards.label }}
      {{ $.Values.grafana.sidecar.dashboards.label }}: "1"
      {{- end }}
      app: {{ template "prometheus-operator.name" $ }}-grafana
{{ include "prometheus-operator.labels" $ | indent 6 }}
  data:
    {{ $dashboardName }}.json: {{ $.Files.Get $path | toJson }}
{{- end }}
{{- end }}

请注意,ConfigMap的大小可能受到限制: https://stackoverflow.com/a/53015758/4252480

答案 2 :(得分:0)

Helm图表是您打包和分发针对kubernetes的精选应用程序的方式,我认为您使用的是已弃用的图表。检查stable通道,如果您将其检出,则有几种导入仪表板的方法。

重要的是要了解图表是要使用的软件包,您当然可以对其进行扩展,添加自定义资源并为自己的存储库上传,甚至对上游有所贡献。

在运行时,只要您有更改要反映在您的环境中,就可以upgrade(应用更改)在已安装的图表上生效。对于grafana,存在具有仪表板内容的configmap的“ sidecar watcher”,如果您在稳定通道上单击提到的属性sidecar.dashboards.label=grafana_dashboard,则使sidecar可以监视kubernetes API上带有标签{{1}的任何configmap的事件}(注意grafana_dashboard的名称空间),只要configmap满足该条件,它将自动影响Grafana上的仪表板(添加/更改/删除...)

我也将Helm Architecture留给您,以获取有关概念的更多信息。

相关问题