1
// Copyright Istio Authors
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
7
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
22
"istio.io/istio/pkg/ctrlz/fw"
23
"istio.io/istio/pkg/ctrlz/topics/assets"
26
type procTopic struct{}
28
// ProcTopic returns a ControlZ topic that allows visualization of process state.
29
func ProcTopic() fw.Topic {
33
func (procTopic) Title() string {
37
func (procTopic) Prefix() string {
42
Egid int `json:"egid"`
43
Euid int `json:"euid"`
45
Groups []int `json:"groups"`
47
Ppid int `json:"ppid"`
50
Hostname string `json:"hostname"`
51
TempDir string `json:"tempdir"`
52
Threads int `json:"threads"`
53
Goroutines int `json:"goroutines"`
56
func getProcInfo() *procInfo {
64
TempDir: os.TempDir(),
65
Goroutines: runtime.NumGoroutine(),
68
pi.Groups, _ = os.Getgroups()
69
pi.Wd, _ = os.Hostname()
70
pi.Hostname, _ = os.Hostname()
71
pi.Threads, _ = runtime.ThreadCreateProfile(nil)
76
func (procTopic) Activate(context fw.TopicContext) {
77
tmpl := assets.ParseTemplate(context.Layout(), "templates/proc.html")
79
_ = context.HTMLRouter().StrictSlash(true).NewRoute().Path("/").HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
80
fw.RenderHTML(w, tmpl, getProcInfo())
83
_ = context.JSONRouter().StrictSlash(true).NewRoute().Methods("GET").Path("/").HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
84
fw.RenderJSON(w, http.StatusOK, getProcInfo())