func (n *DiskStats) Store() { n.lastTime = n.actualTime // no copy for map on "=" with GO for k, v := range n.actual { n.last[k] = v } diskStats, _ := linuxproc.ReadDiskStats("/proc/diskstats") for _, diskStat := range diskStats { device := diskStat.Name if strings.HasPrefix(device, "ram") { continue } if strings.HasPrefix(device, "loop") { continue } // store new value n.actual[device] = diskStat } n.actualTime = time.Now() }
func (ic iopsChecker) iops(name string) (uint64, error) { stats, err := linuxproc.ReadDiskStats(*hostPath + "/proc/diskstats") if err != nil { log.Fatalf("Cannot read disk stat info for %v\n", err) } for _, stat := range stats { if stat.Name == name { return stat.WriteIOs + stat.ReadIOs, nil } } return 0, fmt.Errorf("disk not found %v", name) }
func get_disk_stats_array() ([]linuxproc.DiskStat, error) { var used int stat, err := linuxproc.ReadDiskStats("/proc/diskstats") if err != nil { return nil, err } result := make([]linuxproc.DiskStat, len(stat)) used = 0 for i := range stat { if strings.Contains(stat[i].Name, "ram") == false && strings.Contains(stat[i].Name, "loop") == false { result[used] = stat[i] used++ } } return result[0:used], nil }
func InitAllHarddrives_Proc() ([]Harddrive, error) { DriveArray := []Harddrive{} a, err := linuxproc.ReadDiskStats("/proc/diskstats") if err != nil { log.Error(err.Error()) return nil, err } for i := 0; i < len(a); i++ { end := a[i].Name[len(a[i].Name)-1:] b, _ := utf8.DecodeRuneInString(end) if isnumber(b) == false { //HDD h := Harddrive{Path: "/dev/" + a[i].Name, Name: a[i].Name, Diskstat: a[i]} PartArray := []Partition{} counter2 := 1 for { if (i + counter2) >= len(a) { break } e := a[i+counter2].Name[len(a[i+counter2].Name)-1:] b, _ := utf8.DecodeRuneInString(e) if isnumber(b) == false { //HDD h.Part = PartArray break } if isnumber(b) == true { //Partition p := Partition{Number: e, Name: a[i+counter2].Name, Path: "/dev/" + a[i+counter2].Name, Diskstat: a[i+counter2]} PartArray = append(PartArray, p) } counter2 += 1 } DriveArray = append(DriveArray, h) } } return DriveArray, nil }
//Initalisiert Pc func (x *PCAll) Pc_Init_All() error { cpuinfo, err := linuxproc.ReadCPUInfo("/proc/cpuinfo") if err != nil { revel.ERROR.Print(err) return err } meminfo, err := linuxproc.ReadMemInfo("/proc/meminfo") if err != nil { revel.ERROR.Print(err) return err } diskinfo, err := linuxproc.ReadDiskStats("/proc/diskstats") if err != nil { revel.ERROR.Print(err) return err } netstat, err := linuxproc.ReadNetStat("/proc/net/netstat") if err != nil { revel.ERROR.Print(err) return err } netdev, err := linuxproc.ReadNetworkStat("/proc/net/dev") if err != nil { revel.ERROR.Print(err) return err } x.Cpuinfo = cpuinfo x.Meminfo = meminfo x.Diskstat = diskinfo x.Netstat = netstat x.Netdev = netdev return nil }