|
|
|
@ -25,22 +25,23 @@ Usage
|
|
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/shirou/gopsutil"
|
|
|
|
|
"fmt"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main(){
|
|
|
|
|
v, _ := gopsutil.Virtual_memory()
|
|
|
|
|
|
|
|
|
|
// return value is struct
|
|
|
|
|
fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
|
|
|
|
|
|
|
|
|
|
// convert to JSON
|
|
|
|
|
d, _ := json.Marshal(v)
|
|
|
|
|
fmt.Printf("%s\n", d)
|
|
|
|
|
}
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
|
|
"github.com/shirou/gopsutil"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
v, _ := gopsutil.VirtualMemory()
|
|
|
|
|
|
|
|
|
|
// return value is struct
|
|
|
|
|
fmt.Printf("Total: %v, Free:%v, UsedPercent:%f%%\n", v.Total, v.Free, v.UsedPercent)
|
|
|
|
|
|
|
|
|
|
// convert to JSON
|
|
|
|
|
d, _ := json.Marshal(v)
|
|
|
|
|
fmt.Printf("%s\n", d)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
The output is below.
|
|
|
|
|
|
|
|
|
|