watch-tool/models.go

151 lines
5.7 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"`
TopProcesses []ProcessInfo `json:"top_processes"`
OpenFileDescriptors int32 `json:"open_file_descriptors"`
DiskIOStats map[string]DiskIOStat `json:"disk_io_stats,omitempty"`
NetworkLatency map[string]LatencyInfo `json:"network_latency,omitempty"`
BandwidthUtilization map[string]BandwidthInfo `json:"bandwidth_utilization,omitempty"`
NetworkConnections ConnectionStats `json:"network_connections"`
TCPStats TCPStatistics `json:"tcp_stats"`
SystemLimits SystemLimitInfo `json:"system_limits"`
}
type DiskIOStat struct {
ReadBytes uint64 `json:"read_bytes"`
WriteBytes uint64 `json:"write_bytes"`
ReadOps uint64 `json:"read_ops"`
WriteOps uint64 `json:"write_ops"`
ReadTime uint64 `json:"read_time"`
WriteTime uint64 `json:"write_time"`
IOUtilization float64 `json:"io_utilization"`
AvgReadLatency float64 `json:"avg_read_latency"`
AvgWriteLatency float64 `json:"avg_write_latency"`
}
type LatencyInfo struct {
Host string `json:"host"`
MinLatency time.Duration `json:"min_latency"`
MaxLatency time.Duration `json:"max_latency"`
AvgLatency time.Duration `json:"avg_latency"`
PacketLoss float64 `json:"packet_loss"`
Jitter time.Duration `json:"jitter"`
}
type BandwidthInfo struct {
Interface string `json:"interface"`
CurrentThroughputIn float64 `json:"current_throughput_in_mbps"`
CurrentThroughputOut float64 `json:"current_throughput_out_mbps"`
PeakThroughputIn float64 `json:"peak_throughput_in_mbps"`
PeakThroughputOut float64 `json:"peak_throughput_out_mbps"`
UtilizationPercent float64 `json:"utilization_percent"`
}
type ConnectionStats struct {
TotalConnections int32 `json:"total_connections"`
EstablishedTCP int32 `json:"established_tcp"`
ListeningTCP int32 `json:"listening_tcp"`
TimeWaitTCP int32 `json:"time_wait_tcp"`
TransferConnections int32 `json:"transfer_connections"`
ConnectionsByState map[string]int32 `json:"connections_by_state"`
}
type LoadAverageInfo struct {
Load1 float64 `json:"load_1min"`
Load5 float64 `json:"load_5min"`
Load15 float64 `json:"load_15min"`
}
type TCPStatistics struct {
RetransmitRate float64 `json:"retransmit_rate"`
OutOfOrderPackets uint64 `json:"out_of_order_packets"`
LostPackets uint64 `json:"lost_packets"`
CongestionWindow uint64 `json:"congestion_window"`
TCPMemoryUsage uint64 `json:"tcp_memory_usage"`
}
type SystemLimitInfo struct {
MaxOpenFiles uint64 `json:"max_open_files"`
CurrentOpenFiles uint64 `json:"current_open_files"`
MaxProcesses uint64 `json:"max_processes"`
CurrentProcesses uint64 `json:"current_processes"`
MaxTCPConnections uint64 `json:"max_tcp_connections"`
CurrentTCPConnections uint64 `json:"current_tcp_connections"`
FileDescriptorUsage float64 `json:"file_descriptor_usage_percent"`
}
type DiskUsage struct {
Used uint64 `json:"used"`
Total uint64 `json:"total"`
UsedPercent float64 `json:"used_percent"`
Free uint64 `json:"free"`
}
type ProcessInfo struct {
PID int32 `json:"pid"`
Name string `json:"name"`
CPUPercent float64 `json:"cpu_percent"`
MemoryMB float32 `json:"memory_mb"`
Status string `json:"status"`
CreateTime int64 `json:"create_time"`
}
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),
DiskIOStats: make(map[string]DiskIOStat),
NetworkStats: make(map[string]NetworkStat),
NetworkLatency: make(map[string]LatencyInfo),
BandwidthUtilization: make(map[string]BandwidthInfo),
}
}