Module grafana

Module grafana 

Source
Expand description

Copyright © 2025-2026 Wenze Wei. All Rights Reserved.

This file is part of DMSC. The DMSC project belongs to the Dunimd Team.

Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

§Grafana Integration Module

This module provides data structures for creating and managing Grafana dashboards and panels. It enables programmatic generation of Grafana dashboards with panels, queries, and layout information.

§Key Components

  • DMSCGridPos: Represents the grid position of a panel on a dashboard
  • DMSCGrafanaPanel: Represents a single Grafana panel with title, query, type, and position
  • DMSCGrafanaDashboard: Represents a Grafana dashboard with multiple panels

§Design Principles

  1. Serde Integration: All structs implement Serialize and Deserialize for easy JSON conversion
  2. Simple API: Easy-to-use methods for creating dashboards and adding panels
  3. Layout Support: Built-in support for Grafana’s grid layout system
  4. Extensible: Can be extended to support additional panel types and dashboard features
  5. Type Safety: Strongly typed structs for all Grafana components
  6. JSON Compatibility: Generates JSON that is compatible with Grafana’s API

§Usage

use dmsc::prelude::*;
 
fn example() -> DMSCResult<()> {
    // Create a new dashboard
    let mut dashboard = DMSCGrafanaDashboard::new("DMSC Metrics");
     
    // Create a panel
    let panel = DMSCGrafanaPanel {
        title: "Request Rate".to_string(),
        query: "rate(http_requests_total[5m])".to_string(),
        panel_type: "graph".to_string(),
        grid_pos: DMSCGridPos {
            h: 8,
            w: 12,
            x: 0,
            y: 0,
        },
    };
     
    // Add panel to dashboard
    dashboard.add_panel(panel)?;
     
    // Convert to JSON for Grafana API
    let json = dashboard.to_json()?;
    println!("Dashboard JSON: {}", json);
     
    Ok(())
}

Structs§

DMSCGrafanaDashboard
Grafana dashboard configuration
DMSCGrafanaDashboardGenerator
Grafana dashboard generator
DMSCGrafanaPanel
Grafana panel configuration
DMSCGrafanaTag
Grafana dashboard tag
DMSCGrafanaTarget
Grafana target configuration for data sources
DMSCGrafanaTimeRange
Grafana time range configuration
DMSCGridPos
Grafana grid position configuration