Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Fixed a potential `process` metrics error when `fio.read` returns an empty string or an error.

# [1.5.0] - 2025-08-13

### Added
Expand Down
19 changes: 14 additions & 5 deletions metrics/psutils/psutils_linux.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local fio = require('fio')
local string = require('string')
local ffi = require('ffi')
local log = require('log')

local get_nprocs_conf = function() end
if jit.os == 'Linux' then
Expand All @@ -19,7 +20,7 @@ local function get_cpu_time()

local stats_raw = cpu_stat_file:read(512)
cpu_stat_file:close()
if #stats_raw == 0 then
if stats_raw == nil or #stats_raw == 0 then
return nil
end

Expand All @@ -37,14 +38,22 @@ local function get_cpu_time()
end

local function parse_process_stat(path)
local stat = fio.open(path, 'O_RDONLY')
if stat == nil then
print('stat open error')
local stat, err = fio.open(path, 'O_RDONLY')
if err ~= nil then
log.error('stat open error: %s', tostring(err))
return nil
end

local s = stat:read(512)
local s
s, err = stat:read(512)
stat:close()
if err ~= nil then
log.error('stat read error: %s', tostring(err))
return nil
end
if s == nil or #s == 0 then
return nil
end

local stats = string.split(s)
return {
Expand Down
Loading