Skip to content

Commit 3790c91

Browse files
authored
Merge pull request #941 from HusterWan/zr/info-completion
feature: pouch info print information enhance
2 parents 36ad5cd + 8ef6ad4 commit 3790c91

File tree

6 files changed

+159
-41
lines changed

6 files changed

+159
-41
lines changed

apis/swagger.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,13 @@ definitions:
13171317
- "name=seccomp,profile=default"
13181318
- "name=selinux"
13191319
- "name=userns"
1320+
ListenAddresses:
1321+
description: "List of addresses the pouchd listens on"
1322+
type: "array"
1323+
items:
1324+
type: "string"
1325+
example:
1326+
- ["unix:///var/run/pouchd.sock", "tcp://0.0.0.0:4243"]
13201327

13211328
RegistryServiceConfig:
13221329
description: |

apis/types/system_info.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/info.go

Lines changed: 97 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"os"
7+
8+
"github.com/alibaba/pouch/apis/types"
69

710
"github.com/spf13/cobra"
811
)
@@ -47,44 +50,108 @@ func (v *InfoCommand) runInfo() error {
4750
return fmt.Errorf("failed to get system info: %v", err)
4851
}
4952

50-
v.cli.Print(result)
53+
return prettyPrintInfo(v.cli, result)
54+
}
55+
56+
func prettyPrintInfo(cli *Cli, info *types.SystemInfo) error {
57+
fmt.Fprintln(os.Stdout, "Containers:", info.Containers)
58+
fmt.Fprintln(os.Stdout, "Running:", info.ContainersRunning)
59+
fmt.Fprintln(os.Stdout, "Paused:", info.ContainersPaused)
60+
fmt.Fprintln(os.Stdout, "Stopped:", info.ContainersStopped)
61+
fmt.Fprintln(os.Stdout, "Images: ", info.Images)
62+
fmt.Fprintln(os.Stdout, "ID:", info.ID)
63+
fmt.Fprintln(os.Stdout, "Name:", info.Name)
64+
fmt.Fprintln(os.Stdout, "Server Version:", info.ServerVersion)
65+
fmt.Fprintln(os.Stdout, "Storage Driver:", info.Driver)
66+
fmt.Fprintln(os.Stdout, "Driver Status:", info.DriverStatus)
67+
fmt.Fprintln(os.Stdout, "Logging Driver:", info.LoggingDriver)
68+
fmt.Fprintln(os.Stdout, "Cgroup Driver:", info.CgroupDriver)
69+
if len(info.Runtimes) > 0 {
70+
fmt.Fprintln(os.Stdout, "Runtimes:")
71+
for name := range info.Runtimes {
72+
fmt.Fprintf(os.Stdout, "%s", name)
73+
}
74+
fmt.Fprint(os.Stdout, "\n")
75+
fmt.Fprintln(os.Stdout, "Default Runtime:", info.DefaultRuntime)
76+
}
77+
fmt.Fprintln(os.Stdout, "runc:", info.RuncCommit)
78+
fmt.Fprintln(os.Stdout, "containerd:", info.ContainerdCommit)
79+
80+
// Kernel info
81+
fmt.Fprintln(os.Stdout, "Security Options:", info.SecurityOptions)
82+
fmt.Fprintln(os.Stdout, "Kernel Version:", info.KernelVersion)
83+
fmt.Fprintln(os.Stdout, "Operating System:", info.OperatingSystem)
84+
fmt.Fprintln(os.Stdout, "OSType:", info.OSType)
85+
fmt.Fprintln(os.Stdout, "Architecture:", info.Architecture)
86+
87+
fmt.Fprintln(os.Stdout, "HTTP Proxy:", info.HTTPProxy)
88+
fmt.Fprintln(os.Stdout, "HTTPS Proxy:", info.HTTPSProxy)
89+
fmt.Fprintln(os.Stdout, "Registry:", info.IndexServerAddress)
90+
fmt.Fprintln(os.Stdout, "Experimental:", info.ExperimentalBuild)
91+
fmt.Fprintln(os.Stdout, "Debug:", info.Debug)
92+
fmt.Fprintln(os.Stdout, "Labels:", info.Labels)
93+
94+
fmt.Fprintln(os.Stdout, "CPUs:", info.NCPU)
95+
fmt.Fprintln(os.Stdout, "Total Memory:", info.MemTotal)
96+
fmt.Fprintln(os.Stdout, "Pouch Root Dir:", info.PouchRootDir)
97+
fmt.Fprintln(os.Stdout, "LiveRestoreEnabled:", info.LiveRestoreEnabled)
98+
if info.RegistryConfig != nil && (len(info.RegistryConfig.InsecureRegistryCIDRs) > 0 || len(info.RegistryConfig.IndexConfigs) > 0) {
99+
fmt.Fprintln(os.Stdout, "Insecure Registries:")
100+
for _, registry := range info.RegistryConfig.IndexConfigs {
101+
if !registry.Secure {
102+
fmt.Fprintln(os.Stdout, " "+registry.Name)
103+
}
104+
}
105+
106+
for _, registry := range info.RegistryConfig.InsecureRegistryCIDRs {
107+
fmt.Fprintf(os.Stdout, " %s\n", registry)
108+
}
109+
}
110+
111+
if info.RegistryConfig != nil && len(info.RegistryConfig.Mirrors) > 0 {
112+
fmt.Fprintln(os.Stdout, "Registry Mirrors:")
113+
for _, mirror := range info.RegistryConfig.Mirrors {
114+
fmt.Fprintln(os.Stdout, " "+mirror)
115+
}
116+
}
117+
118+
fmt.Fprintln(os.Stdout, "Daemon Listen Addresses:", info.ListenAddresses)
119+
51120
return nil
52121
}
53122

54123
// infoExample shows examples in info command, and is used in auto-generated cli docs.
55124
func infoExample() string {
56125
return `$ pouch info
126+
Containers: 1
127+
Running: 1
128+
Paused: 0
129+
Stopped: 0
130+
Images: 0
57131
ID:
58132
Name:
59-
OperatingSystem:
60-
PouchRootDir: /var/lib/pouch
61-
ServerVersion: 0.3-dev
62-
ContainersRunning: 0
63-
Debug: false
64-
DriverStatus: []
65-
Labels: []
66-
Containers: 0
67-
DefaultRuntime: runc
68-
Driver:
69-
ExperimentalBuild: false
70-
KernelVersion: 3.10.0-693.11.6.el7.x86_64
71-
OSType: linux
72-
CgroupDriver:
73-
ContainerdCommit: <nil>
74-
ContainersPaused: 0
75-
LoggingDriver:
76-
SecurityOptions: []
77-
NCPU: 0
78-
RegistryConfig: <nil>
79-
RuncCommit: <nil>
80-
ContainersStopped: 0
81-
HTTPSProxy:
82-
IndexServerAddress: https://index.docker.io/v1/
83-
LiveRestoreEnabled: false
84-
Runtimes: map[]
133+
Server Version: 0.3-dev
134+
Storage Driver:
135+
Driver Status: []
136+
Logging Driver:
137+
Cgroup Driver:
138+
runc: <nil>
139+
containerd: <nil>
140+
Security Options: []
141+
Kernel Version: 3.10.0-693.17.1.el7.x86_64
142+
Operating System:
143+
OSType: linux
85144
Architecture:
86-
HTTPProxy:
87-
Images: 0
88-
MemTotal: 0
145+
HTTP Proxy:
146+
HTTPS Proxy:
147+
Registry: https://index.docker.io/v1/
148+
Experimental: false
149+
Debug: true
150+
Labels: []
151+
CPUs: 0
152+
Total Memory: 0
153+
Pouch Root Dir: /var/lib/pouch
154+
LiveRestoreEnabled: false
155+
Daemon Listen Addresses: [unix:///var/run/pouchd.sock]
89156
`
90157
}

daemon/daemon.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (d *Daemon) Run() error {
135135
}
136136
d.imageMgr = imageMgr
137137

138-
systemMgr, err := internal.GenSystemMgr(&d.config)
138+
systemMgr, err := internal.GenSystemMgr(&d.config, d)
139139
if err != nil {
140140
return err
141141
}

daemon/mgr/system.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package mgr
22

33
import (
44
"runtime"
5+
"sync/atomic"
56

67
"github.com/alibaba/pouch/apis/types"
78
"github.com/alibaba/pouch/daemon/config"
89
"github.com/alibaba/pouch/pkg/kernel"
10+
"github.com/alibaba/pouch/pkg/meta"
911
"github.com/alibaba/pouch/registry"
1012
"github.com/alibaba/pouch/version"
1113

@@ -24,14 +26,17 @@ type SystemManager struct {
2426
name string
2527
registry *registry.Client
2628
config *config.Config
29+
30+
store *meta.Store
2731
}
2832

2933
// NewSystemManager creates a brand new system manager.
30-
func NewSystemManager(cfg *config.Config) (*SystemManager, error) {
34+
func NewSystemManager(cfg *config.Config, store *meta.Store) (*SystemManager, error) {
3135
return &SystemManager{
3236
name: "system_manager",
3337
registry: &registry.Client{},
3438
config: cfg,
39+
store: store,
3540
}, nil
3641
}
3742

@@ -44,16 +49,35 @@ func (mgr *SystemManager) Info() (types.SystemInfo, error) {
4449
kernelVersion = kv.String()
4550
}
4651

52+
var cRunning, cPaused, cStopped int64
53+
_ = mgr.store.ForEach(func(obj meta.Object) error {
54+
containerMeta, ok := obj.(*ContainerMeta)
55+
if !ok {
56+
return nil
57+
}
58+
status := containerMeta.State.Status
59+
switch status {
60+
case types.StatusRunning:
61+
atomic.AddInt64(&cRunning, 1)
62+
case types.StatusPaused:
63+
atomic.AddInt64(&cPaused, 1)
64+
case types.StatusStopped:
65+
atomic.AddInt64(&cStopped, 1)
66+
}
67+
68+
return nil
69+
})
70+
4771
inf := types.SystemInfo{
4872
// architecture: ,
4973
// CgroupDriver: ,
5074
// ContainerdCommit: ,
51-
// Containers: ,
52-
// ContainersPaused:,
53-
// ContainersRunning:,
54-
// ContainersStopped:,
55-
Debug: mgr.config.Debug,
56-
DefaultRuntime: mgr.config.DefaultRuntime,
75+
Containers: cRunning + cPaused + cStopped,
76+
ContainersPaused: cPaused,
77+
ContainersRunning: cRunning,
78+
ContainersStopped: cStopped,
79+
Debug: mgr.config.Debug,
80+
DefaultRuntime: mgr.config.DefaultRuntime,
5781
// Driver: ,
5882
// DriverStatus: ,
5983
// ExperimentalBuild: ,
@@ -76,7 +100,8 @@ func (mgr *SystemManager) Info() (types.SystemInfo, error) {
76100
// RuncCommit: ,
77101
// Runtimes: ,
78102
// SecurityOptions: ,
79-
ServerVersion: version.Version,
103+
ServerVersion: version.Version,
104+
ListenAddresses: mgr.config.Listen,
80105
}
81106
return inf, nil
82107
}

internal/generator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func GenContainerMgr(ctx context.Context, d DaemonProvider) (mgr.ContainerMgr, e
2929
}
3030

3131
// GenSystemMgr generates a SystemMgr instance according to config cfg.
32-
func GenSystemMgr(cfg *config.Config) (mgr.SystemMgr, error) {
33-
return mgr.NewSystemManager(cfg)
32+
func GenSystemMgr(cfg *config.Config, d DaemonProvider) (mgr.SystemMgr, error) {
33+
return mgr.NewSystemManager(cfg, d.MetaStore())
3434
}
3535

3636
// GenImageMgr generates a ImageMgr instance according to config cfg.

0 commit comments

Comments
 (0)