@@ -144,12 +144,73 @@ int fpm_status_get(int *idle, int *active, int *total, int *pm) /* {{{ */
144
144
}
145
145
/* }}} */
146
146
147
+ static void fpm_status_handle_status_txt (struct fpm_status_s * status , char * * output , char * * content_type ) /* {{{ */
148
+ {
149
+ if (!status || !output || !content_type ) {
150
+ return ;
151
+ }
152
+
153
+ spprintf (output , 0 ,
154
+ "accepted conn: %lu\n"
155
+ "pool: %s\n"
156
+ "process manager: %s\n"
157
+ "idle processes: %d\n"
158
+ "active processes: %d\n"
159
+ "total processes: %d\n" ,
160
+ status -> accepted_conn , fpm_status_pool , status -> pm == PM_STYLE_STATIC ? "static" : "dynamic" , status -> idle , status -> active , status -> total );
161
+
162
+ spprintf (content_type , 0 , "text/plain" );
163
+ }
164
+ /* }}} */
165
+
166
+ static void fpm_status_handle_status_html (struct fpm_status_s * status , char * * output , char * * content_type ) /* {{{ */
167
+ {
168
+ if (!status || !output || !content_type ) {
169
+ return ;
170
+ }
171
+
172
+ spprintf (output , 0 ,
173
+ "<table>\n"
174
+ "<tr><th>accepted conn</th><td>%lu</td></tr>\n"
175
+ "<tr><th>pool</th><td>%s</td></tr>\n"
176
+ "<tr><th>process manager</th><td>%s</td></tr>\n"
177
+ "<tr><th>idle processes</th><td>%d</td></tr>\n"
178
+ "<tr><th>active processes</th><td>%d</td></tr>\n"
179
+ "<tr><th>total processes</th><td>%d</td></tr>\n"
180
+ "</table>" ,
181
+ status -> accepted_conn , fpm_status_pool , status -> pm == PM_STYLE_STATIC ? "static" : "dynamic" , status -> idle , status -> active , status -> total );
182
+
183
+ spprintf (content_type , 0 , "text/html" );
184
+ }
185
+ /* }}} */
186
+
187
+ static void fpm_status_handle_status_json (struct fpm_status_s * status , char * * output , char * * content_type ) /* {{{ */
188
+ {
189
+ if (!status || !output || !content_type ) {
190
+ return ;
191
+ }
192
+
193
+ spprintf (output , 0 ,
194
+ "{"
195
+ "\"accepted conn\":%lu,"
196
+ "\"pool\":\"%s\","
197
+ "\"process manager\":\"%s\","
198
+ "\"idle processes\":%d,"
199
+ "\"active processes\":%d,"
200
+ "\"total processes\":%d"
201
+ "}" ,
202
+ status -> accepted_conn , fpm_status_pool , status -> pm == PM_STYLE_STATIC ? "static" : "dynamic" , status -> idle , status -> active , status -> total );
203
+
204
+ spprintf (content_type , 0 , "application/jsonrequest" );
205
+ }
206
+ /* }}} */
207
+
147
208
/* return 0 if it's not the request page
148
209
* return 1 if ouput has been set)
149
210
* *output unchanged: error (return 500)
150
211
* *output changed: no error (return 200)
151
212
*/
152
- int fpm_status_handle_status (char * uri , char * * output ) /* {{{ */
213
+ int fpm_status_handle_status (char * uri , char * query_string , char * * output , char * * content_type ) /* {{{ */
153
214
{
154
215
struct fpm_status_s status ;
155
216
@@ -162,7 +223,7 @@ int fpm_status_handle_status(char *uri, char **output) /* {{{ */
162
223
return (0 );
163
224
}
164
225
165
- if (!output || !fpm_status_shm ) {
226
+ if (!output || !content_type || ! fpm_status_shm ) {
166
227
return (1 );
167
228
}
168
229
@@ -177,16 +238,15 @@ int fpm_status_handle_status(char *uri, char **output) /* {{{ */
177
238
return (1 );
178
239
}
179
240
180
- spprintf (output , 0 ,
181
- "accepted conn: %lu\n"
182
- "pool: %s\n"
183
- "process manager: %s\n"
184
- "idle processes: %d\n"
185
- "active processes: %d\n"
186
- "total processes: %d\n" ,
187
- status .accepted_conn , fpm_status_pool , status .pm == PM_STYLE_STATIC ? "static" : "dynamic" , status .idle , status .active , status .total );
241
+ if (query_string && strstr (query_string , "html" )) {
242
+ fpm_status_handle_status_html (& status , output , content_type );
243
+ } else if (query_string && strstr (query_string , "json" )) {
244
+ fpm_status_handle_status_json (& status , output , content_type );
245
+ } else {
246
+ fpm_status_handle_status_txt (& status , output , content_type );
247
+ }
188
248
189
- if (!* output ) {
249
+ if (!* output || ! content_type ) {
190
250
zlog (ZLOG_STUFF , ZLOG_ERROR , "[pool %s] unable to allocate status ouput buffer" , fpm_status_pool );
191
251
return (1 );
192
252
}
0 commit comments