Projet

Général

Profil

Révision bf9c3caa

IDbf9c3caae930e466c603d9ed97024c36ef5d652a
Parent 0a0b4777
Enfant 1368ef0e

Ajouté par Artem Sheremet il y a environ 12 ans

Add open_files capability to ejabberd_resources_

It appears that erlang port is not bound to an OS file very often.
Thus "ulimit -n" is moved to a separate graph and lsof/fstat is used as
a backend to count the number of files open.

Voir les différences:

plugins/ejabberd/ejabberd_resources_/ejabberd_resources_
14 14
# - connect to a running ejabberd node
15 15
#
16 16
# OS: *NIX
17
# Requires lsof/fstat for open_files.
17 18
#
18 19
# Author: Artem Sheremet <dot.doom@gmail.com>
19 20
#
......
120 121
ets.info The total amount of memory currently allocated for ets tables. This memory is part of the memory presented as system memory.
121 122
INFO_FROM_DOC
122 123
	else
123
		pid=$(<$EJABBERD_PID_PATH)
124
		local pid=$(<$EJABBERD_PID_PATH)
124 125
		for memory_type in rss vsz; do
125 126
			memory_value=$(ps -p $pid -o $memory_type=)
126 127
			let memory_value=$memory_value*1024
......
140 141
	local limit=$(ejabberd_exec 'os:getenv("ERL_MAX_PORTS").' | tr '"' ' ')
141 142
	# string "false" indicates that this variable is not defined, thus a default of 1024
142 143
	[ $limit = false ] && limit=1024
143
	local os_limit=$(ejabberd_exec 'os:cmd("ulimit -n").' | tr '"\\n' ' ')
144
	if [ $limit -gt $os_limit ]; then
145
		local real_limit=$os_limit
146
	else
147
		local real_limit=$limit
148
	fi
149 144
	if [ "$1" = "config" ]; then
150 145
		cat <<CONFIG
151 146
graph_vlabel ports
152
opened.draw LINE
153
opened.label opened
154
opened.info length(erlang:ports())
147
open.draw LINE
148
open.label open
149
open.info length(erlang:ports())
155 150
limit.draw LINE2
156 151
limit.label limit
157 152
limit.info ERL_MAX_PORTS environment variable inside ejabberd
158
os_limit.draw LINE2
159
os_limit.label os limit
160
os_limit.info "ulimit -n" from inside of ejabberd
161 153
CONFIG
162
		warning='80%' critical='90%' print_adjusted_thresholds opened $real_limit
154
		warning='80%' critical='90%' print_adjusted_thresholds open $limit
163 155
		[ -n "$ERL_MAX_PORTS" ] && cat <<CONFIG_CONFIGURED
164 156
configured.draw LINE
165 157
configured.label configured
166 158
configured.info Configuration file value ERL_MAX_PORTS
167 159
CONFIG_CONFIGURED
168 160
	else
169
		local opened=$(ejabberd_exec 'length(erlang:ports()).')
161
		local open=$(ejabberd_exec 'length(erlang:ports()).')
170 162
		cat <<DATA
171
opened.value $opened
163
open.value $open
172 164
limit.value $limit
173
os_limit.value $os_limit
174 165
DATA
175 166
		[ -n "$ERL_MAX_PORTS" ] && echo "configured.value $ERL_MAX_PORTS"
176 167
	fi
177 168
}
178 169

  
170
function open_files_counter_util() {
171
	if hash lsof &>/dev/null; then
172
		echo lsof
173
		return 0
174
	elif hash fstat &>/dev/null; then
175
		echo fstat
176
		return 0
177
	fi
178
	return 1
179
}
180

  
181
function open_files_number() {
182
	echo $[$($(open_files_counter_util) -np $(<$EJABBERD_PID_PATH) | wc -l)-1]
183
}
184

  
185
function ejabberd_report_open_files() {
186
	# this spawns a child process, but in most cases the open files limit is inherited
187
	local limit=$(ejabberd_exec 'os:cmd("ulimit -n").' | tr '"\\n' ' ')
188
	if [ "$1" = "config" ]; then
189
		cat <<CONFIG
190
graph_vlabel open files
191
open.draw LINE
192
open.label open
193
open.info number of open files as reported by $(open_files_counter_util)
194
limit.draw LINE2
195
limit.label limit
196
limit.info "ulimit -n" from inside of ejabberd
197
CONFIG
198
		warning='80%' critical='90%' print_adjusted_thresholds open $limit
199
	else
200
		cat <<DATA
201
open.value $(open_files_number)
202
limit.value $limit
203
DATA
204
	fi
205
}
206

  
179 207
function ejabberd_report_processes() {
180 208
	local limit=$(ejabberd_exec 'erlang:system_info(process_limit).')
181 209
	if [ "$1" = "config" ]; then
......
217 245
online_users
218 246
registered_users
219 247
SUGGESTIONS
248
		open_files_counter_util &>/dev/null && echo open_files
220 249
		exit 0
221 250
		;;
222 251
	config)

Formats disponibles : Unified diff