我知道可以用.json
格式的仪表板预加载Grafana的方法,但是不能通过唯一的仪表板ID参考来识别上述门户中所需的仪表板。
答案 0 :(得分:1)
让我们以仪表板 ID 11568 为例:
第 1 步:下载 .json
<块引用>curl https://grafana.com/api/dashboards/11568/revisions/1/download -o ~/Desktop/dashboard.json
第 2 步:将 .json 嵌入到配置映射中并标记它,以便 Grafana 仪表板边车容器将自动加载它。
<块引用>kubectl create configmap mydashboard --from-file=$HOME/Desktop/dashboard.json -n=monitoring --dry-run=client -o yaml | kubectl label -f - --dry-run=client -o yaml --local grafana_dashboard=1 > ~/Desktop/dashboard.yaml
第 3 步:将 configmap 包装在 gitops 自定义资源 Flux v2 CD 中作为示例
cp ~/Desktop/dashboard.yaml ~/Desktop/gitrepo/base/dashboard.yaml
temp="""
resources:
- dashboard.yaml
"""
echo "$temp" | tee ~/Desktop/gitrepo/base/kustomization.yaml
temp="""
apiVersion: source.toolkit.fluxcd.io/v1beta1
kind: GitRepository
metadata:
name: gitrepo
spec:
gitImplementation: go-git
ref:
branch: master
url: https://somegitrepo.com/somepath
---
apiVersion: kustomize.toolkit.fluxcd.io/v1beta1
kind: Kustomization
metadata:
name: gitops-deployment
spec:
interval: 1m
sourceRef:
kind: GitRepository
name: gitrepo
path: ./base
"""
echo "$temp" | tee -a ~/Desktop/gitrepo/deploy.yaml
上面的伪代码意味着如果你这样做了
<块引用>kubectl apply -f ~/Desktop/gitrepo/deploy.yaml
flux gitrepository CR 将使用引用它的 kustomization CR 创建,FluxCD 的 Kustomization 控制器将执行以下操作:
<块引用>cd ~/Desktop/gitrepo/base && kustomize build 。 && kubectl apply -f -
所以它基本上会做一个基于 gitops kustomization 的 configmap 部署,里面嵌入了一个 grafana 仪表板.json,并且在正确的命名空间中,带有正确的标签,这样 grafana 安装了 prometheus operator(带有自动加载仪表板的边车),将“以基础设施即代码方式”自动加载它
答案 1 :(得分:0)
Grafana可以下载这些仪表板(当然,它需要访问Internet)。 bash脚本示例:
#!/bin/bash
jq --version >/dev/null 2>&1 || { echo >&2 "I require jq but it's not installed. Aborting."; exit 1; }
### Please edit grafana_* variables to match your Grafana setup:
grafana_host="http://localhost:3000"
grafana_cred="admin:admin"
# Keep grafana_folder empty for adding the dashboards in "General" folder
grafana_folder="AWS CloudWatch"
ds=(1516 677 139 674 590 659 758 623 617 551 653 969 650 644 607 593 707 575 1519 581 584 2969 8050 11099 11154 11155 12979 13018 13040 13104);
folderId=$(curl -s -k -u "$grafana_cred" $grafana_host/api/folders | jq -r --arg grafana_folder "$grafana_folder" '.[] | select(.title==$grafana_folder).id')
if [ -z "$folderId" ] ; then echo "Didn't get folderId" ; else echo "Got folderId $folderId" ; fi
for d in "${ds[@]}"; do
echo -n "Processing $d: "
j=$(curl -s -k -u "$grafana_cred" $grafana_host/api/gnet/dashboards/$d | jq .json)
payload="{\"dashboard\":$j,\"overwrite\":true"
if [ ! -z "$folderId" ] ; then payload="${payload}, \"folderId\": $folderId }"; else payload="${payload} }" ; fi
curl -s -k -u "$grafana_cred" -XPOST -H "Accept: application/json" \
-H "Content-Type: application/json" \
-d "$payload" \
$grafana_host/api/dashboards/import; echo ""
done
来源:https://github.com/monitoringartist/grafana-aws-cloudwatch-dashboards
随时根据自己喜欢的语言和所需的仪表板进行修改。请记住,某些仪表板可能还需要输入变量。