# linux-exporter **Repository Path**: guanyong1/linux-exporter ## Basic Information - **Project Name**: linux-exporter - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-30 - **Last Updated**: 2026-04-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # linux-exporter 一个基于 Go 的主机指标 exporter,访问 `/metrics` 输出 Prometheus 可采集的指标。 当前已实现的指标: - 主机名和 IP:`linux_host_info{hostname,ip}` - CPU 核数:`linux_host_cpu_cores` - 内存使用率:`linux_host_memory_usage_percent` - 磁盘总大小:`linux_host_disk_total_gb{mountpoint,fstype}` - 磁盘已使用:`linux_host_disk_used_gb{mountpoint,fstype}` - 磁盘使用率:`linux_host_disk_usage_percent{mountpoint,fstype}` - 当前负载:`linux_host_load{period="1m|5m|15m"}` - 采集器状态:`linux_exporter_collector_up{collector}`、`linux_exporter_collector_scrape_error{collector}` ## 架构设计 ```text cmd/linux-exporter/main.go | +-- internal/collector/collector.go | | | +-- Collector 接口 | +-- Registry 注册中心 | +-- internal/collector/system/*.go | | | +-- HostCollector | +-- CPUCollector | +-- MemoryCollector | +-- DiskCollector | +-- LoadCollector | +-- internal/exporter/exporter.go | +-- 聚合所有业务采集器 +-- 转换为 Prometheus Metric +-- 暴露采集器 up/error 状态 ``` ## 扩展方式 新增指标时只需要 2 步: 1. 在 `internal/collector/system` 下新增一个采集器,实现 `collector.Collector` 接口。 2. 在 `cmd/linux-exporter/main.go` 中注册这个采集器。 示例: ```go type NetworkCollector struct{} func (c *NetworkCollector) Name() string { return "network" } func (c *NetworkCollector) Describe(ch chan<- *prometheus.Desc) {} func (c *NetworkCollector) Collect(ctx context.Context) ([]collector.Metric, error) { return nil, nil } ``` ## 运行方式 ```bash go run ./cmd/linux-exporter ``` 自定义监听地址: ```bash EXPORTER_LISTEN_ADDR=:9200 go run ./cmd/linux-exporter ``` 启动后访问: - `http://localhost:9200/` - `http://localhost:9200/metrics`