// Copyright 2017 The Prometheus Authors// Licensed under the Apache License, Version 2.0 (the "License");// you may not use this file except in compliance with the License.// You may obtain a copy of the License at//// http://www.apache.org/licenses/LICENSE-2.0//// Unless required by applicable law or agreed to in writing, software// distributed under the License is distributed on an "AS IS" BASIS,// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.// See the License for the specific language governing permissions and// limitations under the License.package procfsimport ()// A BuddyInfo is the details parsed from /proc/buddyinfo.// The data is comprised of an array of free fragments of each size.// The sizes are 2^n*PAGE_SIZE, where n is the array index.typeBuddyInfostruct { Node string Zone string Sizes []float64}// BuddyInfo reads the buddyinfo statistics from the specified `proc` filesystem.func ( FS) () ([]BuddyInfo, error) { , := os.Open(.proc.Path("buddyinfo"))if != nil {returnnil, }defer .Close()returnparseBuddyInfo()}func parseBuddyInfo( io.Reader) ([]BuddyInfo, error) {var ( = []BuddyInfo{} = bufio.NewScanner() = -1 )for .Scan() {varerror := .Text() := strings.Fields()iflen() < 4 {returnnil, fmt.Errorf("%w: Invalid number of fields, found: %v", ErrFileParse, ) } := strings.TrimSuffix([1], ",") := strings.TrimSuffix([3], ",") := len([4:])if == -1 { = } else {if != {returnnil, fmt.Errorf("%w: mismatch in number of buddyinfo buckets, previous count %d, new count %d", ErrFileParse, , ) } } := make([]float64, )for := 0; < ; ++ { [], = strconv.ParseFloat([+4], 64)if != nil {returnnil, fmt.Errorf("%w: Invalid valid in buddyinfo: %f: %w", ErrFileParse, [], ) } } = append(, BuddyInfo{, , }) }return , .Err()}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.