diff --git a/internal/plugins/inputs/hostobject/info.go b/internal/plugins/inputs/hostobject/info.go index 695d0aa3ff..a69992d907 100644 --- a/internal/plugins/inputs/hostobject/info.go +++ b/internal/plugins/inputs/hostobject/info.go @@ -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) { diff --git a/internal/plugins/inputs/hostobject/input.go b/internal/plugins/inputs/hostobject/input.go index 2bcd820e4c..c9109746a0 100644 --- a/internal/plugins/inputs/hostobject/input.go +++ b/internal/plugins/inputs/hostobject/input.go @@ -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) diff --git a/internal/plugins/inputs/hostobject/measurement.go b/internal/plugins/inputs/hostobject/measurement.go index fa973e225b..657e57f65d 100644 --- a/internal/plugins/inputs/hostobject/measurement.go +++ b/internal/plugins/inputs/hostobject/measurement.go @@ -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"},