Skip to content

Commit

Permalink
#2362
Browse files Browse the repository at this point in the history
  • Loading branch information
songlq committed Sep 2, 2024
1 parent e4b5e9f commit 5569c68
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
9 changes: 9 additions & 0 deletions internal/plugins/inputs/hostobject/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ type (
}
)

func (h *HostInfo) getDiskTotal() uint64 {
total := uint64(0)
for _, disk := range h.Disk {
total += disk.Total
}

return total
}

var collectorStatHist []*io.CollectorStatus

func getHostMeta() (*HostMetaInfo, error) {
Expand Down
32 changes: 18 additions & 14 deletions internal/plugins/inputs/hostobject/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,24 @@ func (ipt *Input) collect() error {

l.Debugf("messageData len: %d", len(messageData))

kvs = kvs.Add("message", string(messageData), false, true)
kvs = kvs.Add("start_time", message.Host.HostMeta.BootTime*1000, false, true)
kvs = kvs.Add("datakit_ver", datakit.Version, false, true)
kvs = kvs.Add("cpu_usage", message.Host.cpuPercent, false, true)
kvs = kvs.Add("mem_used_percent", message.Host.Mem.usedPercent, false, true)
kvs = kvs.Add("load", message.Host.load5, false, true)
kvs = kvs.Add("disk_used_percent", message.Host.diskUsedPercent, false, true)
kvs = kvs.Add("diskio_read_bytes_per_sec", message.Host.diskIOReadBytesPerSec, false, true)
kvs = kvs.Add("diskio_write_bytes_per_sec", message.Host.diskIOWriteBytesPerSec, false, true)
kvs = kvs.Add("net_recv_bytes_per_sec", message.Host.netRecvBytesPerSec, false, true)
kvs = kvs.Add("net_send_bytes_per_sec", message.Host.netSendBytesPerSec, false, true)
kvs = kvs.Add("logging_level", message.Host.loggingLevel, false, true)
kvs = kvs.Add("name", message.Host.HostMeta.HostName, true, true)
kvs = kvs.Add("os", message.Host.HostMeta.OS, true, true)
kvs = kvs.Add("message", string(messageData), false, true).
Add("start_time", message.Host.HostMeta.BootTime*1000, false, true).
Add("datakit_ver", datakit.Version, false, true).
Add("cpu_usage", message.Host.cpuPercent, false, true).
Add("mem_used_percent", message.Host.Mem.usedPercent, false, true).
Add("load", message.Host.load5, false, true).
Add("disk_used_percent", message.Host.diskUsedPercent, false, true).
Add("diskio_read_bytes_per_sec", message.Host.diskIOReadBytesPerSec, false, true).
Add("diskio_write_bytes_per_sec", message.Host.diskIOWriteBytesPerSec, false, true).
Add("net_recv_bytes_per_sec", message.Host.netRecvBytesPerSec, false, true).
Add("net_send_bytes_per_sec", message.Host.netSendBytesPerSec, false, true).
Add("logging_level", message.Host.loggingLevel, false, true).
AddTag("name", message.Host.HostMeta.HostName).
AddTag("os", message.Host.HostMeta.OS).
Add("num_cpu", len(message.Host.CPU), false, false).
AddTag("unicast_ip", message.Config.IP).
Add("disk_total", message.Host.getDiskTotal(), false, true).
AddTag("arch", message.Host.HostMeta.Arch)

if !datakit.IsTestMode {
kvs = kvs.Add("Scheck", message.Collectors[0].Version, false, true)
Expand Down
10 changes: 7 additions & 3 deletions internal/plugins/inputs/hostobject/measurement.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ func (*docMeasurement) Info() *inputs.MeasurementInfo {
Type: "object",
Desc: "Host object metrics",
Tags: map[string]interface{}{
"host": &inputs.TagInfo{Desc: "Hostname. Required."},
"name": &inputs.TagInfo{Desc: "Hostname"},
"os": &inputs.TagInfo{Desc: "Host OS type"},
"host": &inputs.TagInfo{Desc: "Hostname. Required."},
"unicast_ip": &inputs.TagInfo{Desc: "Host unicast ip"},
"name": &inputs.TagInfo{Desc: "Hostname"},
"os": &inputs.TagInfo{Desc: "Host OS type"},
"arch": &inputs.TagInfo{Desc: "Host OS Arch"},
},
Fields: map[string]interface{}{
"message": &inputs.FieldInfo{DataType: inputs.String, Unit: inputs.UnknownUnit, Desc: "Summary of all host information"},
"start_time": &inputs.FieldInfo{DataType: inputs.Int, Unit: inputs.DurationMS, Desc: "Host startup time (Unix timestamp)"},
"datakit_ver": &inputs.FieldInfo{DataType: inputs.String, Unit: inputs.UnknownUnit, Desc: "Collector version"},
"cpu_usage": &inputs.FieldInfo{Type: inputs.Gauge, DataType: inputs.Float, Unit: inputs.Percent, Desc: "CPU usage"},
"num_cpu": &inputs.FieldInfo{Type: inputs.Gauge, DataType: inputs.Int, Unit: inputs.NCount, Desc: "CPU numbers"},
"mem_used_percent": &inputs.FieldInfo{Type: inputs.Gauge, DataType: inputs.Float, Unit: inputs.Percent, Desc: "Memory usage"},
"load": &inputs.FieldInfo{Type: inputs.Gauge, DataType: inputs.Float, Unit: inputs.UnknownUnit, Desc: "System load"},
"disk_total": &inputs.FieldInfo{Type: inputs.Gauge, DataType: inputs.Int, Unit: inputs.SizeByte, Desc: "Disk total"},
"disk_used_percent": &inputs.FieldInfo{Type: inputs.Gauge, DataType: inputs.Float, Unit: inputs.Percent, Desc: "Disk usage"},
"diskio_read_bytes_per_sec": &inputs.FieldInfo{Type: inputs.Gauge, DataType: inputs.Int, Unit: inputs.BytesPerSec, Desc: "Disk read rate"},
"diskio_write_bytes_per_sec": &inputs.FieldInfo{Type: inputs.Gauge, DataType: inputs.Int, Unit: inputs.BytesPerSec, Desc: "Disk write rate"},
Expand Down

0 comments on commit 5569c68

Please sign in to comment.