Skip to content

sureSundar/step

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

STEP System

A comprehensive system monitoring and event processing framework that generates STEP (Space, Time, Event, Psychology) messages for real-time system observability and analysis.

Overview

The STEP System consists of two main components:

  1. STEP Generator (step_generator.py) - Monitors Linux system activities and generates structured STEP messages
  2. STEP-BUS (step-bus.py, step-bus1.py) - Universal event bus architecture for receiving, routing, and distributing STEP messages

What are STEP Messages?

STEP messages are structured event notifications that capture four key dimensions:

  • Space: Where the event occurred (hostname, IP, location context)
  • Time: When the event happened (timestamps, duration)
  • Event: What happened (event type, description, metadata)
  • Psychology: Emotional context of the event (valence, intensity)

Example STEP Message

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "time": {
    "start": 1693872000000
  },
  "event": {
    "type": "system.cpu.high",
    "description": "CPU usage at 85%"
  },
  "space": {
    "hostname": "server01",
    "ip": "192.168.1.100",
    "cpu_percent": 85
  },
  "psychology": {
    "valence": -0.3,
    "intensity": 0.7
  }
}

Components

STEP Generator

The STEP Generator monitors various system activities and generates STEP messages in real-time:

Monitored Activities

  • CPU Usage: Alerts when CPU usage exceeds 80%
  • Memory Usage: Tracks memory consumption above 85%
  • Disk I/O: Monitors heavy disk read/write operations (>50MB)
  • Network Traffic: Detects high network activity (>10MB)
  • Process Management: Tracks process creation and termination
  • File System Events: Monitors file creation, deletion, and modification (requires pyinotify)
  • User Activity: Tracks active user sessions

Features

  • Multi-threaded monitoring for concurrent system observation
  • Psychology scoring for system stress indicators
  • Optional integration with STEP-BUS for centralized collection
  • Console output and remote publishing support

STEP-BUS

The STEP-BUS provides a universal event bus architecture for STEP message processing:

Core Features

  • Message Publishing: REST API for publishing STEP messages
  • Pattern-based Subscriptions: Subscribe to specific event types or patterns
  • WebSocket Support: Real-time message streaming
  • Message History: In-memory and Redis-backed message persistence
  • Query Interface: Historical message retrieval with pattern matching
  • Statistics: Real-time bus performance metrics

API Endpoints

  • POST /step - Publish a STEP message
  • POST /subscribe - Create subscription pattern
  • DELETE /subscribe/{id} - Remove subscription
  • GET /query - Query historical messages
  • GET /stats - Bus statistics
  • WS /ws - WebSocket subscription endpoint

Installation

Prerequisites

pip install psutil fastapi uvicorn websockets redis pydantic

Optional Dependencies

pip install pyinotify  # For file system monitoring on Linux

Usage

Running the STEP Generator

# Console output only
python step_generator.py

# With STEP-BUS integration
python step_generator.py --bus-url http://localhost:8080/step

Running the STEP-BUS

# Start the event bus server
python step-bus.py

The STEP-BUS will be available at:

Example Usage

Publishing STEP Messages

curl -X POST http://localhost:8080/step \
  -H "Content-Type: application/json" \
  -d '{
    "event": {"type": "custom.test", "description": "Test message"},
    "space": {"source": "api"},
    "psychology": {"valence": 0.5, "intensity": 0.3}
  }'

Querying Messages

curl "http://localhost:8080/query?limit=10"

WebSocket Subscription

const ws = new WebSocket('ws://localhost:8080/ws?pattern={"event":{"type":"system.cpu.high"}}');
ws.onmessage = function(event) {
    console.log('Received STEP:', JSON.parse(event.data));
};

Architecture

┌─────────────────┐    ┌──────────────┐    ┌─────────────────┐
│ STEP Generator  │───▶│   STEP-BUS   │───▶│   Subscribers   │
│ (System Monitor)│    │ (Event Bus)  │    │ (Applications)  │
└─────────────────┘    └──────────────┘    └─────────────────┘
         │                       │                    │
         ▼                       ▼                    ▼
┌─────────────────┐    ┌──────────────┐    ┌─────────────────┐
│ System Events   │    │   Message    │    │  Real-time      │
│ • CPU/Memory    │    │   History    │    │  Notifications  │
│ • Disk/Network  │    │   (Redis)    │    │  • WebSocket    │
│ • Processes     │    │              │    │  • Callbacks    │
│ • Files         │    │              │    │  • Dashboards   │
└─────────────────┘    └──────────────┘    └─────────────────┘

Configuration

STEP Generator Configuration

  • Monitoring thresholds can be adjusted in the source code
  • Custom event types can be added by extending the monitor methods
  • Psychology scoring can be customized for different event types

STEP-BUS Configuration

  • Redis URL: Configure Redis connection for message persistence
  • Message history limits: Adjust in-memory and Redis storage limits
  • WebSocket and REST API ports: Configurable in the main execution block

Use Cases

  1. System Monitoring: Real-time system health monitoring and alerting
  2. Performance Analysis: Historical system performance data analysis
  3. Anomaly Detection: Pattern-based detection of unusual system behavior
  4. Integration Testing: Event-driven testing and validation frameworks
  5. Observability: Comprehensive system observability and debugging
  6. Automation: Event-triggered automation and workflow systems

Psychology Scoring

The system includes emotional context through psychology scoring:

  • Valence: Emotional positivity (-1.0 negative to +1.0 positive)
  • Intensity: Emotional strength (0.0 low to 1.0 high)

This enables:

  • System "mood" tracking
  • Stress level monitoring
  • Intelligent alerting based on emotional context
  • Human-like interpretation of system states

Development

Adding Custom Monitors

Extend the LinuxStepGenerator class with new monitor methods:

def monitor_custom_metric(self):
    """Monitor custom system metric"""
    while self.running:
        # Your monitoring logic here
        if condition:
            step = self.create_step(
                "custom.metric.event",
                "Custom event description",
                {"custom_data": value},
                {"valence": 0.0, "intensity": 0.5}
            )
            self.publish_step(step)
        time.sleep(interval)

Custom Subscribers

Create custom STEP message processors:

def custom_handler(step_message):
    """Process incoming STEP messages"""
    if step_message.event.get("type") == "system.cpu.high":
        # Handle high CPU events
        send_alert(step_message)

# Subscribe to specific patterns
bus.subscribe({"event": {"type": "system.cpu.high"}}, custom_handler)

License

This project is open source and available under standard open source licensing terms.

Contributing

Contributions are welcome! Areas for improvement:

  • Additional system monitors
  • Enhanced pattern matching
  • Dashboard interfaces
  • Mobile notifications
  • Cloud integrations
  • Machine learning analysis

STEP System - Bringing consciousness to system monitoring

About

Space.Time.Event.Psychology

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages