Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON status to simplify automatic monitoring #25

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 14 additions & 37 deletions ngx_http_upstream_check_handler.c
Expand Up @@ -1654,8 +1654,8 @@ ngx_http_upstream_check_status_handler(ngx_http_request_t *r)
return rc;
}

r->headers_out.content_type.len = sizeof("text/html; charset=utf-8") - 1;
r->headers_out.content_type.data = (u_char *) "text/html; charset=utf-8";
r->headers_out.content_type.len = sizeof("application/json; charset=utf-8") - 1;
r->headers_out.content_type.data = (u_char *) "application/json; charset=utf-8";

if (r->method == NGX_HTTP_HEAD) {
r->headers_out.status = NGX_HTTP_OK;
Expand Down Expand Up @@ -1693,53 +1693,30 @@ ngx_http_upstream_check_status_handler(ngx_http_request_t *r)
out.next = NULL;

b->last = ngx_snprintf(b->last, b->end - b->last,
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\n"
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
"<head>\n"
" <title>Nginx http upstream check status</title>\n"
"</head>\n"
"<body>\n"
"<h1>Nginx http upstream check status</h1>\n"
"<h2>Check upstream server number: %ui, generation: %ui</h2>\n"
"<table style=\"background-color:white\" cellspacing=\"0\" "
" cellpadding=\"3\" border=\"1\">\n"
" <tr bgcolor=\"#C0C0C0\">\n"
" <th>Index</th>\n"
" <th>Upstream</th>\n"
" <th>Name</th>\n"
" <th>Status</th>\n"
" <th>Rise counts</th>\n"
" <th>Fall counts</th>\n"
" <th>Check type</th>\n"
" </tr>\n",
"{ \"upstream_servers\": %ui, \"generation\": %ui, \"peers\": [ ",
peers->peers.nelts, ngx_http_check_shm_generation);

for (i = 0; i < peers->peers.nelts; i++) {
b->last = ngx_snprintf(b->last, b->end - b->last,
" <tr%s>\n"
" <td>%ui</td>\n"
" <td>%V</td>\n"
" <td>%V</td>\n"
" <td>%s</td>\n"
" <td>%ui</td>\n"
" <td>%ui</td>\n"
" <td>%s</td>\n"
" </tr>\n",
peer_shm[i].down ? " bgcolor=\"#FF0000\"" : "",
i,
"{ \"upstream\": \"%V\", "
"\"member\": \"%V\", "
"\"status\": \"%s\", "
"\"rise_count\": %ui, "
"\"fall_count\": %ui, "
"\"check_type\": \"%s\""
"} %s",
peer[i].upstream_name,
&peer[i].peer_addr->name,
peer_shm[i].down ? "down" : "up",
peer_shm[i].rise_count,
peer_shm[i].fall_count,
peer[i].conf->check_type_conf->name);
peer[i].conf->check_type_conf->name,
(i < (peers->peers.nelts - 1)) ? ", " : ""
);
}

b->last = ngx_snprintf(b->last, b->end - b->last,
"</table>\n"
"</body>\n"
"</html>\n");
"] }");

r->headers_out.status = NGX_HTTP_OK;
r->headers_out.content_length_n = b->last - b->pos;
Expand Down