mirror of
https://github.com/jkstack/libagent.git
synced 2025-12-24 12:11:57 +08:00
修改注释
This commit is contained in:
@@ -5,37 +5,37 @@ import (
|
||||
"github.com/jkstack/agent/limit"
|
||||
)
|
||||
|
||||
// Configure common configure
|
||||
// Configure 基础配置
|
||||
type Configure struct {
|
||||
// agent id, if empty generate by server
|
||||
// $HOSTNAME: use agent id by hostname
|
||||
// $IP: use agent id by ip of connect server
|
||||
// ${env}: use envionment variables
|
||||
// agent id, 为空则为服务器端分配
|
||||
// $HOSTNAME: 使用当前主机名作为agent id
|
||||
// $IP: 使用连接到服务器端的网卡IP作为agent id
|
||||
// ${env}: 使用环境变量作为agent id
|
||||
ID string `json:"id" yaml:"id" kv:"id"`
|
||||
|
||||
// server address
|
||||
// server 服务器端地址,支持环境变量
|
||||
Server string `json:"server" yaml:"server" kv:"server"`
|
||||
|
||||
// logging config
|
||||
// 日志相关配置
|
||||
Log struct {
|
||||
// log targets, supported: stdout, file
|
||||
// 日志输出目标,支持stdout和file
|
||||
Target logTarget `json:"target" yaml:"target" kv:"target"`
|
||||
// log file path
|
||||
// 日志文件保存路径
|
||||
Dir string `json:"dir" yaml:"dir" kv:"dir"`
|
||||
// rotate size for file
|
||||
// 日志文件滚动生成时的文件大小
|
||||
Size utils.Bytes `json:"size" yaml:"size" kv:"size"`
|
||||
// rotate file count for save
|
||||
// 日志文件滚动生成时的保留数量
|
||||
Rotate int `json:"rotate" yaml:"rotate" kv:"rotate"`
|
||||
} `json:"log" yaml:"log" kv:"log"`
|
||||
|
||||
// monitor config
|
||||
// 监控配置
|
||||
Monitor struct {
|
||||
// enable report data
|
||||
// 是否启用监控数据上报
|
||||
Enabled bool `json:"enabled" yaml:"enabled" kv:"enabled"`
|
||||
// report interval
|
||||
// 监控数据上报间隔
|
||||
Interval utils.Duration `json:"interval" yaml:"interval" kv:"interval"`
|
||||
} `json:"monitor" yaml:"monitor" kv:"monitor"`
|
||||
|
||||
// limit config
|
||||
// 资源限制配置
|
||||
Limit limit.Configure `json:"limit" yaml:"limit" kv:"limit"`
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import (
|
||||
runtime "github.com/jkstack/jkframe/utils"
|
||||
)
|
||||
|
||||
// RewriteServer rewrite server configure
|
||||
// - use $... to set value by envionment variables
|
||||
// RewriteServer 重写服务器地址配置,每次连接时自动调用
|
||||
// - 当给定值以$开头则表示使用系统环境变量
|
||||
func (cfg *Configure) RewriteServer() {
|
||||
cfg.Server = strings.TrimSpace(cfg.Server)
|
||||
if len(cfg.Server) == 0 {
|
||||
@@ -30,10 +30,10 @@ func (cfg *Configure) RewriteServer() {
|
||||
}
|
||||
}
|
||||
|
||||
// RewriteID rewrite agent id configure
|
||||
// - use $IP to set value by ip address in interface to connect server
|
||||
// - use $HOSTNAME to set value by hostname
|
||||
// - use $... to set value by envionment variables
|
||||
// RewriteID 重写agent id配置,每次连接时自动调用
|
||||
// - $HOSTNAME: 使用当前主机名作为agent id
|
||||
// - $IP: 使用连接到服务器端的网卡IP作为agent id
|
||||
// - ${env}: 使用环境变量作为agent id
|
||||
func (cfg *Configure) RewriteID() {
|
||||
cfg.RewriteServer()
|
||||
cfg.ID = strings.TrimSpace(cfg.ID)
|
||||
@@ -64,7 +64,7 @@ func (cfg *Configure) RewriteID() {
|
||||
logging.Info("now agent id is %s", cfg.ID)
|
||||
}
|
||||
|
||||
// SetAgentID reset agent id by value
|
||||
// SetAgentID 重设当前agent id,当服务器端自动分配了新的agent id时被调用
|
||||
func (cfg *Configure) SetAgentID(id string) {
|
||||
cfg.ID = id
|
||||
}
|
||||
|
||||
@@ -88,14 +88,14 @@ func limitDiskV1(group cgroups.Cgroup, limits diskLimits) {
|
||||
return append(target, device)
|
||||
}
|
||||
if disk.ReadBytes > 0 {
|
||||
block.ThrottleReadBpsDevice = write(disk.ReadBytes, block.ThrottleReadBpsDevice)
|
||||
block.ThrottleReadBpsDevice = write(disk.ReadBytes.Bytes(), block.ThrottleReadBpsDevice)
|
||||
logging.Info(" - set read_bytes limit by dev [%s]: %s",
|
||||
disk.Dev, humanize.IBytes(disk.ReadBytes))
|
||||
disk.Dev, disk.ReadBytes.String())
|
||||
}
|
||||
if disk.WriteBytes > 0 {
|
||||
block.ThrottleWriteBpsDevice = write(disk.WriteBytes, block.ThrottleWriteBpsDevice)
|
||||
block.ThrottleWriteBpsDevice = write(disk.WriteBytes.Bytes(), block.ThrottleWriteBpsDevice)
|
||||
logging.Info(" - set write_bytes limit by dev [%s]: %s",
|
||||
disk.Dev, humanize.IBytes(disk.WriteBytes))
|
||||
disk.Dev, disk.WriteBytes.String())
|
||||
}
|
||||
if disk.ReadIOPS > 0 {
|
||||
block.ThrottleReadIOPSDevice = write(disk.ReadIOPS, block.ThrottleReadIOPSDevice)
|
||||
|
||||
@@ -73,14 +73,14 @@ func limitDiskV2(group *v2.Manager, limits diskLimits) {
|
||||
})
|
||||
}
|
||||
if disk.ReadBytes > 0 {
|
||||
write(v2.ReadBPS, disk.ReadBytes)
|
||||
write(v2.ReadBPS, disk.ReadBytes.Bytes())
|
||||
logging.Info(" - set read_bytes limit by dev [%s]: %s",
|
||||
disk.Dev, humanize.IBytes(disk.ReadBytes))
|
||||
disk.Dev, disk.ReadBytes.String())
|
||||
}
|
||||
if disk.WriteBytes > 0 {
|
||||
write(v2.WriteBPS, disk.WriteBytes)
|
||||
write(v2.WriteBPS, disk.WriteBytes.Bytes())
|
||||
logging.Info(" - set write_bytes limit by dev [%s]: %s",
|
||||
disk.Dev, humanize.IBytes(disk.WriteBytes))
|
||||
disk.Dev, disk.WriteBytes.Bytes())
|
||||
}
|
||||
if disk.ReadIOPS > 0 {
|
||||
write(v2.ReadIOPS, disk.ReadIOPS)
|
||||
|
||||
@@ -6,27 +6,27 @@ import (
|
||||
"github.com/jkstack/agent/internal/utils"
|
||||
)
|
||||
|
||||
// DiskLimit disk limit configure
|
||||
// DiskLimit 磁盘限制配置
|
||||
type DiskLimit struct {
|
||||
// device number of lsblk command eg: 8:0
|
||||
// 磁盘设备编号,可使用lsblk进行查询,如: 8:0
|
||||
Dev string `json:"dev" yaml:"dev" kv:"dev"`
|
||||
// read bytes
|
||||
ReadBytes uint64 `json:"read_bytes" yaml:"read_bytes" kv:"read_bytes"`
|
||||
// write bytes
|
||||
WriteBytes uint64 `json:"write_bytes" yaml:"write_bytes" kv:"write_bytes"`
|
||||
// read iops
|
||||
// 每秒读取字节数,为0表示不限制
|
||||
ReadBytes utils.Bytes `json:"read_bytes" yaml:"read_bytes" kv:"read_bytes"`
|
||||
// 每秒写入字节数,为0表示不限制
|
||||
WriteBytes utils.Bytes `json:"write_bytes" yaml:"write_bytes" kv:"write_bytes"`
|
||||
// 每秒并发读取次数,为0表示不限制
|
||||
ReadIOPS uint64 `json:"read_iops" yaml:"read_iops" kv:"read_iops"`
|
||||
// write iops
|
||||
// 每秒并发写入次数,为0表示不限制
|
||||
WriteIOPS uint64 `json:"write_iops" yaml:"write_iops" kv:"write_iops"`
|
||||
}
|
||||
|
||||
// Configure limit configure
|
||||
// Configure 资源限制配置
|
||||
type Configure struct {
|
||||
// cpu usage 100 means 1 core
|
||||
// CPU使用率限制,100表示1个核心
|
||||
CPUQuota int64 `json:"cpu_quota" yaml:"cpu_quota" kv:"cpu_quota"`
|
||||
// memory size limit in bytes
|
||||
// 内存使用限制
|
||||
Memory utils.Bytes `json:"memory_limit" yaml:"memory_limit" kv:"memory_limit"`
|
||||
// limit of disk
|
||||
// 磁盘限制
|
||||
Disks diskLimits `json:"disk_limit" yaml:"disk_limit" kv:"disk_limit"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user