grafana配置的Prometheus数据源点进去,默认是不可编辑修改的(编辑后无法保存),如何变为可修改?
case1:grafana使用外部数据库
保存以下文件到env.sh
db_host=`kubectl get cm -n ark-system ark.cmdb.app.tianjimon-prometheus.resource -o go-template='{{index .data "db.tianjimongrafana.host"}}'`
db_user=`kubectl get cm -n ark-system ark.cmdb.app.tianjimon-prometheus.resource -o go-template='{{index .data "db.tianjimongrafana.user"}}'`
db_name=`kubectl get cm -n ark-system ark.cmdb.app.tianjimon-prometheus.resource -o go-template='{{index .data "db.tianjimongrafana.name"}}'`
db_passwd=`kubectl get cm -n ark-system ark.cmdb.app.tianjimon-prometheus.resource -o go-template='{{index .data "db.tianjimongrafana.password"}}'`
db_port=`kubectl get cm -n ark-system ark.cmdb.app.tianjimon-prometheus.resource -o go-template='{{index .data "db.tianjimongrafana.port"}}'`
alias db2="mysql -h $db_host -u $db_user -D $db_name -P $db_port -p$db_passwd"
source env.sh
db2
mysql> update data_source set read_only=0 where type="prometheus" and name="Prometheus";
退出刷新grafana即可
case2:grafana使用本地数据库
如果以上命令无法登陆数据库(一般是敏捷版,或较老的企业版3.14、3.15版本),使用下面方式操作:
kubectl get cm -n monitoring tianjimon-prometheus-prome-grafana-datasource -oyaml
如果没有 readOnly: false,说明默认配置是只读的
找到grafana使用的pv所在机器
#kubectl get pvc -n monitoring | grep grafana
tianjimon-grafana Bound yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8 10Gi RWO yoda-lvm 108d
#kubectl get pv yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8 -oyaml
登陆机器,找到grafana所使用的本地数据库 grafana.db
#ssh a56c07002.cloud.c07.amtest11
#find /var/lib/kubelet | grep yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8
/var/lib/kubelet/plugins/kubernetes.io/csi/pv/yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8
/var/lib/kubelet/plugins/kubernetes.io/csi/pv/yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8/globalmount
/var/lib/kubelet/plugins/kubernetes.io/csi/pv/yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8/vol_data.json
/var/lib/kubelet/pods/4094ba34-4dbd-11ec-a799-a0369f98df9c/volumes/kubernetes.io~csi/yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8
/var/lib/kubelet/pods/4094ba34-4dbd-11ec-a799-a0369f98df9c/volumes/kubernetes.io~csi/yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8/mount
/var/lib/kubelet/pods/4094ba34-4dbd-11ec-a799-a0369f98df9c/volumes/kubernetes.io~csi/yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8/mount/grafana.db
#sqlite3 /var/lib/kubelet/pods/4094ba34-4dbd-11ec-a799-a0369f98df9c/volumes/kubernetes.io~csi/yoda-83f2d2d4-f8be-11eb-9e03-a0369f9365b8/mount/grafana.db
sqlite> update data_source set read_only=0 where type="prometheus" and name="Prometheus";
刷新grafana即可