设为首页 收藏本站
查看: 285|回复: 0

[经验分享] Shell文件处理,Tomcat默认项目,AccessLog的配置

[复制链接]

尚未签到

发表于 2017-2-5 09:58:53 | 显示全部楼层 |阅读模式
最近处理了几个简单的技术问题,在这儿写一下,加深一下映象。
1. shell读取解析固定格式文件
在当前项目中,需要处理一个文件的内容,解析每行的数据,以这些数据位参数然后调用一些job完成任务,文件是固定的格式,以“|”分隔每个参数,例子:
假设有如下的一个文件,格式为First_Name|Surname|age, Job的任务是提取出每个人的age,判断是否为成年人
Xianning|Liu|27
Yujiao|Zhang|25

代码:
#!\bin\bash
#################################
#Usage: sh parse.sh <input_file>
#
#example: sh parse.sh records.txt
#
#################################
if [ $# -lt 1 ] ; then
echo "Usage: sh parse.sh <input_file>"
exit 0
fi
while read line ; do
age=`echo $line | cut -f3 -d"|"`
first_name=`echo $line | cut -f1 -d"|"`
if [ $age -gt 18 ]; then
echo "$first_name is growup"
else
echo "$first_name is a child"
fi
done < $1

2. Tomcat7的默认项目配置
Tomcat的所有项目都是放在Webapps目录下的,当我们访问Tomcat根目录, 默认情况下会访问webapps目录下的Root项目,可以通过修改Tomcat目录下的配置文件conf/server.xml,来设置自己想要的默认项目,只需要在server.xml的Host节点下添加Context节点,并把其docBase属性设置为自己的项目名即可。
<Service name="Catalina">
...
<Engine name="Catalina" defaultHost="localhost">
...
<Host name="localhost">
<Context path="" docBase="<your project name>"/>
</Host>
</Engine>
</Service>


3. Tomcat7 通过Access log记录所有request的performance
Tomcat服务器默认会记录下所有的请求,这其实是一个很好的performance记录,在我们系统中可以把这个文件导入到Splunk中,然后就可以获得整个系统的Performance状态。Tomcat7中关于access log的配置在conf/server.xml中, 如下:
<Service name="Catalina">
...
<Engine name="Catalina" defaultHost="localhost">
...
<Host name="localhost">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" resolveHosts="false" />
...
</Host>
</Engine>
</Service>

通过修改日志记录的格式,可以获取基于每个Request的各种信息,包括每个request消耗的时间,从哪儿来的等等,其日志格式支持的参数有:
%a - Remote IP address
%A - Local IP address
%b - Bytes sent, excluding HTTP headers, or '-' if zero
%B - Bytes sent, excluding HTTP headers
%h - Remote host name (or IP address if enableLookups for the connector is false)
%H - Request protocol
%l - Remote logical username from identd (always returns '-')
%m - Request method (GET, POST, etc.)
%p - Local port on which this request was received
%q - Query string (prepended with a '?' if it exists)
%r - First line of the request (method and request URI)
%s - HTTP status code of the response
%S - User session ID
%t - Date and time, in Common Log Format
%u - Remote user that was authenticated (if any), else '-'
%U - Requested URL path
%v - Local server name
%D - Time taken to process the request, in millis
%T - Time taken to process the request, in seconds
%F - Time taken to commit the response, in millis
%I - Current request thread name (can compare later with stacktraces)
%{xxx}i for incoming headers
%{xxx}o for outgoing response headers
%{xxx}c for a specific cookie
%{xxx}r xxx is an attribute in the ServletRequest
%{xxx}s xxx is an attribute in the HttpSession
%{xxx}t xxx is an enhanced SimpleDateFormat pattern

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-337673-1-1.html 上篇帖子: Tomcat中将第三方jar移出你的WEB-INF/LIB 下篇帖子: freemarker 在tomcat中生成文件编码问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表