1. 安装tsar
- # cd /usr/local/src/
- wget -O tsar.zip https://github.com/alibaba/tsar/archive/master.zip --no-check-certificate
- unzip tsar.zip
- 该版本解压后的文件夹名称为:tsar-master
- cd tsar-master/
- make
- make install
- 安装 tsardevel
- make tsardevel
- 至此,已安装好,可以使用命令
- # tsar -l
- 查看是否成功。
- # tsardevel
- Usage:
- tsardevel modname
- 表示tsardevel安装成功
文件路径为:/etc/tsar/tsar.conf
modules
路径为:/usr/local/tsar/modules
3. 使用tsar的模块开发工具tsardevel生成一个模块模板
- cd /usr/local/tsar/
- tsardevel mod_ngx
- cd /usr/local/src/tsar-master/modules/
- mv ./mod_nginx.c /usr/local/tsar/mod_ngx/
- cd ./mod_ngx/
- mv ./mod_nginx.c ./mod_mod_ngx.c
- vi mod_mod_ngx.c
- unned long long naccept; /* accepted connections */
- unsigned long long nhandled; /* handled connections */
- unsigned long long nrequest; /* handled requests */
- unsigned long long nactive; /* number of all open connections including connections to backends */
- unsigned long long nreading; /* nginx reads request header */
- unsigned long long nwriting; /* nginx reads request body, processes request, or writes response to a client */
- unsigned long long nwaiting; /* keep-alive connections, actually it is active - (reading + writing) */
- unsigned long long nrstime; /* reponse time of handled requests */
- 修改 nginx 相关的一些配置
- p->host = getenv("NGX_TSAR_HOST");
- p->host = p->host ? p->host : "127.0.0.1";
- port = getenv("NGX_TSAR_PORT");
- p->port = port ? atoi(port) : 80;
- p->uri = getenv("NGX_TSAR_URI");
- p->uri = p->uri ? p->uri : "/nginx_status";
- p->server_name = getenv("NGX_TSAR_SERVER_NAME");
- p->server_name = p->server_name ? p->server_name : "status.taobao.com";
- sprintf(request,
- "GET %s HTTP/1.0\r\n"
- "User-Agent: tsar\r\n"
- "Host: %s\r\n"
- "Accept:*/*\r\n"
- "Connection: Close\r\n\r\n",
- hinfo.uri, hinfo.server_name);
tsar --ngx -l