Skip to content

Commit 4ae2e93

Browse files
authored
Merge pull request #1 from Dev-Dami/dev-dami
``` feat: Add CONTRIBUTING, API, architecture, and modules docs ```
2 parents aa64321 + 11cc6a4 commit 4ae2e93

7 files changed

Lines changed: 686 additions & 24 deletions

File tree

CONTRIBUTING.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Contributing to gim
2+
3+
Thank you for your interest in contributing to gim! This document outlines the process and guidelines for contributing to the project.
4+
5+
## Project Overview
6+
7+
gim is a fast, high-performance, modular system metrics and diagnostics CLI tool written in Rust. It collects and displays system metrics like CPU, memory, disk, and network usage.
8+
9+
## Getting Started
10+
11+
1. Fork the repository
12+
2. Clone your fork: `git clone https://github.com/your-username/gim.git`
13+
3. Create a new branch: `git checkout -b feature/your-feature-name`
14+
4. Make your changes
15+
5. Test thoroughly
16+
6. Submit a pull request
17+
18+
## Development Setup
19+
20+
```bash
21+
# Install Rust if you don't have it
22+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
23+
24+
# Build the project
25+
cargo build
26+
27+
# Run the project
28+
cargo run
29+
30+
# Run tests
31+
cargo test
32+
33+
# Format code
34+
cargo fmt
35+
36+
# Check for linting issues
37+
cargo clippy
38+
```
39+
40+
## Project Structure
41+
42+
```
43+
src/
44+
├── lib.rs # Main application logic
45+
├── main.rs # Entry point
46+
├── cli/ # Command line interface parsing
47+
├── core/ # Core data structures and traits
48+
├── modules/ # Metric collection modules
49+
├── output/ # Output formatting logic
50+
└── tui/ # Terminal UI (planned future feature)
51+
```
52+
53+
## Adding New Modules
54+
55+
To add a new metric collection module:
56+
57+
1. Create a new file in `src/modules/` (e.g., `disk.rs`)
58+
2. Implement the `MetricCollector` trait
59+
3. Add the module to `src/modules/mod.rs`
60+
4. Register the module in the main function in `src/lib.rs`
61+
5. Update the CLI to accept your module as an argument (if needed)
62+
63+
Example module implementation:
64+
```rust
65+
use crate::core::{MetricCollector, MetricData, MetricValue};
66+
use std::collections::HashMap;
67+
68+
pub struct NewCollector {}
69+
70+
impl NewCollector {
71+
pub fn new() -> Self {
72+
NewCollector {}
73+
}
74+
}
75+
76+
impl MetricCollector for NewCollector {
77+
fn collect(&self) -> Result<MetricData, Box<dyn std::error::Error>> {
78+
let mut metrics = HashMap::new();
79+
80+
// Collect your metrics here
81+
metrics.insert("metric_name".to_string(), MetricValue::from(42));
82+
83+
Ok(MetricData {
84+
timestamp: std::time::SystemTime::now(),
85+
metrics,
86+
})
87+
}
88+
89+
fn name(&self) -> &'static str {
90+
"module_name"
91+
}
92+
}
93+
```
94+
95+
## Code Style
96+
97+
- Follow Rust idioms and best practices
98+
- Use `cargo fmt` to format code
99+
- Add documentation comments for public APIs
100+
- Write tests for new functionality
101+
- Keep functions focused and well-named
102+
103+
## Pull Request Guidelines
104+
105+
1. Describe your changes clearly in the PR description
106+
2. Include tests if adding new functionality
107+
3. Ensure all tests pass before submitting
108+
4. Link any relevant issues
109+
5. Keep PRs focused on a single feature or fix
110+
111+
## Questions?
112+
113+
If you have questions, feel free to open an issue or reach out to the maintainers.

README.md

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
# gim - GENERIC INFRASTRUCTURE MONITOR
22

3-
gmi-cli is a fast, high performance, modular system metrics and diagnostics CLI tool written in Rust.
3+
gim is a fast, high-performance, modular system metrics and diagnostics CLI tool written in Rust.
44

5-
# why - use cases
6-
- Monitoring system resources such as CPU, memory, disk usage, network traffic, and more.
7-
- Diagnosing issues with system performance and stability.
8-
- Gathering metrics for performance analysis and optimization.
9-
- Providing insights into system health and performance trends.
10-
- Automating routine tasks and alerts for system monitoring.
5+
## Features
116

12-
# planned features
13-
- CPU, memory, disk, and network metric collectors
14-
- Unified MetricCollector trait for easy module additions
15-
- JSON, table, and raw output modes
16-
- Optional ratatui-based live dashboard
17-
- JSON config support
7+
- **Modular Design**: Easy to extend with new metric collectors
8+
- **Multiple Output Formats**: JSON, table, and raw output modes
9+
- **Real-time Metrics**: CPU and memory usage statistics
10+
- **Clean Architecture**: Well-structured codebase for easy maintenance
1811

19-
# Build & Run
12+
## Use Cases
13+
14+
- Monitor system resources (CPU, memory, disk, network)
15+
- Diagnose performance issues
16+
- Gather metrics for analysis
17+
- Track system health trends
18+
19+
## Installation & Usage
20+
21+
### Build from Source
2022

2123
```bash
24+
# Clone the repository
25+
git clone https://github.com/your-repo/gim.git
26+
2227
# Build the project
23-
cargo build
28+
cargo build --release
2429

2530
# Run with default settings
2631
cargo run
@@ -35,16 +40,27 @@ cargo run -- --output raw
3540
cargo run -- --module cpu --output json
3641
```
3742

38-
# Current Features
39-
- CPU metric collection (usage, core count)
40-
- Memory metric collection (usage, available/free/used, swap)
41-
- Unified MetricCollector trait for modules
42-
- Multiple output formats (JSON, table, raw)
43-
- CLI argument parsing with clap
44-
- Basic architecture with core, modules, and output components
43+
## Current Capabilities
44+
45+
- **CPU Metrics**: Usage percentage, core count
46+
- **Memory Metrics**: Total, used, free, available memory and swap
47+
- **Output Options**: JSON, formatted table, or raw key-value pairs
48+
49+
## Planned Features
4550

46-
# Next Steps
4751
- Disk and network metric collectors
48-
- TUI dashboard implementation
52+
- TUI dashboard with ratatui
4953
- Configuration file support
5054
- Live monitoring capabilities
55+
56+
## Documentation
57+
58+
- [API Documentation](docs/api.md)
59+
- [Architecture](docs/architecture.md)
60+
- [Modules Guide](docs/modules.md)
61+
- [Extending Guide](docs/extending.md)
62+
- [Contributing](CONTRIBUTING.md)
63+
64+
## License
65+
66+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

docs/api.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# gim API Documentation
2+
3+
## Overview
4+
5+
gim is a modular system metrics collection library with a CLI interface. The API is designed to be extensible, allowing for new metric collectors to be easily added while maintaining a consistent interface.
6+
7+
## Core Components
8+
9+
### MetricCollector Trait
10+
11+
The `MetricCollector` trait is the core abstraction that all metric collection modules implement:
12+
13+
```rust
14+
pub trait MetricCollector {
15+
fn collect(&self) -> Result<MetricData, Box<dyn std::error::Error>>;
16+
fn name(&self) -> &'static str;
17+
}
18+
```
19+
20+
- `collect()`: Gathers metrics and returns them as `MetricData`
21+
- `name()`: Returns the identifier for the collector (e.g., "cpu", "memory")
22+
23+
### MetricData Structure
24+
25+
Represents the collected metrics with timestamp:
26+
27+
```rust
28+
pub struct MetricData {
29+
pub timestamp: std::time::SystemTime,
30+
pub metrics: HashMap<String, MetricValue>,
31+
}
32+
```
33+
34+
### MetricValue Enum
35+
36+
A flexible type to represent different metric value types:
37+
38+
```rust
39+
pub enum MetricValue {
40+
Integer(i64),
41+
Float(f64),
42+
String(String),
43+
Boolean(bool),
44+
List(Vec<MetricValue>),
45+
}
46+
```
47+
48+
## Available Modules
49+
50+
### CPU Collector
51+
52+
Collects CPU-related metrics:
53+
54+
- `cpu_usage_percent`: Average CPU usage percentage
55+
- `cpu_count`: Number of CPU cores
56+
- Memory-related metrics are also available (total, used, free, swap)
57+
58+
### Memory Collector
59+
60+
Collects memory-related metrics:
61+
62+
- `total_memory_bytes`: Total system memory in bytes
63+
- `used_memory_bytes`: Currently used memory in bytes
64+
- `free_memory_bytes`: Currently free memory in bytes
65+
- `available_memory_bytes`: Available memory for applications
66+
- `total_swap_bytes`, `used_swap_bytes`, `free_swap_bytes`: Swap memory metrics
67+
- `memory_usage_percent`: Memory usage percentage
68+
69+
## Output Formats
70+
71+
The system supports multiple output formats through the `OutputFormat` enum:
72+
73+
- `Table`: Formatted table with headers
74+
- `Json`: JSON output with timestamp and metrics
75+
- `Raw`: Raw key=value format
76+
77+
## CLI Interface
78+
79+
Command line arguments are handled by the `Cli` struct:
80+
81+
```rust
82+
pub struct Cli {
83+
pub module: Option<String>, // Module to run (cpu, memory, etc.)
84+
pub output: Option<String>, // Output format (json, table, raw)
85+
}
86+
```
87+
88+
### Usage Examples
89+
90+
```bash
91+
# Run with default modules and table output
92+
cargo run
93+
94+
# Run specific module
95+
cargo run -- --module cpu
96+
97+
# Use specific output format
98+
cargo run -- --output json
99+
100+
# Combine module and output format
101+
cargo run -- --module memory --output raw
102+
```
103+
104+
## Adding New Modules
105+
106+
To add a new metric collection module:
107+
108+
1. Create a struct that implements `MetricCollector`
109+
2. Implement the required methods (`collect` and `name`)
110+
3. Register the module in the main application logic
111+
4. Optionally add CLI support for the new module
112+
113+
## Library Functions
114+
115+
### `run()`
116+
117+
Main entry point that handles command parsing, module selection, and output formatting.
118+
119+
### `format_output(data: &MetricData, format: OutputFormat)`
120+
121+
Formats metric data according to the specified output format.

0 commit comments

Comments
 (0)