Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create grafana configmap for datasources?

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.

like image 653
dwlian Avatar asked Nov 11 '20 03:11

dwlian


People also ask

Where are Grafana datasources stored?

The default folder of the dashboard is /var/lib/grafana . If you navigate to the folder, you will find a file name grafana. db .

How do you use mixed datasource in Grafana?

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.

Can Grafana have multiple data sources?

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.


1 Answers

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
like image 64
nickhalden Avatar answered Oct 19 '22 18:10

nickhalden