Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Contributing to gim

Thank you for your interest in contributing to gim! This document outlines the process and guidelines for contributing to the project.

## Project Overview

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.

## Getting Started

1. Fork the repository
2. Clone your fork: `git clone https://github.com/your-username/gim.git`
3. Create a new branch: `git checkout -b feature/your-feature-name`
4. Make your changes
5. Test thoroughly
6. Submit a pull request

## Development Setup

```bash
# Install Rust if you don't have it
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Build the project
cargo build

# Run the project
cargo run

# Run tests
cargo test

# Format code
cargo fmt

# Check for linting issues
cargo clippy
```

## Project Structure

```
src/
├── lib.rs # Main application logic
├── main.rs # Entry point
├── cli/ # Command line interface parsing
├── core/ # Core data structures and traits
├── modules/ # Metric collection modules
├── output/ # Output formatting logic
└── tui/ # Terminal UI (planned future feature)
```

## Adding New Modules

To add a new metric collection module:

1. Create a new file in `src/modules/` (e.g., `disk.rs`)
2. Implement the `MetricCollector` trait
3. Add the module to `src/modules/mod.rs`
4. Register the module in the main function in `src/lib.rs`
5. Update the CLI to accept your module as an argument (if needed)

Example module implementation:
```rust
use crate::core::{MetricCollector, MetricData, MetricValue};
use std::collections::HashMap;

pub struct NewCollector {}

impl NewCollector {
pub fn new() -> Self {
NewCollector {}
}
}

impl MetricCollector for NewCollector {
fn collect(&self) -> Result<MetricData, Box<dyn std::error::Error>> {
let mut metrics = HashMap::new();

// Collect your metrics here
metrics.insert("metric_name".to_string(), MetricValue::from(42));

Ok(MetricData {
timestamp: std::time::SystemTime::now(),
metrics,
})
}

fn name(&self) -> &'static str {
"module_name"
}
}
```

## Code Style

- Follow Rust idioms and best practices
- Use `cargo fmt` to format code
- Add documentation comments for public APIs
- Write tests for new functionality
- Keep functions focused and well-named

## Pull Request Guidelines

1. Describe your changes clearly in the PR description
2. Include tests if adding new functionality
3. Ensure all tests pass before submitting
4. Link any relevant issues
5. Keep PRs focused on a single feature or fix

## Questions?

If you have questions, feel free to open an issue or reach out to the maintainers.
64 changes: 40 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
# gim - GENERIC INFRASTRUCTURE MONITOR

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

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

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

# Build & Run
## Use Cases

- Monitor system resources (CPU, memory, disk, network)
- Diagnose performance issues
- Gather metrics for analysis
- Track system health trends

## Installation & Usage

### Build from Source

```bash
# Clone the repository
git clone https://github.com/your-repo/gim.git

# Build the project
cargo build
cargo build --release

# Run with default settings
cargo run
Expand All @@ -35,16 +40,27 @@ cargo run -- --output raw
cargo run -- --module cpu --output json
```

# Current Features
- CPU metric collection (usage, core count)
- Memory metric collection (usage, available/free/used, swap)
- Unified MetricCollector trait for modules
- Multiple output formats (JSON, table, raw)
- CLI argument parsing with clap
- Basic architecture with core, modules, and output components
## Current Capabilities

- **CPU Metrics**: Usage percentage, core count
- **Memory Metrics**: Total, used, free, available memory and swap
- **Output Options**: JSON, formatted table, or raw key-value pairs

## Planned Features

# Next Steps
- Disk and network metric collectors
- TUI dashboard implementation
- TUI dashboard with ratatui
- Configuration file support
- Live monitoring capabilities

## Documentation

- [API Documentation](docs/api.md)
- [Architecture](docs/architecture.md)
- [Modules Guide](docs/modules.md)
- [Extending Guide](docs/extending.md)
- [Contributing](CONTRIBUTING.md)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
121 changes: 121 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# gim API Documentation

## Overview

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.

## Core Components

### MetricCollector Trait

The `MetricCollector` trait is the core abstraction that all metric collection modules implement:

```rust
pub trait MetricCollector {
fn collect(&self) -> Result<MetricData, Box<dyn std::error::Error>>;
fn name(&self) -> &'static str;
}
```

- `collect()`: Gathers metrics and returns them as `MetricData`
- `name()`: Returns the identifier for the collector (e.g., "cpu", "memory")

### MetricData Structure

Represents the collected metrics with timestamp:

```rust
pub struct MetricData {
pub timestamp: std::time::SystemTime,
pub metrics: HashMap<String, MetricValue>,
}
```

### MetricValue Enum

A flexible type to represent different metric value types:

```rust
pub enum MetricValue {
Integer(i64),
Float(f64),
String(String),
Boolean(bool),
List(Vec<MetricValue>),
}
```

## Available Modules

### CPU Collector

Collects CPU-related metrics:

- `cpu_usage_percent`: Average CPU usage percentage
- `cpu_count`: Number of CPU cores
- Memory-related metrics are also available (total, used, free, swap)

### Memory Collector

Collects memory-related metrics:

- `total_memory_bytes`: Total system memory in bytes
- `used_memory_bytes`: Currently used memory in bytes
- `free_memory_bytes`: Currently free memory in bytes
- `available_memory_bytes`: Available memory for applications
- `total_swap_bytes`, `used_swap_bytes`, `free_swap_bytes`: Swap memory metrics
- `memory_usage_percent`: Memory usage percentage

## Output Formats

The system supports multiple output formats through the `OutputFormat` enum:

- `Table`: Formatted table with headers
- `Json`: JSON output with timestamp and metrics
- `Raw`: Raw key=value format

## CLI Interface

Command line arguments are handled by the `Cli` struct:

```rust
pub struct Cli {
pub module: Option<String>, // Module to run (cpu, memory, etc.)
pub output: Option<String>, // Output format (json, table, raw)
}
```

### Usage Examples

```bash
# Run with default modules and table output
cargo run

# Run specific module
cargo run -- --module cpu

# Use specific output format
cargo run -- --output json

# Combine module and output format
cargo run -- --module memory --output raw
```

## Adding New Modules

To add a new metric collection module:

1. Create a struct that implements `MetricCollector`
2. Implement the required methods (`collect` and `name`)
3. Register the module in the main application logic
4. Optionally add CLI support for the new module

## Library Functions

### `run()`

Main entry point that handles command parsing, module selection, and output formatting.

### `format_output(data: &MetricData, format: OutputFormat)`

Formats metric data according to the specified output format.
Loading