Files
monitor/README.md
2025-12-07 18:21:12 +08:00

5.9 KiB
Raw Blame History

系统监控平台

一个基于Go语言开发的跨平台系统监控工具支持Linux和Windows操作系统提供实时的系统性能监控和数据可视化功能。

功能特性

监控代理Agent

  • 跨平台支持Linux和Windows操作系统
  • 系统资源监控
    • CPU使用率和负载
    • 内存使用情况
    • 磁盘空间和I/O
    • 网络流量和连接
  • 进程管理:实时进程列表和资源消耗
  • 硬件信息CPU型号、内存大小、磁盘详情、网络接口
  • 操作系统信息:版本、架构、完整名称
  • HTTP API:提供本地数据查询接口

后端服务Backend

  • 数据收集接收Agent上报的监控数据
  • 数据存储支持InfluxDB和MySQL数据库
  • Web界面:实时监控仪表盘
  • 图表可视化:系统资源趋势图
  • 设备管理:多设备监控和管理
  • API接口:提供数据查询和管理接口

系统架构

┌─────────────────┐       ┌─────────────────┐
│  Linux Agent    │──────▶│                 │
└─────────────────┘       │                 │
                          │  Backend Server │
┌─────────────────┐       │                 │
│ Windows Agent   │──────▶│                 │
└─────────────────┘       └─────────────────┘
                                │
                                ▼
┌─────────────────┐       ┌─────────────────┐
│   InfluxDB      │◀──────│   Web Console   │
└─────────────────┘       └─────────────────┘
                                │
                                ▼
┌─────────────────┐
│    MySQL        │
└─────────────────┘

安装部署

环境要求

  • Go 1.24+(用于编译)
  • InfluxDB 2.x用于时序数据存储
  • MySQL 8.x用于设备和配置存储

编译Agent

Linux Agent

cd /root/monitor/agent
go build -o agent main.go

Windows Agent

cd /root/monitor/agent-windows
go build -o agent-windows.exe main.go
# 或使用交叉编译
GOOS=windows GOARCH=amd64 go build -o agent-windows.exe main.go

编译Backend

cd /root/monitor/backend
go build -o monitor-server main.go

运行

Agent运行

Linux

./agent -server=http://your-backend-server:8080 -interval=10s

Windows

agent-windows.exe -server=http://your-backend-server:8080 -interval=10s

Backend运行

./monitor-server -config=config.json

使用说明

Web界面访问

访问 http://your-backend-server:8080 即可进入监控系统Web界面。

Agent API接口

获取系统指标

curl http://agent-host:8081/metrics

获取设备信息

curl http://agent-host:8081/info

获取进程列表

curl http://agent-host:8081/processes

配置说明

Agent配置

Agent支持通过命令行参数配置

-server    # 后端服务器地址
-interval  # 数据上报间隔
-port      # 本地API服务端口默认8081
-log-level # 日志级别debug, info, warn, error

Backend配置

Backend使用config.json配置文件

{
  "server": {
    "port": 8080,
    "host": "0.0.0.0"
  },
  "influxdb": {
    "url": "http://localhost:8086",
    "token": "your-token",
    "org": "monitor",
    "bucket": "metrics"
  },
  "mysql": {
    "host": "localhost",
    "port": 3306,
    "user": "root",
    "password": "password",
    "database": "monitor"
  }
}

项目结构

monitor/
├── agent/             # Linux监控代理
│   ├── main.go        # 主程序
│   ├── go.mod         # 依赖管理
│   └── agent          # 编译后的可执行文件
├── agent-windows/     # Windows监控代理
│   ├── main.go        # 主程序
│   ├── go.mod         # 依赖管理
│   └── agent-windows.exe # 编译后的可执行文件
└── backend/           # 后端服务
    ├── main.go        # 主程序
    ├── config/        # 配置模块
    ├── internal/      # 内部模块
    ├── static/        # Web静态文件
    └── monitor-server # 编译后的可执行文件

API文档

Agent API

GET /metrics

返回系统监控指标包括CPU、内存、磁盘、网络等信息。

GET /info

返回设备硬件和操作系统信息。

GET /processes

返回当前运行的进程列表。

Backend API

POST /api/v1/metrics

接收Agent上报的监控数据。

GET /api/v1/metrics/:device_id

获取指定设备的历史监控数据。

GET /api/v1/devices

获取所有注册设备列表。

开发计划

已实现功能

  • 跨平台AgentLinux/Windows
  • 系统资源监控
  • 硬件信息采集
  • 进程监控
  • HTTP API接口
  • Web界面可视化
  • 数据持久化存储

后期实现

  • 告警系统:基于阈值的系统告警
    • CPU/内存/磁盘使用率告警
    • 网络流量异常告警
    • 进程异常告警
    • 告警通知邮件、短信、Webhook
  • 历史数据查询和分析
  • 多用户权限管理
  • 集群监控支持
  • 容器监控集成
  • 数据导出和报表功能

技术栈

  • 语言Go 1.24+
  • Web框架原生http包
  • 数据库InfluxDB 2.x, MySQL 8.x
  • 前端HTML, CSS, JavaScript, Chart.js
  • 依赖管理Go Modules

贡献

欢迎提交Issue和Pull Request

许可证

MIT License