(processConfig PsProcessConfig)
| 207 | } |
| 208 | |
| 209 | func getProcessData(processConfig PsProcessConfig) (res []byte, err error) { |
| 210 | ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout) |
| 211 | defer cancel() |
| 212 | |
| 213 | processes, err := process.ProcessesWithContext(ctx) |
| 214 | if err != nil { |
| 215 | return |
| 216 | } |
| 217 | |
| 218 | connections, err := net.ConnectionsMaxWithContext(ctx, "all", 32768) |
| 219 | if err != nil { |
| 220 | return |
| 221 | } |
| 222 | |
| 223 | pidConnections := make(map[int32][]net.ConnectionStat, len(processes)) |
| 224 | for _, conn := range connections { |
| 225 | if conn.Pid == 0 { |
| 226 | continue |
| 227 | } |
| 228 | pidConnections[conn.Pid] = append(pidConnections[conn.Pid], conn) |
| 229 | } |
| 230 | |
| 231 | result := make([]PsProcessData, 0, len(processes)) |
| 232 | |
| 233 | for _, proc := range processes { |
| 234 | procData := handleProcessData(proc, &processConfig, pidConnections) |
| 235 | if procData != nil { |
| 236 | result = append(result, *procData) |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | res, err = json.Marshal(result) |
| 241 | return |
| 242 | } |
| 243 | |
| 244 | func getSSHSessions(config SSHSessionConfig) (res []byte, err error) { |
| 245 | var ( |
no test coverage detected