📄 jk_worker_status.c
字号:
/* ========================================================================= * * * * The Apache Software License, Version 1.1 * * * * Copyright (c) 1999-2002 The Apache Software Foundation. * * All rights reserved. * * * * ========================================================================= * * * * Redistribution and use in source and binary forms, with or without modi- * * fication, are permitted provided that the following conditions are met: * * * * 1. Redistributions of source code must retain the above copyright notice * * notice, this list of conditions and the following disclaimer. * * * * 2. Redistributions in binary form must reproduce the above copyright * * notice, this list of conditions and the following disclaimer in the * * documentation and/or other materials provided with the distribution. * * * * 3. The end-user documentation included with the redistribution, if any, * * must include the following acknowlegement: * * * * "This product includes software developed by the Apache Software * * Foundation <http://www.apache.org/>." * * * * Alternately, this acknowlegement may appear in the software itself, if * * and wherever such third-party acknowlegements normally appear. * * * * 4. The names "The Jakarta Project", "Jk", and "Apache Software * * Foundation" must not be used to endorse or promote products derived * * from this software without prior written permission. For written * * permission, please contact <apache@apache.org>. * * * * 5. Products derived from this software may not be called "Apache" nor may * * "Apache" appear in their names without prior written permission of the * * Apache Software Foundation. * * * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES * * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * * THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY * * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * * POSSIBILITY OF SUCH DAMAGE. * * * * ========================================================================= * * * * This software consists of voluntary contributions made by many indivi- * * duals on behalf of the Apache Software Foundation. For more information * * on the Apache Software Foundation, please see <http://www.apache.org/>. * * * * ========================================================================= *//** * Status worker. It'll not connect to tomcat, but just generate response * itself, containing a simple xhtml page with the current jk info. * * Note that the html tags are using 'class' attribute. Someone with some * color taste can do a nice CSS and display it nicely, but more important is * that it should be easy to grep/xpath it programmatically. * * @author Costin Manolache */#include "jk_pool.h"#include "jk_service.h"#include "jk_worker.h"#include "jk_logger.h"#include "jk_env.h"#include "jk_requtil.h"#include "jk_registry.h"#include "jk_endpoint.h"#define JK_CHECK_NULL( str ) ( ((str)==NULL) ? "null" : (str) )static void jk2_worker_status_displayStat(jk_env_t *env, jk_ws_service_t *s, jk_stat_t *stat, int *totalReqP, int *totalErrP, unsigned long *totalTimeP, unsigned long *maxTimeP ){ int totalReq=*totalReqP; int totalErr=*totalErrP; unsigned long totalTime=*totalTimeP; unsigned long maxTime=*maxTimeP; s->jkprintf(env, s, "<tr><td>%d</td><td>%d</td><td>%d</td>\n", stat->workerId, stat->reqCnt, stat->errCnt ); s->jkprintf(env, s, "<td>%s</td>\n", JK_CHECK_NULL(stat->active) ); totalReq+=stat->reqCnt; totalErr+=stat->errCnt;#ifdef HAS_APR { char ctimeBuf[APR_CTIME_LEN]; apr_ctime( ctimeBuf, stat->connectedTime ); s->jkprintf(env, s, "<td>%s</td>\n", ctimeBuf ); s->jkprintf(env, s, "<td>%ld</td>\n", (long)stat->totalTime ); s->jkprintf(env, s, "<td>%ld</td>\n", (long)stat->maxTime ); if( stat->reqCnt + stat->errCnt > 0 ) s->jkprintf(env, s, "<td>%ld</td>\n", (long)(stat->totalTime / ( stat->reqCnt + stat->errCnt )) ); else s->jkprintf(env, s, "<td>-</td>\n"); s->jkprintf(env, s, "<td>%lu</td>\n", (long)stat->startTime ); s->jkprintf(env, s, "<td>%ld</td>\n", (long)(stat->jkStartTime - stat->startTime) ); s->jkprintf(env, s, "<td>%ld</td>\n", (long)(stat->endTime - stat->startTime) ); totalTime += (long)stat->totalTime; if( maxTime < stat->maxTime ) maxTime = (long)stat->maxTime; }#endif s->jkprintf(env, s, "</tr>\n"); *maxTimeP=maxTime; *totalTimeP=totalTime; *totalReqP=totalReq; *totalErrP=totalErr;}static void jk2_worker_status_displayAggregate(jk_env_t *env, jk_ws_service_t *s, int totalReq, int totalErr, unsigned long totalTime, unsigned long maxTime ){ s->jkprintf(env, s, "Totals:\n"); s->jkprintf(env, s, "<table border><tr><th>Req</th><th>Err</th><th>Max</th><th>Avg</th></tr>"); s->jkprintf(env, s, "<tr><td>%d</td>\n", totalReq ); s->jkprintf(env, s, "<td>%d</td>\n", totalErr ); s->jkprintf(env, s, "<td>%ld</td>\n", maxTime ); if( totalErr + totalReq > 0 ) { unsigned long avg=totalTime / ( totalReq + totalErr ); s->jkprintf(env, s, "<td>%ld</td>\n", avg ); } else { s->jkprintf(env, s, "<td>-</td>\n" ); } s->jkprintf(env, s, "</tr></table>\n");}static void jk2_worker_status_displayEndpointInfo(jk_env_t *env, jk_ws_service_t *s, jk_workerEnv_t *wenv){ int i; int totalReq=0; int totalErr=0; unsigned long totalTime=0; unsigned long maxTime=0; s->jkprintf(env, s, "<h2>Endpoint info ( no shm )</h2>\n"); s->jkprintf(env, s, "<table border>\n"); s->jkprintf(env, s, "<tr><th>Worker</th><th>Req</th><th>Err</th>"); s->jkprintf(env, s,"<th>LastReq</th>\n" ); #ifdef HAS_APR s->jkprintf(env, s, "<th>ConnectionTime</th><th>TotalTime</th><th>MaxTime</th><th>AvgTime</th>" ); s->jkprintf(env, s, "<th>ReqStart</th><th>+jk</th><th>+end</th>" );#endif for( i=0; i < env->_objects->size( env, env->_objects ); i++ ) { char *name=env->_objects->nameAt( env, env->_objects, i ); jk_bean_t *mbean=env->_objects->valueAt( env, env->_objects, i ); jk_endpoint_t *ep; if( mbean==NULL ) continue; if( strncmp( "endpoint", mbean->type, 8 ) != 0 ) continue; ep=mbean->object; if( ep->stats != NULL ){ jk2_worker_status_displayStat( env, s, ep->stats, &totalReq, &totalErr, &totalTime, &maxTime); } } s->jkprintf(env, s, "</table>\n"); jk2_worker_status_displayAggregate( env, s, totalReq, totalErr, totalTime, maxTime);}static void jk2_worker_status_displayScoreboardInfo(jk_env_t *env, jk_ws_service_t *s, jk_workerEnv_t *wenv){ jk_map_t *map=wenv->initData; int i; int j; int totalReq=0; int totalErr=0; unsigned long totalTime=0; unsigned long maxTime=0; int needHeader=JK_TRUE; if( wenv->shm==NULL || wenv->shm->head==NULL) { return; } s->jkprintf(env, s, "<h2>Scoreboard info (ver=%d slots=%d)</h2>\n", wenv->shm->head->lbVer, wenv->shm->head->lastSlot ); s->jkprintf(env, s, "<a href='jkstatus?scoreboard.reset'>reset</a>\n"); s->jkprintf(env, s, "<table border>\n"); for( i=1; i < wenv->shm->head->lastSlot; i++ ) { jk_shm_slot_t *slot= wenv->shm->getSlot( env, wenv->shm, i ); if( slot==NULL ) continue; if( strncmp( slot->name, "epStat", 6 ) == 0 ) { /* This is an endpoint slot */ void *data=slot->data; s->jkprintf(env, s, "<tr><th colspan='4'>%s</th>\n", JK_CHECK_NULL(slot->name) ); s->jkprintf(env, s, "<th>Cnt=%d</th><th>size=%d</th>\n", slot->structCnt, slot->structSize ); s->jkprintf(env, s, "<tr><th>Worker</th><th>Req</th><th>Err</th>"); s->jkprintf(env, s,"<th>LastReq</th>\n" ); #ifdef HAS_APR s->jkprintf(env, s, "<th>ConnectionTime</th><th>TotalTime</th><th>MaxTime</th><th>AvgTime</th>" ); s->jkprintf(env, s, "<th>ReqStart</th><th>+jk</th><th>+end</th>" );#endif /* XXX Add info about number of slots */ for( j=0; j<slot->structCnt ; j++ ) { jk_stat_t *statArray=(jk_stat_t *)data; jk_stat_t *stat=statArray + j; jk2_worker_status_displayStat( env, s, stat, &totalReq, &totalErr, &totalTime, &maxTime); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -