Skip to content

monobilisim/grafana-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors

Forks Stargazers Issues GPL License

Readme in English

gcli - Grafana API CLI Tool

gcli is a powerful Go-based command-line interface for interacting with the Grafana API. It allows you to manage multiple Grafana profiles, switch between organizations, and manage data sources with ease.


Implemented Features

  • Profile Management: Save multiple Grafana instances and switch between them.
  • Organization (Tenant) Management: List, create, delete, update, and switch active organizations.
  • Data Source Management: Full CRUD operations for data sources (List, Create, Read details, Update, Delete) with tabular output and interactive editing.
  • Dashboard Management: List, read, create (handles external templates with mapping), update (interactive editor), and delete dashboards.
  • Generic Requests: Make raw API calls to any Grafana endpoint.

Roadmap

Upcoming features and improvements:

  • Folder Management: Full control over dashboard folders.
  • User Management: Manage Grafana users via CLI.
  • Group/Team Management: Manage teams and permissions.
  • Improved Output Formats: More flexible output options (CSV, etc.).

Installation

Prerequisites

  • Go 1.20 or later

Build & Install

Clone the repository and run:

make install

This will generate the gcli binary, move it to /usr/local/bin, and set up auto-completion for your shell.

Usage

1. Configuration (gcli config)

Manage your Grafana API profiles.

  • Add a profile:
    ./gcli config add --name my-grafana --url https://grafana.example.com --user admin --pass secret
  • List profiles:
    ./gcli config list
  • Set active profile:
    ./gcli config use my-grafana

2. Organization Management (gcli org)

Manage organizations in the active Grafana profile.

  • List organizations:
    ./gcli org list
  • Select active organization:
    ./gcli org use "Main Org."
  • Create organization:
    ./gcli org create --name "New Org"
  • Delete organization:
    ./gcli org rm 12
  • Update organization:
    ./gcli org update 12 --name "New Name"

3. Dashboard Management (gcli dash)

Manage your Grafana dashboards.

  • List dashboards:
    ./gcli dash list
  • Read dashboard (extracts .dashboard field):
    ./gcli dash read <uid>
  • Export for sharing (external template):
    ./gcli dash read <uid> --external
  • Create dashboard (handles external templates with datasource mapping):
    ./gcli dash create --file dash.json
  • Update dashboard (interactive editor with retry logic):
    ./gcli dash update <uid>
  • Remove dashboard:
    ./gcli dash rm <uid>

4. Data Source Management (gcli ds)

Manage data sources in the active organization.

  • List data sources (tabular view):
    ./gcli ds list
  • List data sources (full JSON details):
    ./gcli ds list --details
  • Read data source details:
    ./gcli ds read "Prometheus"
  • Create data source (via flags):
    ./gcli ds create --name my-db --type graphite --url http://localhost:8080 --access proxy
  • Create data source (via file):
    ./gcli ds create --file ds.json
  • Update data source (interactive editor):
    # Opens your default $EDITOR with the current config
    ./gcli ds update my-db
  • Update data source (via file):
    ./gcli ds update my-db --file update.json
  • Remove data source:
    ./gcli ds rm my-db

4. Generic Request (gcli request)

Make any request to the active Grafana instance.

./gcli request GET /api/health

Configuration File

Profiles and active settings are stored in ~/.gcli/config.yaml.


About

Grafana CLI tool that uses Grafana API calls

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors