| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | /* | 
					
						
							|  |  |  |  * MinIO Cloud Storage, (C) 2020 MinIO, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *     http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							|  |  |  |  * limitations under the License. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | package cmd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							|  |  |  | 	"context" | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 	"fmt" | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 	"net/http" | 
					
						
							|  |  |  | 	"os" | 
					
						
							|  |  |  | 	"sync" | 
					
						
							|  |  |  | 	"syscall" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	"github.com/minio/minio/pkg/disk" | 
					
						
							|  |  |  | 	"github.com/minio/minio/pkg/madmin" | 
					
						
							|  |  |  | 	cpuhw "github.com/shirou/gopsutil/cpu" | 
					
						
							|  |  |  | 	memhw "github.com/shirou/gopsutil/mem" | 
					
						
							|  |  |  | 	"github.com/shirou/gopsutil/process" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | func getLocalCPUInfo(ctx context.Context, r *http.Request) madmin.ServerCPUInfo { | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 	addr := r.Host | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if globalIsDistErasure { | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		addr = GetLocalPeer(globalEndpoints) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	info, err := cpuhw.InfoWithContext(ctx) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 		return madmin.ServerCPUInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 			Addr:  addr, | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			Error: fmt.Sprintf("info: %v", err), | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	time, err := cpuhw.TimesWithContext(ctx, false) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 		return madmin.ServerCPUInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 			Addr:  addr, | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			Error: fmt.Sprintf("times: %v", err), | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 	return madmin.ServerCPUInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		Addr:     addr, | 
					
						
							|  |  |  | 		CPUStat:  info, | 
					
						
							|  |  |  | 		TimeStat: time, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-02 05:50:33 +08:00
										 |  |  | func getLocalDrives(ctx context.Context, parallel bool, endpointServerPools EndpointServerPools, r *http.Request) madmin.ServerDrivesInfo { | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 	var drivesPerfInfo []madmin.DrivePerfInfo | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 	var wg sync.WaitGroup | 
					
						
							| 
									
										
										
										
											2020-12-02 05:50:33 +08:00
										 |  |  | 	for _, ep := range endpointServerPools { | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 		for _, endpoint := range ep.Endpoints { | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 			// Only proceed for local endpoints
 | 
					
						
							|  |  |  | 			if endpoint.IsLocal { | 
					
						
							|  |  |  | 				if _, err := os.Stat(endpoint.Path); err != nil { | 
					
						
							|  |  |  | 					// Since this drive is not available, add relevant details and proceed
 | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 					drivesPerfInfo = append(drivesPerfInfo, madmin.DrivePerfInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 						Path:  endpoint.Path, | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 						Error: fmt.Sprintf("stat: %v", err), | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 					}) | 
					
						
							|  |  |  | 					continue | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-04-13 10:37:09 +08:00
										 |  |  | 				measurePath := pathJoin(minioMetaTmpBucket, mustGetUUID()) | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 				measure := func(path string) { | 
					
						
							|  |  |  | 					defer wg.Done() | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 					driveInfo := madmin.DrivePerfInfo{ | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 						Path: path, | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 					latency, throughput, err := disk.GetHealthInfo(ctx, path, pathJoin(path, measurePath)) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 					if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 						driveInfo.Error = fmt.Sprintf("health-info: %v", err) | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 					} else { | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 						driveInfo.Latency = latency | 
					
						
							|  |  |  | 						driveInfo.Throughput = throughput | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 					drivesPerfInfo = append(drivesPerfInfo, driveInfo) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				wg.Add(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if parallel { | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 					go measure(endpoint.Path) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 					measure(endpoint.Path) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	wg.Wait() | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 	addr := r.Host | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if globalIsDistErasure { | 
					
						
							| 
									
										
										
										
											2020-12-02 05:50:33 +08:00
										 |  |  | 		addr = GetLocalPeer(endpointServerPools) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if parallel { | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 		return madmin.ServerDrivesInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 			Addr:     addr, | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 			Parallel: drivesPerfInfo, | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 	return madmin.ServerDrivesInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		Addr:   addr, | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 		Serial: drivesPerfInfo, | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | func getLocalMemInfo(ctx context.Context, r *http.Request) madmin.ServerMemInfo { | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 	addr := r.Host | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if globalIsDistErasure { | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		addr = GetLocalPeer(globalEndpoints) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	swap, err := memhw.SwapMemoryWithContext(ctx) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 		return madmin.ServerMemInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 			Addr:  addr, | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			Error: fmt.Sprintf("swap: %v", err), | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	vm, err := memhw.VirtualMemoryWithContext(ctx) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 		return madmin.ServerMemInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 			Addr:  addr, | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			Error: fmt.Sprintf("virtual-mem: %v", err), | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 	return madmin.ServerMemInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		Addr:       addr, | 
					
						
							|  |  |  | 		SwapMem:    swap, | 
					
						
							|  |  |  | 		VirtualMem: vm, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | func getLocalProcInfo(ctx context.Context, r *http.Request) madmin.ServerProcInfo { | 
					
						
							| 
									
										
										
										
											2020-05-19 00:59:45 +08:00
										 |  |  | 	addr := r.Host | 
					
						
							| 
									
										
										
										
											2020-06-13 11:04:01 +08:00
										 |  |  | 	if globalIsDistErasure { | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		addr = GetLocalPeer(globalEndpoints) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 	errProcInfo := func(tag string, err error) madmin.ServerProcInfo { | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 		return madmin.ServerProcInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 			Addr:  addr, | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			Error: fmt.Sprintf("%s: %v", tag, err), | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	selfPid := int32(syscall.Getpid()) | 
					
						
							|  |  |  | 	self, err := process.NewProcess(selfPid) | 
					
						
							|  |  |  | 	if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 		return errProcInfo("new-process", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	processes := []*process.Process{self} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 	sysProcs := []madmin.SysProcess{} | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 	for _, proc := range processes { | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 		sysProc := madmin.SysProcess{} | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		sysProc.Pid = proc.Pid | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bg, err := proc.BackgroundWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("background", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Background = bg | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		cpuPercent, err := proc.CPUPercentWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("cpu-percent", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.CPUPercent = cpuPercent | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		children, _ := proc.ChildrenWithContext(ctx) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for _, c := range children { | 
					
						
							|  |  |  | 			sysProc.Children = append(sysProc.Children, c.Pid) | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		cmdLine, err := proc.CmdlineWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("cmdline", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.CmdLine = cmdLine | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		conns, err := proc.ConnectionsWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("conns", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2021-02-06 13:32:28 +08:00
										 |  |  | 		sysProc.ConnectionCount = len(conns) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		createTime, err := proc.CreateTimeWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("create-time", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.CreateTime = createTime | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		cwd, err := proc.CwdWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("cwd", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Cwd = cwd | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		exe, err := proc.ExeWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("exe", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Exe = exe | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		gids, err := proc.GidsWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("gids", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Gids = gids | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ioCounters, err := proc.IOCountersWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("iocounters", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.IOCounters = ioCounters | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		isRunning, err := proc.IsRunningWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("is-running", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.IsRunning = isRunning | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		memInfo, err := proc.MemoryInfoWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("mem-info", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.MemInfo = memInfo | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		memMaps, err := proc.MemoryMapsWithContext(ctx, true) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("mem-maps", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.MemMaps = memMaps | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		memPercent, err := proc.MemoryPercentWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("mem-percent", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.MemPercent = memPercent | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		name, err := proc.NameWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("name", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Name = name | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		netIOCounters, err := proc.NetIOCountersWithContext(ctx, false) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("netio-counters", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.NetIOCounters = netIOCounters | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		nice, err := proc.NiceWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("nice", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Nice = nice | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		numCtxSwitches, err := proc.NumCtxSwitchesWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("num-ctx-switches", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.NumCtxSwitches = numCtxSwitches | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		numFds, err := proc.NumFDsWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("num-fds", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.NumFds = numFds | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		numThreads, err := proc.NumThreadsWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("num-threads", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.NumThreads = numThreads | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		pageFaults, err := proc.PageFaultsWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("page-faults", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.PageFaults = pageFaults | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		parent, err := proc.ParentWithContext(ctx) | 
					
						
							| 
									
										
										
										
											2020-04-19 02:06:11 +08:00
										 |  |  | 		if err == nil { | 
					
						
							|  |  |  | 			sysProc.Parent = parent.Pid | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ppid, err := proc.PpidWithContext(ctx) | 
					
						
							| 
									
										
										
										
											2020-04-19 02:06:11 +08:00
										 |  |  | 		if err == nil { | 
					
						
							|  |  |  | 			sysProc.Ppid = ppid | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		rlimit, err := proc.RlimitWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("rlimit", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Rlimit = rlimit | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		status, err := proc.StatusWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("status", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Status = status | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		tgid, err := proc.Tgid() | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("tgid", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Tgid = tgid | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		times, err := proc.TimesWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("times", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Times = times | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		uids, err := proc.UidsWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("uids", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Uids = uids | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		username, err := proc.UsernameWithContext(ctx) | 
					
						
							|  |  |  | 		if err != nil { | 
					
						
							| 
									
										
										
										
											2021-02-06 04:37:15 +08:00
										 |  |  | 			return errProcInfo("username", err) | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		sysProc.Username = username | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		sysProcs = append(sysProcs, sysProc) | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-21 04:52:53 +08:00
										 |  |  | 	return madmin.ServerProcInfo{ | 
					
						
							| 
									
										
										
										
											2020-03-27 12:07:39 +08:00
										 |  |  | 		Addr:      addr, | 
					
						
							|  |  |  | 		Processes: sysProcs, | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |