aboutsummaryrefslogtreecommitdiff
path: root/libpod/info.go
diff options
context:
space:
mode:
authorumohnani8 <umohnani@redhat.com>2017-12-12 12:48:51 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-12-14 00:54:21 +0000
commit5330d3da7c07861bfca12c7e8197a17a7c6a1b39 (patch)
treee37ad654380f53bd3b7e4b7f46832f998233b347 /libpod/info.go
parent40f01d56aba23045d2c5077b2ea4e9f7fdfa3249 (diff)
downloadpodman-5330d3da7c07861bfca12c7e8197a17a7c6a1b39.tar.gz
podman-5330d3da7c07861bfca12c7e8197a17a7c6a1b39.tar.bz2
podman-5330d3da7c07861bfca12c7e8197a17a7c6a1b39.zip
Update kpod info to use new libpod api
Signed-off-by: umohnani8 <umohnani@redhat.com> Closes: #124 Approved by: mheon
Diffstat (limited to 'libpod/info.go')
-rw-r--r--libpod/info.go116
1 files changed, 116 insertions, 0 deletions
diff --git a/libpod/info.go b/libpod/info.go
new file mode 100644
index 000000000..8a77c2ab7
--- /dev/null
+++ b/libpod/info.go
@@ -0,0 +1,116 @@
+package libpod
+
+import (
+ "bytes"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "runtime"
+
+ "github.com/docker/docker/pkg/system"
+ "github.com/pkg/errors"
+)
+
+// InfoData holds the info type, i.e store, host etc and the data for each type
+type InfoData struct {
+ Type string
+ Data map[string]interface{}
+}
+
+// top-level "host" info
+func (r *Runtime) hostInfo() (map[string]interface{}, error) {
+ // lets say OS, arch, number of cpus, amount of memory, maybe os distribution/version, hostname, kernel version, uptime
+ info := map[string]interface{}{}
+ info["os"] = runtime.GOOS
+ info["arch"] = runtime.GOARCH
+ info["cpus"] = runtime.NumCPU()
+ mi, err := system.ReadMemInfo()
+ if err != nil {
+ return nil, errors.Wrapf(err, "error reading memory info")
+ }
+ // TODO this might be a place for github.com/dustin/go-humanize
+ info["MemTotal"] = mi.MemTotal
+ info["MemFree"] = mi.MemFree
+ info["SwapTotal"] = mi.SwapTotal
+ info["SwapFree"] = mi.SwapFree
+
+ kv, err := readKernelVersion()
+ if err != nil {
+ return nil, errors.Wrapf(err, "error reading kernet version")
+ }
+ info["kernel"] = kv
+
+ up, err := readUptime()
+ if err != nil {
+ return nil, errors.Wrapf(err, "error reading up time")
+ }
+ info["uptime"] = up
+
+ host, err := os.Hostname()
+ if err != nil {
+ return nil, errors.Wrapf(err, "error getting hostname")
+ }
+ info["hostname"] = host
+
+ return info, nil
+}
+
+// top-level "store" info
+func (r *Runtime) storeInfo() (map[string]interface{}, error) {
+ // lets say storage driver in use, number of images, number of containers
+ info := map[string]interface{}{}
+ info["GraphRoot"] = r.store.GraphRoot()
+ info["RunRoot"] = r.store.RunRoot()
+ info["GraphDriverName"] = r.store.GraphDriverName()
+ info["GraphOptions"] = r.store.GraphOptions()
+ statusPairs, err := r.store.Status()
+ if err != nil {
+ return nil, err
+ }
+ status := map[string]string{}
+ for _, pair := range statusPairs {
+ status[pair[0]] = pair[1]
+ }
+ info["GraphStatus"] = status
+ images, err := r.store.Images()
+ if err != nil {
+ return nil, errors.Wrapf(err, "error getting number of images")
+ }
+ info["ImageStore"] = map[string]interface{}{
+ "number": len(images),
+ }
+
+ containers, err := r.store.Containers()
+ if err != nil {
+ return nil, errors.Wrapf(err, "error getting number of containers")
+ }
+ info["ContainerStore"] = map[string]interface{}{
+ "number": len(containers),
+ }
+
+ return info, nil
+}
+
+func readKernelVersion() (string, error) {
+ buf, err := ioutil.ReadFile("/proc/version")
+ if err != nil {
+ return "", err
+ }
+ f := bytes.Fields(buf)
+ if len(f) < 2 {
+ return string(bytes.TrimSpace(buf)), nil
+ }
+ return string(f[2]), nil
+}
+
+func readUptime() (string, error) {
+ buf, err := ioutil.ReadFile("/proc/uptime")
+ if err != nil {
+ return "", err
+ }
+ f := bytes.Fields(buf)
+ if len(f) < 1 {
+ return "", fmt.Errorf("invalid uptime")
+ }
+ return string(f[0]), nil
+}