Software /
code /
prosody-modules
Comparison
mod_measure_process/mod_measure_process.lua @ 4878:c26f515751af
mod_measure_process: Handle unlimited FD limits
While unlikely, better type-safe than sorry
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 18 Jan 2022 19:09:01 +0100 |
parent | 4877:adc6241e5d16 |
comparison
equal
deleted
inserted
replaced
4877:adc6241e5d16 | 4878:c26f515751af |
---|---|
55 ):with_labels() | 55 ):with_labels() |
56 else | 56 else |
57 module:log("warn", "not reporting maximum number of file descriptors because mod_posix is not available") | 57 module:log("warn", "not reporting maximum number of file descriptors because mod_posix is not available") |
58 end | 58 end |
59 | 59 |
60 local function limit2num(limit) | |
61 if limit == "unlimited" then | |
62 return math.huge | |
63 end | |
64 return limit | |
65 end | |
66 | |
60 module:hook("stats-update", function () | 67 module:hook("stats-update", function () |
61 local count = 0 | 68 local count = 0 |
62 for _ in lfs.dir("/proc/self/fd") do | 69 for _ in lfs.dir("/proc/self/fd") do |
63 count = count + 1 | 70 count = count + 1 |
64 end | 71 end |
65 open_fds:set(count) | 72 open_fds:set(count) |
66 | 73 |
67 if has_posix then | 74 if has_posix then |
68 local ok, soft, hard = posix.getrlimit("NOFILE") | 75 local ok, soft, hard = posix.getrlimit("NOFILE") |
69 if ok then | 76 if ok then |
70 max_fds:set(soft or hard); | 77 max_fds:set(limit2num(soft or hard)); |
71 end | 78 end |
72 end | 79 end |
73 end); | 80 end); |
74 end | 81 end |