Add Prometheus with CLI


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.


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:

Hope that helps,


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:

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

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