71 lines
1.7 KiB
Go
71 lines
1.7 KiB
Go
// Package model 定义采集模块的领域模型与指标命名规范。
|
|
package model
|
|
|
|
import "time"
|
|
|
|
// 指标组名称,用于标签 metric_group 与采集调度分组。
|
|
const (
|
|
GroupCore = "core" // 15s
|
|
GroupDisk = "disk" // 30s
|
|
GroupNetwork = "network" // 30s
|
|
GroupProcess = "process" // 60s
|
|
)
|
|
|
|
// 指标命名规范:<domain>.<metric>。
|
|
const (
|
|
MetricCPUUsage = "cpu.usage"
|
|
MetricMemUsedPercent = "mem.used_percent"
|
|
MetricLoad1m = "load.1m"
|
|
|
|
MetricDiskUsedPercent = "disk.used_percent"
|
|
MetricDiskIOReadBytes = "disk.io.read_bytes"
|
|
MetricDiskIOWriteBytes = "disk.io.write_bytes"
|
|
|
|
MetricNetBytesSent = "net.bytes_sent"
|
|
MetricNetBytesRecv = "net.bytes_recv"
|
|
MetricNetPktDrop = "net.pkt_drop"
|
|
|
|
MetricProcessCPU = "process.cpu"
|
|
MetricProcessMem = "process.mem"
|
|
MetricProcessCount = "process.count"
|
|
)
|
|
|
|
// 标签键。
|
|
const (
|
|
LabelHostID = "host_id"
|
|
LabelService = "service"
|
|
LabelMetricGroup = "metric_group"
|
|
)
|
|
|
|
// Sample 是采集模块内部的指标样本表示,与 protobuf MetricSample 保持一一对应。
|
|
type Sample struct {
|
|
Name string
|
|
Value float64
|
|
Timestamp int64
|
|
Labels map[string]string
|
|
}
|
|
|
|
// NewSample 构造一个携带基础标签的样本。
|
|
func NewSample(name string, value float64, at time.Time, labels map[string]string) Sample {
|
|
if labels == nil {
|
|
labels = map[string]string{}
|
|
}
|
|
return Sample{
|
|
Name: name,
|
|
Value: value,
|
|
Timestamp: at.Unix(),
|
|
Labels: labels,
|
|
}
|
|
}
|
|
|
|
// LogRecord 是采集模块内部的日志记录表示。
|
|
type LogRecord struct {
|
|
Timestamp int64
|
|
Level string
|
|
Source string
|
|
Message string
|
|
Fields map[string]string
|
|
File string
|
|
Offset int64
|
|
}
|