68 lines
2.2 KiB
Go
68 lines
2.2 KiB
Go
package main
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
type SystemResources struct {
|
|
Timestamp time.Time `json:"@timestamp"`
|
|
Type string `json:"type"`
|
|
Host string `json:"host"`
|
|
CPUPercent float64 `json:"cpu_percent,omitempty"`
|
|
MemoryUsed uint64 `json:"memory_used,omitempty"`
|
|
MemoryTotal uint64 `json:"memory_total,omitempty"`
|
|
MemoryPercent float64 `json:"memory_percent,omitempty"`
|
|
DiskUsage map[string]DiskUsage `json:"disk_usage,omitempty"`
|
|
NetworkStats map[string]NetworkStat `json:"network_stats,omitempty"`
|
|
LoadAverage []float64 `json:"load_average,omitempty"`
|
|
Uptime uint64 `json:"uptime,omitempty"`
|
|
}
|
|
|
|
type DiskUsage struct {
|
|
Used uint64 `json:"used"`
|
|
Total uint64 `json:"total"`
|
|
UsedPercent float64 `json:"used_percent"`
|
|
Free uint64 `json:"free"`
|
|
}
|
|
|
|
type NetworkStat struct {
|
|
BytesSent uint64 `json:"bytes_sent"`
|
|
BytesRecv uint64 `json:"bytes_recv"`
|
|
PacketsSent uint64 `json:"packets_sent"`
|
|
PacketsRecv uint64 `json:"packets_recv"`
|
|
}
|
|
|
|
type LogEntry struct {
|
|
Timestamp time.Time `json:"@timestamp"`
|
|
Type string `json:"type"`
|
|
Host string `json:"host"`
|
|
Tool string `json:"tool,omitempty"`
|
|
Service string `json:"service,omitempty"`
|
|
Message string `json:"message,omitempty"`
|
|
Fields map[string]any `json:"fields,omitempty"`
|
|
Raw string `json:"raw,omitempty"`
|
|
Priority string `json:"priority,omitempty"`
|
|
Unit string `json:"unit,omitempty"`
|
|
PID int `json:"pid,omitempty"`
|
|
BootID string `json:"boot_id,omitempty"`
|
|
MachineID string `json:"machine_id,omitempty"`
|
|
}
|
|
|
|
func NewLogEntry(entryType string) LogEntry {
|
|
return LogEntry{
|
|
Timestamp: time.Now(),
|
|
Type: entryType,
|
|
Host: hostname,
|
|
Fields: make(map[string]any),
|
|
}
|
|
}
|
|
|
|
func NewSystemResources() SystemResources {
|
|
return SystemResources{
|
|
Timestamp: time.Now(),
|
|
Type: "system_metrics",
|
|
Host: hostname,
|
|
DiskUsage: make(map[string]DiskUsage),
|
|
NetworkStats: make(map[string]NetworkStat),
|
|
}
|
|
}
|