<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nithya15aa</title>
    <description>The latest articles on DEV Community by Nithya15aa (@nithya15aa).</description>
    <link>https://dev.to/nithya15aa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F733860%2Fd001a25d-6f76-4baf-bb40-3fe3a5c836dc.png</url>
      <title>DEV Community: Nithya15aa</title>
      <link>https://dev.to/nithya15aa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nithya15aa"/>
    <language>en</language>
    <item>
      <title>Automating Dashboard Import for Grafana Standalone Setup using Provisioning</title>
      <dc:creator>Nithya15aa</dc:creator>
      <pubDate>Tue, 11 Apr 2023 13:48:15 +0000</pubDate>
      <link>https://dev.to/nithya15aa/automating-dashboard-import-for-grafana-standalone-setup-using-provisioning-59ga</link>
      <guid>https://dev.to/nithya15aa/automating-dashboard-import-for-grafana-standalone-setup-using-provisioning-59ga</guid>
      <description>&lt;p&gt;As a DevOps engineer, I completely understand how manually importing dashboards can be a time-consuming task. Luckily, Grafana provides several ways to automate the process of importing dashboards.&lt;a href="https://rudimartinsen.com/2020/08/06/grafana-importing-dashboards/"&gt;manual import&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One way to automate the import process is through the use of Grafana’s API. Grafana’s API allows you to programmatically manage your Grafana instance, including importing dashboards. The API supports importing dashboards in JSON format, which means you can automate the entire process of importing dashboards using a script or another automation tool.While iterating through an entire folder to import dashboards using Ansible tasks can be a useful approach for automating dashboard imports, it can also require a lot of attention to detail and calculation to ensure the dashboard is imported correctly and that the directory structure is preserved in Grafana.What if it were as simple as placing the dashboard JSON files in the provisioning folder and letting Grafana handle the rest?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Grafana Provisioning?&lt;/strong&gt;&lt;br&gt;
Grafana Provisioning is the process of automating the setup and configuration of Grafana dashboards, data sources, and other settings. By using provisioning, you can easily deploy changes to multiple instances of Grafana, without having to manually make the same changes over and over again. Grafana provisioning is especially useful in environments where you have many instances of Grafana that need to be set up and maintained.&lt;/p&gt;

&lt;p&gt;Getting Started with Grafana Provisioning&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Prepare Your Configuration&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first step in Grafana provisioning is to prepare your configuration files. Grafana provisioning uses YAML files to define data sources, dashboards, and other settings. You can create these files manually.&lt;/p&gt;

&lt;p&gt;Here is the sample.yaml file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;`apiVersion: 1

providers:
  # &amp;lt;string&amp;gt; an unique provider name. Required
  - name: 'a unique provider name'
    # &amp;lt;int&amp;gt; Org id. Default to 1
    orgId: 1
    # &amp;lt;string&amp;gt; name of the dashboard folder.
    folder: ''
    # &amp;lt;string&amp;gt; folder UID. will be automatically generated if not specified
    folderUid: ''
    # &amp;lt;string&amp;gt; provider type. Default to 'file'
    type: file
    # &amp;lt;bool&amp;gt; disable dashboard deletion
    disableDeletion: false
    # &amp;lt;int&amp;gt; how often Grafana will scan for changed dashboards
    updateIntervalSeconds: 10
    # &amp;lt;bool&amp;gt; allow updating provisioned dashboards from the UI
    allowUiUpdates: false
    options:
      # &amp;lt;string, required&amp;gt; path to dashboard files on disk. Required when using the 'file' type
      path: "{{ dest_dashboard_path }}"
      # &amp;lt;bool&amp;gt; use folder names from filesystem to create folders in Grafana
      foldersFromFilesStructure: true`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace the dest_dashboard_path in the yaml with the path where you have stored your dashboard JSON files. You can choose the path according to your preference and file structure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Place your dashboards to dashboard path&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Default dest_dashboard_path is /var/lib/grafana/dashboards/&lt;br&gt;
Place your dashboards json files or directories in dest_dashboard_path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3: Configure Grafana&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Edit your Grafana configuration file (grafana.ini) to specify the location of your configuration directory. You can do this by adding the following lines to your configuration file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[provisioning]

#Enable provisioning

enabled = true

#Specify the location of the provisioning files

provisioning_path = /etc/grafana/provisioning
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;**&lt;br&gt;
Step 4: Restart Grafana**&lt;/p&gt;

&lt;p&gt;Finally, you’ll need to restart Grafana to load your configuration files. You can do this by running the following command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo systemctl restart grafana-server&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Once Grafana has restarted, it will automatically load your configuration files and apply any changes you’ve made.&lt;/p&gt;

&lt;p&gt;— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —&lt;/p&gt;

&lt;p&gt;Ansible tasks to automate grafana dashboard provisioning&lt;/p&gt;

&lt;p&gt;add below tasks to roles/grafana/tasks/main.yaml file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- name: " Copy Dashboards to grafana server"
  copy: 
    src: "{{ src_dashboard_path }}"
    dest: "{{ dest_dashboard_path }}"
    owner: grafana
    group: grafana
    mode: 0644

- name: " Copy dashboard provisioning config file"
  template:
    src: "sample.yaml"
    dest: "{{ provisioning_path }}"

- name: "Grafana configuration for provisioning"
  become: yes 
  ansible.builtin.lineinfile:
    path: "{{ gr_confFile }}/grafana.ini"
    line: |
      [provisioning]
      #Enable provisioning
      enabled = true
      #Specify the location of the provisioning files
      provisioning_path = /etc/grafana/provisioning
  notify: event_restart_grafana   

- name: "Grafana server started"
  service:
    name: grafana-server
    enabled: true
    state: started
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;keep dashboards in ‘grafana/files/’ folder&lt;/p&gt;

&lt;p&gt;your ‘group_vars/grafana’ variable file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;configFilePath: /etc/ #change according to your requirement
gr_confFile: "{{ configFilePath }}/grafana"
src_dashboard_path: "roles/grafana/files/"
dest_dashboard_path: /var/lib/grafana/dashboards/
provisioning_path: "{{ gr_confFile }}/provisioning/dashboards/"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Playbook can look like this: grafana.yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- hosts: grafana
  become: yes
  become_user: root
  become_method: sudo
  roles:
    - grafana
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;host file: hosts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[grafana]
xx.xx.xx.xx
#replace xx.xx.xx.xx with your host IP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and run ‘&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ansible-playbook -i hosts grafana.yaml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;’&lt;/p&gt;

&lt;p&gt;Once Grafana has restarted, it will automatically load your configuration files and apply any changes you’ve made. Congratulations, you’re now using Grafana provisioning!&lt;/p&gt;

</description>
      <category>grafanaprovisioning</category>
      <category>dashboardsimport</category>
      <category>ansible</category>
      <category>grafana</category>
    </item>
  </channel>
</rss>
