This repository provides a utility to convert a Grafana dashboard JSON file into a React component that renders an EmbeddedScene using @grafana/scenes. The script parses panel configurations from the dashboard JSON and maps them to corresponding React components.
- Read Dashboard JSON: The script reads a Grafana dashboard JSON file.
- Parse Panels: It identifies supported panel types and generates corresponding React components.
- Generate Scene Component: It uses a template (
sceneTemplate.ts
) to structure the Scene. - Write Output: The generated component is saved as
GeneratedScene.tsx
which can then be used in a Grafana Scenes app.
- Clone the repository:
git clone [email protected]:cjdyer/grafana-dashboard-to-scenes.git cd grafana-dashboard-to-scenes
- Use correct node version:
nvm use OR nvm install
- Install dependencies:
npm install
Run the script with the example dashboard JSON file:
npm run generate:example
Run the script with a provided dashboard JSON file:
npx ts-node src/index.ts <JSON file path>
This will generate the GeneratedScene.tsx
file, which can be used in a Grafana plugin or project.
{
"panels": [
{
"type": "gauge",
"title": "CPU Usage",
"options": {"min": 0, "max": 100}
},
{
"type": "stat",
"title": "Memory Usage",
"options": {}
}
]
}
import React from 'react';
import { EmbeddedScene, SceneGridLayout } from '@grafana/scenes';
const CPUUsage = /* Generated gauge component */;
const MemoryUsage = /* Generated stat component */;
export default function GeneratedDashboard() {
const scene = new EmbeddedScene({
body: new SceneGridLayout({
children: [CPUUsage, MemoryUsage],
}),
});
return <scene.Component model={scene} />;
}
- Gauge Panel
- Stat Panel
- Table Panel
- Timeseries Panel