func DiskIOMetrics() (L []*model.MetricValue) { dsList, err := nux.ListDiskStats() if err != nil { log.Println(err) return } for _, ds := range dsList { if !ShouldHandleDevice(ds.Device) { continue } device := "device=" + ds.Device L = append(L, CounterValue("disk.io.read_requests", ds.ReadRequests, device)) L = append(L, CounterValue("disk.io.read_merged", ds.ReadMerged, device)) L = append(L, CounterValue("disk.io.read_sectors", ds.ReadSectors, device)) L = append(L, CounterValue("disk.io.msec_read", ds.MsecRead, device)) L = append(L, CounterValue("disk.io.write_requests", ds.WriteRequests, device)) L = append(L, CounterValue("disk.io.write_merged", ds.WriteMerged, device)) L = append(L, CounterValue("disk.io.write_sectors", ds.WriteSectors, device)) L = append(L, CounterValue("disk.io.msec_write", ds.MsecWrite, device)) L = append(L, CounterValue("disk.io.ios_in_progress", ds.IosInProgress, device)) L = append(L, CounterValue("disk.io.msec_total", ds.MsecTotal, device)) L = append(L, CounterValue("disk.io.msec_weighted_total", ds.MsecWeightedTotal, device)) } return }
func CheckCollector() { output := make(map[string]bool) _, procStatErr := nux.CurrentProcStat() _, listDiskErr := nux.ListDiskStats() ports, listeningPortsErr := nux.ListeningPorts() procs, psErr := nux.AllProcs() _, duErr := sys.CmdOut("du", "--help") output["kernel "] = len(KernelMetrics()) > 0 output["df.bytes"] = len(DeviceMetrics()) > 0 output["net.if "] = len(CoreNetMetrics([]string{})) > 0 output["loadavg "] = len(LoadAvgMetrics()) > 0 output["cpustat "] = procStatErr == nil output["disk.io "] = listDiskErr == nil output["memory "] = len(MemMetrics()) > 0 output["netstat "] = len(NetstatMetrics()) > 0 output["ss -s "] = len(SocketStatSummaryMetrics()) > 0 output["ss -tln "] = listeningPortsErr == nil && len(ports) > 0 output["ps aux "] = psErr == nil && len(procs) > 0 output["du -bs "] = duErr == nil for k, v := range output { status := "fail" if v { status = "ok" } fmt.Println(k, "...", status) } }
func UpdateDiskStats() error { dsList, err := nux.ListDiskStats() if err != nil { return err } dsLock.Lock() defer dsLock.Unlock() for i := 0; i < len(dsList); i++ { device := dsList[i].Device diskStatsMap[device] = [2]*nux.DiskStats{dsList[i], diskStatsMap[device][0]} } return nil }