I am trying to create a configmap for a Grafana datasource, using an instance of Grafana from the Kube-Prometheus-Stack helm chart https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack
I am aware for dashboards, you can create a configmap from a json file using the commands listed in this answer: stable/prometheus-operator - adding persistent grafana dashboards
wget https://raw.githubusercontent.com/percona/grafana-dashboards/master/dashboards/MongoDB_Overview.json
kubectl -n monitoring create cm grafana-mongodb-overview --from-file=MongoDB_Overview.json
kubectl -n monitoring label cm grafana-mongodb-overview grafana_dashboard=mongodb-overview
Can something similar be done for grafana datasources? I currently have a datasource.yaml which contains the following lines:
data:
datasource-PRF1-Prometheus.yaml: |-
apiVersion: 1
datasources:
- name: Test-Prometheus
type: prometheus
url: https://prometheus.url.net/
access: Server
isDefault: true
basicAuth: true
basicAuthPassword: password
basicAuthUser: admin
However, I am not able to import a datasource using it, even though it creates a configmap.
The default folder of the dashboard is /var/lib/grafana . If you navigate to the folder, you will find a file name grafana. db .
You can enable this by selecting the built in -- Mixed -- data source. When selected this will allow you to specify data source on a per query basis. This will, for example, allow you to plot metrics from different Graphite servers on the same Graph or plot data from Elasticsearch alongside data from Prometheus.
You can not have a single graph fetching data from two different data sources. Although you can query data with multiple queries but they are on same data source.
For you to load the data by grafana server component, you would need to set this in your metadata field grafana_datasource: "1"
.
For a configmap:
apiVersion: v1
kind: ConfigMap
metadata:
name: example-grafana-datasource
labels:
grafana_datasource: "1"
namespace: monitoring
data:
datasource.yaml: |-
apiVersion: 1
datasources:
- access: proxy
basicAuth: false
editable: false
isDefault: false
jsonData:
authType: credentials
defaultRegion: us-west-2
name: CloudWatch
type: cloudwatch
For a secret with the same label
apiVersion: v1
kind: Secret
metadata:
name: influx-grafana-datasource
labels:
grafana_datasource: "1"
namespace: monitoring
type: Opaque
stringData:
influxdatasource.yaml: |-
# config file version
apiVersion: 1
datasources:
- name: influxdb
type: influxdb
access: proxy
database: metrics_db
user: metrics_read_user
url: http://influx.example.com:8086/
jsonData:
timeInterval: "15s"
secureJsonData:
password: yourinfluxpassword
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With