storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/sys/stats_netbsd.go (about) 1 //go:build netbsd 2 // +build netbsd 3 4 /* 5 * MinIO Cloud Storage, (C) 2020 MinIO, Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 package sys 21 22 import ( 23 "encoding/binary" 24 "syscall" 25 ) 26 27 func getHwPhysmem() (uint64, error) { 28 totalString, err := syscall.Sysctl("hw.physmem64") 29 if err != nil { 30 return 0, err 31 } 32 33 // syscall.sysctl() helpfully assumes the result is a null-terminated string and 34 // removes the last byte of the result if it's 0 :/ 35 totalString += "\x00" 36 37 total := uint64(binary.LittleEndian.Uint64([]byte(totalString))) 38 39 return total, nil 40 } 41 42 // GetStats - return system statistics for bsd. 43 func GetStats() (stats Stats, err error) { 44 stats.TotalRAM, err = getHwPhysmem() 45 return stats, err 46 }