mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-11-04 07:49:35 +00:00 
			
		
		
		
	godep restore pushd $GOPATH/src/github.com/appc/spec git co master popd go get go4.org/errorutil rm -rf Godeps godep save ./... git add vendor git add -f $(git ls-files --other vendor/) git co -- Godeps/LICENSES Godeps/.license_file_state Godeps/OWNERS
		
			
				
	
	
		
			56 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			56 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package procfs
 | 
						|
 | 
						|
import (
 | 
						|
	"bufio"
 | 
						|
	"fmt"
 | 
						|
	"strconv"
 | 
						|
	"strings"
 | 
						|
)
 | 
						|
 | 
						|
// Stat represents kernel/system statistics.
 | 
						|
type Stat struct {
 | 
						|
	// Boot time in seconds since the Epoch.
 | 
						|
	BootTime int64
 | 
						|
}
 | 
						|
 | 
						|
// NewStat returns kernel/system statistics read from /proc/stat.
 | 
						|
func NewStat() (Stat, error) {
 | 
						|
	fs, err := NewFS(DefaultMountPoint)
 | 
						|
	if err != nil {
 | 
						|
		return Stat{}, err
 | 
						|
	}
 | 
						|
 | 
						|
	return fs.NewStat()
 | 
						|
}
 | 
						|
 | 
						|
// NewStat returns an information about current kernel/system statistics.
 | 
						|
func (fs FS) NewStat() (Stat, error) {
 | 
						|
	f, err := fs.open("stat")
 | 
						|
	if err != nil {
 | 
						|
		return Stat{}, err
 | 
						|
	}
 | 
						|
	defer f.Close()
 | 
						|
 | 
						|
	s := bufio.NewScanner(f)
 | 
						|
	for s.Scan() {
 | 
						|
		line := s.Text()
 | 
						|
		if !strings.HasPrefix(line, "btime") {
 | 
						|
			continue
 | 
						|
		}
 | 
						|
		fields := strings.Fields(line)
 | 
						|
		if len(fields) != 2 {
 | 
						|
			return Stat{}, fmt.Errorf("couldn't parse %s line %s", f.Name(), line)
 | 
						|
		}
 | 
						|
		i, err := strconv.ParseInt(fields[1], 10, 32)
 | 
						|
		if err != nil {
 | 
						|
			return Stat{}, fmt.Errorf("couldn't parse %s: %s", fields[1], err)
 | 
						|
		}
 | 
						|
		return Stat{BootTime: i}, nil
 | 
						|
	}
 | 
						|
	if err := s.Err(); err != nil {
 | 
						|
		return Stat{}, fmt.Errorf("couldn't parse %s: %s", f.Name(), err)
 | 
						|
	}
 | 
						|
 | 
						|
	return Stat{}, fmt.Errorf("couldn't parse %s, missing btime", f.Name())
 | 
						|
}
 |