{"id":29267657,"url":"https://github.com/tldr-devops/grafana-dashboards","last_synced_at":"2025-07-04T18:11:22.276Z","repository":{"id":302722613,"uuid":"1010359723","full_name":"tldr-devops/grafana-dashboards","owner":"tldr-devops","description":"Templates for generating Grafana Dashboards","archived":false,"fork":false,"pushed_at":"2025-07-03T21:43:34.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-03T22:28:37.781Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tldr-devops.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-28T22:44:59.000Z","updated_at":"2025-07-03T21:43:37.000Z","dependencies_parsed_at":"2025-07-03T22:39:01.038Z","dependency_job_id":null,"html_url":"https://github.com/tldr-devops/grafana-dashboards","commit_stats":null,"previous_names":["tldr-devops/grafana-dashboards"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tldr-devops/grafana-dashboards","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tldr-devops%2Fgrafana-dashboards","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tldr-devops%2Fgrafana-dashboards/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tldr-devops%2Fgrafana-dashboards/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tldr-devops%2Fgrafana-dashboards/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tldr-devops","download_url":"https://codeload.github.com/tldr-devops/grafana-dashboards/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tldr-devops%2Fgrafana-dashboards/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263594623,"owners_count":23485877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-04T18:11:20.294Z","updated_at":"2025-07-04T18:11:22.266Z","avatar_url":"https://github.com/tldr-devops.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Grafana Dashboards Generator\n\nA Python tool for building Grafana dashboards from Jinja2 templates and converting existing dashboards into reusable templates. This tool allows you to create dynamic, parameterized dashboards that can be easily maintained and deployed across different environments.\n\n## Features\n\n- **Template-based Dashboard Generation**: Create dashboards using Jinja2 templates with variables\n- **Multi-datasource Support**: Generate dashboards for different datasources (InfluxDB, Prometheus, etc.)\n- **Multiple Output Formats**: Export dashboards as JSON or YAML\n- **Dashboard Conversion**: Convert existing Grafana dashboards into reusable templates\n- **Flexible Configuration**: Configure outputs, datasources, and labels via YAML config\n\n## Installation\n\n### Requirements\n\n- Python 3.13+\n- Dependencies listed in `pyproject.toml`\n\n### Setup\n\n1. Clone the repository:\n```bash\ngit clone \u003crepository-url\u003e\ncd grafana-dashboards\n```\n\n2. Install dependencies:\n```bash\npip install -r requirements.txt\n# or if using pip directly:\npip install jinja2\u003e=3.1.6 pyyaml\u003e=6.0.2\n```\n\n## Usage\n\n### Building Templates\n\nGenerate dashboards from templates:\n\n```bash\npython3 builder.py build --config config.yml --templates templates --output output\n```\n\n**Parameters:**\n- `--config`: Configuration file path (default: `config.yml`)\n- `--templates`: Templates directory path (default: `templates`)\n- `--output`: Output directory path (default: `output`)\n\n### Converting Existing Dashboards\n\nConvert existing Grafana dashboards to templates:\n\n```bash\n# Convert JSON dashboard\npython3 builder.py convert --input dashboard.json --templates templates\n\n# Convert YAML dashboard\npython3 builder.py convert --input dashboard.yaml --templates templates\n```\n\n**Parameters:**\n- `--input`: Path to dashboard JSON or YAML file (required)\n- `--templates`: Templates directory path (default: `templates`)\n\n## Configuration\n\n### config.yml\n\n```yaml\noutput_format:\n  - json\n  - yaml\n\ndatasource:\n  - influxdb\n  - prometheus\n\nlabels:\n  - host\n  - name\n  - env\n  - namespace\n  - pod\n\ntarget:\n  - dashboards\n```\n\n**Configuration Options:**\n- `output_format`: List of output formats (`json`, `yaml`)\n- `datasource`: List of datasources to generate dashboards for\n- `labels`: List of labels/variables to use in templates\n- `target`: List of target types to generate (`dashboards`, `alerts`, etc.)\n\n## Template Structure\n\nTemplates are organized in numbered directories:\n\n```\ntemplates/\n├── 01_targets/          # Query targets/metrics\n│   ├── cpu_usage.yml.j2\n│   └── memory_usage.yml.j2\n├── 01_variables/        # Dashboard variables\n│   ├── hostname.yml.j2\n│   └── environment.yml.j2\n├── 01_inputs/           # Datasource inputs\n│   └── prometheus.yml.j2\n├── 02_panels/           # Individual panels\n│   ├── cpu_panel.yml.j2\n│   └── memory_panel.yml.j2\n├── 03_rows/             # Row panels\n│   └── system_metrics.yml.j2\n└── 04_dashboards/       # Complete dashboards\n    └── system_overview.yml.j2\n```\n\n### Template Syntax\n\nTemplates use `@{ }@` delimiters instead of `{{ }}` to avoid conflicts with Grafana variables:\n\n```yaml\n# Example panel template\ntitle: \"CPU Usage - @{ datasource }@\"\ntargets:\n  - expr: 'cpu_usage{@{ prom_labels(labels) }@}'\n    datasource: \"@{ datasource }@\"\n```\n\n### Available Template Functions\n\n- `prom_labels(labels)`: Generate Prometheus label selectors\n- `influx_labels(labels)`: Generate InfluxDB WHERE clauses\n- `to_nice_yaml`: Convert objects to formatted YAML\n\n### Template Variables\n\n- `datasource`: Current datasource being processed\n- `labels`: List of available labels\n- `targets`: Dictionary of rendered query targets\n- `variables`: Dictionary of rendered dashboard variables\n- `inputs`: Dictionary of rendered datasource inputs\n- `panels`: Dictionary of rendered panels\n- `rows`: Dictionary of rendered row panels\n- `dashboards`: Dictionary of rendered dashboards\n\n## Testing\n\nThe `builder.py` script has been tested with the popular [Node Exporter Full dashboard](https://grafana.com/grafana/dashboards/1860-node-exporter-full/) v41 from Grafana.com. This dashboard contains complex panels, variables, and queries that demonstrate the tool's capability to handle real-world Grafana dashboards.\n\n```\n❯ python3 builder.py convert --input node-exporter-full.json \n[✓] Converted node-exporter-full.json -\u003e templates\n\n❯ python3 builder.py build\n***\n[✓] Saved output/json/prometheus/dashboards/node_exporter_full.json\n[✓] Saved output/yaml/prometheus/dashboards/node_exporter_full.yaml\n\n❯ diff node-exporter-full.json output/json/prometheus/dashboards/node_exporter_full.json\n\n```\n\n### Test Example\n\n```bash\n# Download the Node Exporter Full dashboard\ncurl -o node-exporter-full.json \"https://grafana.com/api/dashboards/1860/revisions/41/download\"\n\n# Convert to templates\npython3 builder.py convert --input node-exporter-full.json --templates templates\n\n# Build back to dashboard\npython3 builder.py build --config config.yml --templates templates --output output\n```\n\n## Output Structure\n\nGenerated dashboards are organized by format, datasource, and target type:\n\n```\noutput/\n├── json/\n│   ├── prometheus/\n│   │   └── dashboards/\n│   │       └── system_overview.json\n│   └── influxdb/\n│       └── dashboards/\n│           └── system_overview.json\n└── yaml/\n    ├── prometheus/\n    │   └── dashboards/\n    │       └── system_overview.yaml\n    └── influxdb/\n        └── dashboards/\n            └── system_overview.yaml\n```\n\n## Examples\n\n### Creating a Simple Dashboard Template\n\n1. Create a query target template (`templates/01_targets/cpu_usage.yml.j2`):\n```yaml\nexpr: 'cpu_usage{@{ prom_labels(labels) }@}'\ndatasource: \"@{ datasource }@\"\nrefId: \"A\"\n```\n\n2. Create a panel template (`templates/02_panels/cpu_panel.yml.j2`):\n```yaml\ntitle: \"CPU Usage\"\ntype: \"graph\"\ntargets:\n  - @{ targets[\"cpu_usage\"] | to_nice_yaml | indent(4, false) }@\n```\n\n3. Create a dashboard template (`templates/04_dashboards/system.yml.j2`):\n```yaml\ntitle: \"System Dashboard - @{ datasource }@\"\npanels:\n  - @{ panels[\"cpu_panel\"] | to_nice_yaml | indent(4, false) }@\n```\n\n4. Build the dashboard:\n```bash\npython3 builder.py build\n```\n\n## License\n\nThis project is licensed under the MIT License. See the LICENSE file for details.\n\n## Troubleshooting\n\n### Common Issues\n\n1. **Template syntax errors**: Ensure you're using `@{ }@` delimiters, not `{{ }}`\n2. **Missing templates**: Check that all referenced templates exist in the correct directories\n3. **YAML parsing errors**: Validate your YAML syntax in template files\n4. **Permission errors**: Ensure the output directory is writable\n\n### Debug Mode\n\nAdd debug prints to see what's being processed:\n\n```python\n# Add to builder.py for debugging\nprint(f\"Processing template: {template_path}\")\nprint(f\"Context: {template_context}\")\n```\n\n## Version History\n\n- **v0.1.0**: Initial release with basic template building and conversion features\n- Tested with Node Exporter Full dashboard v41\n\n## Support\n\nFor issues and questions, please open an issue on the project repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftldr-devops%2Fgrafana-dashboards","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftldr-devops%2Fgrafana-dashboards","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftldr-devops%2Fgrafana-dashboards/lists"}