xref: /unit/src/nxt_status.c (revision 2189:56af27d1e159)
12185Svbart@nginx.com 
22185Svbart@nginx.com /*
32185Svbart@nginx.com  * Copyright (C) NGINX, Inc.
42185Svbart@nginx.com  */
52185Svbart@nginx.com 
62185Svbart@nginx.com #include <nxt_main.h>
72185Svbart@nginx.com #include <nxt_conf.h>
82185Svbart@nginx.com #include <nxt_status.h>
92185Svbart@nginx.com 
102185Svbart@nginx.com 
112185Svbart@nginx.com nxt_conf_value_t *
nxt_status_get(nxt_status_report_t * report,nxt_mp_t * mp)122185Svbart@nginx.com nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
132185Svbart@nginx.com {
142185Svbart@nginx.com     size_t            i;
152185Svbart@nginx.com     nxt_str_t         name;
162185Svbart@nginx.com     nxt_int_t         ret;
172185Svbart@nginx.com     nxt_status_app_t  *app;
182185Svbart@nginx.com     nxt_conf_value_t  *status, *obj, *apps, *app_obj;
192185Svbart@nginx.com 
202185Svbart@nginx.com     static nxt_str_t conns_str = nxt_string("connections");
212185Svbart@nginx.com     static nxt_str_t acc_str = nxt_string("accepted");
222185Svbart@nginx.com     static nxt_str_t active_str = nxt_string("active");
232185Svbart@nginx.com     static nxt_str_t idle_str = nxt_string("idle");
242185Svbart@nginx.com     static nxt_str_t closed_str = nxt_string("closed");
252185Svbart@nginx.com     static nxt_str_t reqs_str = nxt_string("requests");
262186Sz.hong@f5.com     static nxt_str_t total_str = nxt_string("total");
272185Svbart@nginx.com     static nxt_str_t apps_str = nxt_string("applications");
282185Svbart@nginx.com     static nxt_str_t procs_str = nxt_string("processes");
292185Svbart@nginx.com     static nxt_str_t run_str = nxt_string("running");
302185Svbart@nginx.com     static nxt_str_t start_str = nxt_string("starting");
312185Svbart@nginx.com 
322185Svbart@nginx.com     status = nxt_conf_create_object(mp, 3);
332185Svbart@nginx.com     if (nxt_slow_path(status == NULL)) {
342185Svbart@nginx.com         return NULL;
352185Svbart@nginx.com     }
362185Svbart@nginx.com 
372185Svbart@nginx.com     obj = nxt_conf_create_object(mp, 4);
382185Svbart@nginx.com     if (nxt_slow_path(obj == NULL)) {
392185Svbart@nginx.com         return NULL;
402185Svbart@nginx.com     }
412185Svbart@nginx.com 
422185Svbart@nginx.com     nxt_conf_set_member(status, &conns_str, obj, 0);
432185Svbart@nginx.com 
442185Svbart@nginx.com     nxt_conf_set_member_integer(obj, &acc_str, report->accepted_conns, 0);
452185Svbart@nginx.com     nxt_conf_set_member_integer(obj, &active_str, report->accepted_conns
462185Svbart@nginx.com                                                   - report->closed_conns
472185Svbart@nginx.com                                                   - report->idle_conns, 1);
482185Svbart@nginx.com     nxt_conf_set_member_integer(obj, &idle_str, report->idle_conns, 2);
492185Svbart@nginx.com     nxt_conf_set_member_integer(obj, &closed_str, report->closed_conns, 3);
502185Svbart@nginx.com 
512186Sz.hong@f5.com     obj = nxt_conf_create_object(mp, 1);
522185Svbart@nginx.com     if (nxt_slow_path(obj == NULL)) {
532185Svbart@nginx.com         return NULL;
542185Svbart@nginx.com     }
552185Svbart@nginx.com 
562185Svbart@nginx.com     nxt_conf_set_member(status, &reqs_str, obj, 1);
572185Svbart@nginx.com 
582186Sz.hong@f5.com     nxt_conf_set_member_integer(obj, &total_str, report->requests, 0);
592186Sz.hong@f5.com 
602185Svbart@nginx.com     apps = nxt_conf_create_object(mp, report->apps_count);
61*2189Sz.hong@f5.com     if (nxt_slow_path(apps == NULL)) {
622185Svbart@nginx.com         return NULL;
632185Svbart@nginx.com     }
642185Svbart@nginx.com 
652185Svbart@nginx.com     nxt_conf_set_member(status, &apps_str, apps, 2);
662185Svbart@nginx.com 
672185Svbart@nginx.com     for (i = 0; i < report->apps_count; i++) {
682185Svbart@nginx.com         app = &report->apps[i];
692185Svbart@nginx.com 
702185Svbart@nginx.com         app_obj = nxt_conf_create_object(mp, 2);
712185Svbart@nginx.com         if (nxt_slow_path(app_obj == NULL)) {
722185Svbart@nginx.com             return NULL;
732185Svbart@nginx.com         }
742185Svbart@nginx.com 
752185Svbart@nginx.com         name.length = app->name.length;
762185Svbart@nginx.com         name.start = nxt_pointer_to(report, (uintptr_t) app->name.start);
772185Svbart@nginx.com 
782185Svbart@nginx.com         ret = nxt_conf_set_member_dup(apps, mp, &name, app_obj, i);
792185Svbart@nginx.com         if (nxt_slow_path(ret != NXT_OK)) {
802185Svbart@nginx.com             return NULL;
812185Svbart@nginx.com         }
822185Svbart@nginx.com 
832185Svbart@nginx.com         obj = nxt_conf_create_object(mp, 3);
84*2189Sz.hong@f5.com         if (nxt_slow_path(obj == NULL)) {
852185Svbart@nginx.com             return NULL;
862185Svbart@nginx.com         }
872185Svbart@nginx.com 
882185Svbart@nginx.com         nxt_conf_set_member(app_obj, &procs_str, obj, 0);
892185Svbart@nginx.com 
902185Svbart@nginx.com         nxt_conf_set_member_integer(obj, &run_str, app->processes, 0);
912185Svbart@nginx.com         nxt_conf_set_member_integer(obj, &start_str, app->pending_processes, 1);
922185Svbart@nginx.com         nxt_conf_set_member_integer(obj, &idle_str, app->idle_processes, 2);
932185Svbart@nginx.com 
942185Svbart@nginx.com         obj = nxt_conf_create_object(mp, 1);
95*2189Sz.hong@f5.com         if (nxt_slow_path(obj == NULL)) {
962185Svbart@nginx.com             return NULL;
972185Svbart@nginx.com         }
982185Svbart@nginx.com 
992185Svbart@nginx.com         nxt_conf_set_member(app_obj, &reqs_str, obj, 1);
1002185Svbart@nginx.com 
1012185Svbart@nginx.com         nxt_conf_set_member_integer(obj, &active_str, app->active_requests, 0);
1022185Svbart@nginx.com     }
1032185Svbart@nginx.com 
1042185Svbart@nginx.com     return status;
1052185Svbart@nginx.com }
106