Add Prometheus with CLI

Hello,

I would like to know if it is possible to add Prometheus as Data source via CLI and not via WEB UI.
I ask this question because I would like to automate the installation and configuration of these 2 tools through an ansible script.

Regards,

Yes, it is.

There are two ways to do it that I know of:

  1. Via the HTTP API:
  1. By creating a definition file and copying it to the Grafana server:

https://grafana.com/docs/grafana/latest/administration/provisioning/#datasources

Hope that helps,

Antony.

Thank you Anthony,

I think i will use the second m├ęthode ans if I understand right, i can declare the datasource via cli by editing the etc/grafana/grafana.ini file and add the bloc datasource (URL, user, password) ?

For example:

datasources:
  - name: Prometheus
    url: http://localhost:$PORT
    user: user1
    secureJsonData:
      password: 123456
...

Or i have to create this file and declare it in grafana.ini file ?