Skip to content

Commit

Permalink
Add stats for zombie processes encountered
Browse files Browse the repository at this point in the history
  • Loading branch information
ovalenti committed Jan 2, 2025
1 parent 400f5c1 commit 2561ca3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
1 change: 1 addition & 0 deletions collector/lib/CollectorStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
X(procfs_could_not_get_socket_inodes) \
X(procfs_could_not_read_exe) \
X(procfs_could_not_read_cmdline) \
X(procfs_zombie_process) \
X(event_timestamp_distant_past) \
X(event_timestamp_future)

Expand Down
15 changes: 7 additions & 8 deletions collector/lib/ProcfsScraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,9 @@ bool GetSocketINodes(int dirfd, uint64_t pid, UnorderedSet<SocketInfo>* sock_ino
return true;
}

// IsZombieProcess fetches the current state of the process pointed to by dirfd, and
// - returns true, if the process state is 'Z'
// - returns false otherwise
bool IsZombieProcess(int dirfd) {
// Fetches the current state of the process pointed to by dirfd
// returns nulopt in case of error
std::optional<char> ReadProcessState(int dirfd) {
FileHandle stat_file(FDHandle(openat(dirfd, "stat", O_RDONLY)), "r");
if (!stat_file.valid()) {
return false;
Expand All @@ -159,9 +158,7 @@ bool IsZombieProcess(int dirfd) {
return false;
}

auto state = ExtractProcessState(linebuf);

return state && *state == 'Z';
return ExtractProcessState(linebuf);
}

// GetContainerID retrieves the container ID of the process represented by dirfd. The container ID is extracted from
Expand Down Expand Up @@ -512,7 +509,9 @@ bool ReadContainerConnections(const char* proc_path, std::shared_ptr<ProcessStor
continue;
}

if (IsZombieProcess(dirfd)) {
auto process_state = ReadProcessState(dirfd);
if (process_state && *process_state == 'Z') {
COUNTER_INC(CollectorStats::procfs_zombie_process);
continue;
}

Expand Down

0 comments on commit 2561ca3

Please sign in to comment.