func (m *MemInfo) Update() error {
	m.mutex.Lock()
	defer m.mutex.Unlock()

	if m.updateInterval != nil {
		now := time.Now()
		if now.Before(m.lastUpdate.Add(*m.updateInterval)) {
			return nil // no need to update yet
		}
		m.lastUpdate = now
	}

	if m.Values == nil {
		m.Values = make(map[string]uint64)
	}

	var err error

	path := filepath.Join("/proc/meminfo")
	file, err := os.Open(path)
	defer file.Close()
	if err != nil {
		return err
	}

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		text := scanner.Text()

		n := strings.Index(text, ":")
		if n == -1 {
			continue
		}

		key := text[:n] // metric
		data := strings.Split(strings.Trim(text[(n+1):], " "), " ")
		if len(data) == 1 {
			value, err := strconv.ParseUint(data[0], 10, 64)
			if err != nil {
				continue
			}
			m.Values[key] = value
		} else if len(data) == 2 {
			if data[1] == "kB" {
				value, err := strconv.ParseUint(data[0], 10, 64)
				if err != nil {
					continue
				}
				m.Values[key] = value * 1024
			}
		}

	}
	return nil
}
// Update get fresh data from /proc/meminfo
Update get fresh data from /proc/meminfo
// Update get fresh data from / proc / meminfo
func (m *MemInfo) Update() error {
	m.mutex.Lock()
	defer m.mutex.Unlock()
	if m.updateInterval != nil {
		now := time.Now()
		if now.Before(m.lastUpdate.Add(*m.updateInterval)) {
			return nil 
		}
		m.lastUpdate = now
	}
	if m.Values == nil {
		m.Values = make(map[string]uint64)
	}
	var err error
	path := filepath.Join("/proc/meminfo")
	file, err := os.Open(path)
	defer file.Close()
	if err != nil {
		return err
	}
	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		text := scanner.Text()
		n := strings.Index(text, ":")
		if n == -1 {
			continue
		}
		key := text[:n] 
		data := strings.Split(strings.Trim(text[(n+1):], " "), " ")
		if len(data) == 1 {
			value, err := strconv.ParseUint(data[0], 10, 64)
			if err != nil {
				continue
			}
			m.Values[key] = value
		} else if len(data) == 2 {
			if data[1] == "kB" {
				value, err := strconv.ParseUint(data[0], 10, 64)
				if err != nil {
					continue
				}
				m.Values[key] = value * 1024
			}
		}
	}
	return nil
}
func ( m * MemInfo ) Update ( ) error { m . mutex . Lock ( ) defer m . mutex . Unlock ( ) if m . updateInterval != nil { now := time . Now ( ) if now . Before ( m . lastUpdate . Add ( * m . updateInterval ) ) { return nil } m . lastUpdate = now } if m . Values == nil { m . Values = make ( map [ string ] uint64 ) } var err error path := filepath . Join ( " " ) file , err := os . Open ( path ) defer file . Close ( ) if err != nil { return err } scanner := bufio . NewScanner ( file ) for scanner . Scan ( ) { text := scanner . Text ( ) n := strings . Index ( text , " " ) if n == - 1 { continue } key := text [ : n ] data := strings . Split ( strings . Trim ( text [ ( n + 1 ) : ] , " " ) , " " ) if len ( data ) == 1 { value , err := strconv . ParseUint ( data [ 0 ] , 10 , 64 ) if err != nil { continue } m . Values [ key ] = value } else if len ( data ) == 2 { if data [ 1 ] == " " { value , err := strconv . ParseUint ( data [ 0 ] , 10 , 64 ) if err != nil { continue } m . Values [ key ] = value * 1024 } } } return nil }
Update get fresh data from /proc/meminfo
Update get fresh data from / proc / meminfo
// no need to update yet // metric