- Rename project from system-monitor to Tyto (barn owl themed) - Update Go module name and all import paths - Update Docker container names (tyto-backend, tyto-frontend) - Update localStorage keys (tyto-settings, tyto-hosts) - Create barn owl SVG favicon and PWA icons (192, 512) - Update header with owl logo icon - Update manifest.json and app.html with Tyto branding Named after Tyto alba, the barn owl — nature's silent, watchful guardian 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package collectors
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"tyto/internal/models"
|
|
)
|
|
|
|
type MemoryCollector struct {
|
|
procPath string
|
|
}
|
|
|
|
func NewMemoryCollector(procPath string) *MemoryCollector {
|
|
return &MemoryCollector{procPath: procPath}
|
|
}
|
|
|
|
func (c *MemoryCollector) Collect() (models.MemoryStats, error) {
|
|
stats := models.MemoryStats{}
|
|
|
|
file, err := os.Open(filepath.Join(c.procPath, "meminfo"))
|
|
if err != nil {
|
|
return stats, err
|
|
}
|
|
defer file.Close()
|
|
|
|
values := make(map[string]uint64)
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
|
line := scanner.Text()
|
|
fields := strings.Fields(line)
|
|
if len(fields) < 2 {
|
|
continue
|
|
}
|
|
|
|
key := strings.TrimSuffix(fields[0], ":")
|
|
value, _ := strconv.ParseUint(fields[1], 10, 64)
|
|
// Values in /proc/meminfo are in kB, convert to bytes
|
|
values[key] = value * 1024
|
|
}
|
|
|
|
stats.Total = values["MemTotal"]
|
|
stats.Available = values["MemAvailable"]
|
|
stats.Cached = values["Cached"]
|
|
stats.Buffers = values["Buffers"]
|
|
stats.SwapTotal = values["SwapTotal"]
|
|
stats.SwapFree = values["SwapFree"]
|
|
stats.SwapUsed = stats.SwapTotal - stats.SwapFree
|
|
|
|
// Calculate used memory (total - available is most accurate)
|
|
stats.Used = stats.Total - stats.Available
|
|
|
|
return stats, nil
|
|
}
|