Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

JSON status to simplify automatic monitoring #25

Closed
wants to merge 1 commit into from

8 participants

@dkerwin

Hi,

we modified the the status resource to return json instead of a HTML table. This can be used to simplify monitoring. Example output looks like this:

{
  upstream_servers: 4,
  generation: 1,
  peers: [
    {
      upstream: "example-api.com",
      member: "192.168.1.1:80",
      status: "up",
      rise_count: 8,
      fall_count: 0,
      check_type: "http"
    },
    {
      upstream: "www.example-app.com",
      member: "192.168.1.2:80",
      status: "up",
      rise_count: 8,
      fall_count: 0,
      check_type: "http"
    },
    {
      upstream: "www.company.com",
      member: "192.168.1.3:80",
      status: "up",
      rise_count: 9,
      fall_count: 0,
      check_type: "http"
    },
  ]
}

There is lot's of room for improvement regarding the structure of the hash but i still hope you like the idea.

Cheers!
Daniel

@guillaumerose

Great idea ! Thanks for this patch.

@yaoweibin
Owner

Acctually, I have added the json and csv output page in the develop branch: https://github.com/yaoweibin/nginx_upstream_check_module/blob/development/ngx_http_upstream_check_module.c

the docs is the same as tengine: http://tengine.taobao.org/document/http_upstream_check.html

@XavM

What you've done in the develop branch about specifying a default check_status as csv|json|html is great, and being able to override it using the format query string is really good.

When do you plan to integrate this in master ?

@dkerwin

@XavM :+1: Would be awesome to see that merged into master

@vaijab

Would be great if you could merge into master. I can do testing and report any issues.

@scalp42

Any chances to see this in master?

@yaoweibin
Owner

OK. I'll do this merge in this weekend.

@XavM

Really good news
Thanks a lot

@lusis

wow I didn't even see this when I made my PR.

@scalp42 scalp42 referenced this pull request
Closed

Feature/json check status #39

@scalp42

@yaoweibin any updates please?

@yaoweibin
Owner

I have added this json status page, very similar with tengine(http://tengine.taobao.org/document/http_upstream_check.html). See the master branch
https://github.com/yaoweibin/nginx_upstream_check_module/

@yaoweibin yaoweibin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 24, 2013
  1. @dkerwin
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 37 deletions.
  1. +14 −37 ngx_http_upstream_check_handler.c
View
51 ngx_http_upstream_check_handler.c
@@ -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;
@@ -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;
Something went wrong with that request. Please try again.