tourze/server-node-bundle

提供服务器节点管理功能的Symfony包,包括SSH连接、节点状态监控、负载统计等功能

Installs: 571

Dependents: 4

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/server-node-bundle


README

English | 中文

Latest Version PHP Version Build Status License Code Coverage

A comprehensive server node management bundle for Symfony applications, providing server monitoring, SSH management, and traffic statistics.

Table of Contents

Features

  • Server Node Management: Complete CRUD operations for server nodes
  • SSH Connection Support: Secure SSH connection management with password or key authentication
  • Traffic Monitoring: Real-time monitoring of upload/download traffic and bandwidth
  • System Information: Automatic collection of server hardware and system information
  • Status Management: Track node status (online, offline, maintenance, etc.)
  • EasyAdmin Integration: Ready-to-use admin interface with tourze/easy-admin-menu-bundle
  • API Key Management: Secure API key generation and management
  • Multi-Country Support: Built-in support for international server locations

Installation

composer require tourze/server-node-bundle

Quick Start

Requirements

  • PHP 8.1+
  • Symfony 6.4+
  • Doctrine ORM 3.0+
  • EasyAdmin Bundle 4+

Configuration

1. Bundle Registration

Add the bundle to your config/bundles.php:

return [
    // ...
    ServerNodeBundle\ServerNodeBundle::class => ['all' => true],
];

2. Database Schema

Create the database table:

php bin/console doctrine:schema:update --force

Basic Usage

Creating a Server Node

use ServerNodeBundle\Entity\Node;
use ServerNodeBundle\Enum\NodeStatus;

$node = new Node();
$node->setName('Production Server 1');
$node->setSshHost('192.168.1.100');
$node->setSshPort(22);
$node->setSshUser('root');
$node->setSshPassword('your-password');
$node->setStatus(NodeStatus::ONLINE);
$node->setValid(true);

$entityManager->persist($node);
$entityManager->flush();

Repository Usage

use ServerNodeBundle\Repository\NodeRepository;

class YourService
{
    public function __construct(private NodeRepository $nodeRepository)
    {
    }
    
    public function getActiveNodes(): array
    {
        return $this->nodeRepository->findBy(['valid' => true]);
    }
    
    public function getOnlineNodes(): array
    {
        return $this->nodeRepository->findBy(['status' => NodeStatus::ONLINE]);
    }
}

Node Properties

The Node entity includes comprehensive server information:

  • Basic Info: Name, country, domain, SSH credentials
  • System Info: Hostname, OS version, kernel version, architecture
  • Hardware Info: CPU model, frequency, core count, virtualization tech
  • Network Info: Bandwidth, online IP, TCP congestion control
  • Traffic Stats: Total, upload, download flow statistics
  • Status: Current operational status and user count

Advanced Usage

Admin Interface

The bundle automatically provides admin menu integration when using tourze/easy-admin-menu-bundle. The menu includes:

  • Server Management
    • Server Nodes (with full CRUD operations)

Custom Node Status Handling

use ServerNodeBundle\Enum\NodeStatus;

// Check node status
if ($node->getStatus() === NodeStatus::OFFLINE) {
    // Handle offline node
    $this->logger->warning('Node is offline', ['node' => $node->getName()]);
}

// Update node status
$node->setStatus(NodeStatus::MAINTAIN);
$this->entityManager->flush();

SSH Connection Management

use ServerNodeBundle\Exception\SshConnectionException;

try {
    // Your SSH connection logic here
    $connection = $this->sshService->connect($node);
} catch (SshConnectionException $e) {
    $this->logger->error('SSH connection failed', [
        'node' => $node->getName(),
        'error' => $e->getMessage()
    ]);
}

API Reference

Node Status Enum

use ServerNodeBundle\Enum\NodeStatus;

// Available statuses
NodeStatus::INIT;           // 初始化
NodeStatus::ONLINE;         // 正常
NodeStatus::OFFLINE;        // 离线
NodeStatus::BANDWIDTH_OVER; // 流量用完
NodeStatus::MAINTAIN;       // 维护中

SSH Connection Exception

use ServerNodeBundle\Exception\SshConnectionException;

try {
    // SSH connection logic
} catch (SshConnectionException $e) {
    // Handle SSH connection errors
    echo $e->getMessage();
}

Security

This bundle handles sensitive information like SSH credentials. Please ensure:

  • Use environment variables for sensitive configuration
  • Enable proper access controls on admin interfaces
  • Regularly rotate SSH keys and passwords
  • Monitor access logs for unauthorized attempts

For security vulnerabilities, please email security@tourze.com instead of using the issue tracker.

Contributing

Please see CONTRIBUTING.md for details.

License

The MIT License (MIT). Please see License File for more information.