@@ -18,11 +18,14 @@ func (r *Registry) Server() *Server {
1818 Short : "Envoy server commands" ,
1919 }
2020 cmd .AddCommand (r .BuildServerInfoCommand ())
21+ cmd .AddCommand (r .BuildServerMemoryCommand ())
2122 return & Server {
2223 Command : cmd ,
2324 }
2425}
2526
27+ // server info
28+
2629func (r * Registry ) BuildServerInfoCommand () * cobra.Command {
2730 return & cobra.Command {
2831 Use : "info" ,
@@ -44,10 +47,11 @@ type ServerInfoController struct {
4447
4548func (s * ServerInfoController ) Run () error {
4649 e , err := envoy .NewFromServiceName (s .ServiceName )
47- if err != nil {
48- return err
49- }
50- response := e .Server ().Info ()
50+ if err != nil { return err }
51+
52+ response , err := e .Server ().Info ()
53+ if err != nil { return err }
54+
5155 s .DisplayOutput (response )
5256 return nil
5357}
@@ -108,4 +112,51 @@ func (s *ServerInfoController) DisplayOutput(data envoy.ServerInfoJson) {
108112 table .AppendBulk (d )
109113 table .SetAlignment (tablewriter .ALIGN_LEFT )
110114 table .Render ()
115+ }
116+
117+ // server memory
118+
119+ type ServerMemoryController struct {
120+ ServiceName string
121+ }
122+ func (r * Registry ) BuildServerMemoryCommand () * cobra.Command {
123+ return & cobra.Command {
124+ Use : "memory" ,
125+ Short : "Display envoy memory information" ,
126+ Long : `Display memory usage information about the envoy sidecar` ,
127+ Args : cobra .MinimumNArgs (1 ),
128+ RunE : func (cmd * cobra.Command , args []string ) error {
129+ controller := ServerMemoryController {
130+ ServiceName : args [0 ],
131+ }
132+ return controller .Run ()
133+ },
134+ }
135+ }
136+
137+ func (s * ServerMemoryController ) Run () error {
138+ e , err := envoy .NewFromServiceName (s .ServiceName )
139+ if err != nil { return err }
140+
141+ data , err := e .Server ().Memory ()
142+ if err != nil { return err }
143+
144+ fmt .Println ("----------------------" )
145+ fmt .Println ("- Server Memory Info -" )
146+ fmt .Println ("----------------------" )
147+ d := [][]string {
148+ {"Allocated" , data .Allocated },
149+ {"Heap Size" , data .HeapSize },
150+ {"Page Heap (Unmapped)" , data .PageHeapUnmapped },
151+ {"Page Heap (Free)" , data .PageHeapFree },
152+ {"Total Physical Bytes" , data .TotalPhysicalBytes },
153+ {"Total Thread Cache" , data .TotalThreadCache },
154+ }
155+ table := tablewriter .NewWriter (os .Stdout )
156+ table .SetBorder (false )
157+ table .SetTablePadding ("\t " )
158+ table .AppendBulk (d )
159+ table .SetAlignment (tablewriter .ALIGN_LEFT )
160+ table .Render ()
161+ return nil
111162}
0 commit comments