7 月 272016
 
curl -o /dev/null -s -w %{http_code}:%{http_connect}:%{content_type}:%{time_namelookup}:%{time_redirect}:%{time_pretransfer}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} linuxcache.com

使用curl测试web页面响应加载速度的参数明细

[root@localhost tmp]# curl -V
curl 7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
Protocols: tftp ftp telnet dict ldap ldaps http file https ftps scp sftp
Features: GSS-Negotiate IDN IPv6 Largefile NTLM SSL libz
[root@localhost tmp]# ]

The variables available at this point are:

url_effective The URL that was fetched last. This is most meaningful if you’ve told
curl to follow location: headers.

http_code The numerical response code that was found in the last retrieved
HTTP(S) or FTP(s) transfer. In 7.18.2 the alias response_code was
added to show the same info.

http_connect The numerical code that was found in the last response (from a proxy)
to a curl CONNECT request. (Added in 7.12.4)

time_total The total time, in seconds, that the full operation lasted. The time
will be displayed with millisecond resolution.

time_namelookup
The time, in seconds, it took from the start until the name resolving
was completed.

time_connect The time, in seconds, it took from the start until the TCP connect to
the remote host (or proxy) was completed.

time_appconnect
The time, in seconds, it took from the start until the SSL/SSH/etc
connect/handshake to the remote host was completed. (Added in 7.19.0)

time_pretransfer
The time, in seconds, it took from the start until the file transfer
was just about to begin. This includes all pre-transfer commands and
negotiations that are specific to the particular protocol(s) involved.

time_redirect The time, in seconds, it took for all redirection steps include name
lookup, connect, pretransfer and transfer before the final transaction
was started. time_redirect shows the complete execution time for mul-
tiple redirections. (Added in 7.12.3)

time_starttransfer
The time, in seconds, it took from the start until the first byte was
just about to be transferred. This includes time_pretransfer and also
the time the server needed to calculate the result.

size_download The total amount of bytes that were downloaded.

size_upload The total amount of bytes that were uploaded.

size_header The total amount of bytes of the downloaded headers.

size_request The total amount of bytes that were sent in the HTTP request.
speed_download The average download speed that curl measured for the complete down-
load.

speed_upload The average upload speed that curl measured for the complete upload.

content_type The Content-Type of the requested document, if there was any.

num_connects Number of new connects made in the recent transfer. (Added in 7.12.3)

num_redirects Number of redirects that were followed in the request. (Added in
7.12.3)

redirect_url When a HTTP request was made without -L to follow redirects, this
variable will show the actual URL a redirect would take you to. (Added
in 7.18.2)

ftp_entry_path The initial path libcurl ended up in when logging on to the remote FTP
server. (Added in 7.15.4)

ssl_verify_result
The result of the SSL peer certificate verification that was
requested. 0 means the verification was successful. (Added in 7.19.0)

7 月 152016
 

 

修改环境变量配置文件,将历史命令条数由默认1000条改为5000条,使用可供查看的时间格式输出历史命令。

#
#!/bin/bash

#vi /etc/profile
#HISTSIZE=5000
#export HISTTIMEFORMAT=’%F %T ‘
#source /etc/profile
#echo “” > .bash_history

yesterday=`date -d ‘-1 day’ +%Y-%m-%d`

history > /tmp/history.tmp

cat /tmp/history.tmp |grep $yesterday > /tmp/sc.tmp

cat /tmp/sc.tmp |grep startup.sh > /tmp/sc.$yesterday

exit 0;

0 2 * * * root /tmp/startcounter.sh

7 月 042016
 

下载地址:
https://github.com/javamelody/javamelody/releases
提取jar文件并放置
javamelody-1.60.0.zip

apache-tomcat-javamelody-monitoring-01javamelody.jar
jrobin-1.5.9.1.jar
webapps/appname/WEB-INF/lib

修改web.xml禁用或启用此服务,可通过注释或取消注释来停止此服务的访问,且加入注释停止服务时无需重启tomcat。

<!--
 <filter>
 <filter-name>monitoring</filter-name>
 <filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
 </filter>
 <filter-mapping>
 <filter-name>monitoring</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>
 <listener>
 <listener-class>net.bull.javamelody.SessionListener</listener-class>
 </listener>
-->

自v1.53版本新增的基本http登录验证功能示例

<filter>
 <filter-name>javamelody</filter-name>
 <filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
 <init-param>
 <param-name>authorized-users</param-name>
 <param-value>user1:pwd1, user2:pwd2</param-value>
 </init-param>
</filter>

JavaMelody中文乱码处理(删除中文语言包)

apache-tomcat-javamelody-monitoring-02
完整配置示例

apache-tomcat-javamelody-monitoring-03

apache-tomcat-javamelody-monitoring-04

7 月 012016
 

使用脚本定时备份MongoDB指定数据库

[root@localhost ~]# mkdir -p /data/backup
[root@localhost ~]# mkdir -p /data/backup/mongo
[root@localhost ~]# cd /data/backup

[root@localhost backup]# cat mbackup.sh 
#
#!/bin/bash

cd /data/backup

mkdir -p risk.`date +%y%m%d`

mongodump -uusername -p12345678 -d risk -o risk.`date +%y%m%d`

sleep 2;

tar czf mongo/risk.`date +%y%m%d`.tgz risk.`date +%y%m%d`

sleep 2;

rm -rf risk.`date +%y%m%d`

exit 0;
[root@localhost backup]#
7 月 012016
 

使用脚本定时获取接口动态IP并处理保存

[root@localhost tmp]# cat listip.sh
#
#!/bin/bash

# run @ every 3 hour

cd /tmp/
#执行ping获取花生壳服务所返回的接口IP地址
/bin/ping ddns.domain.com -c 1 |grep 'time=' |awk {'print $4'} > listip.tmp
#处理IP地址后面的:符号
newip=$(sed -e 's/.$//' listip.tmp)
#将处理过的IP存入按日生成临时文件
echo $newip >> ip.`date +%y%m%d`.tmp

exit 0;
[root@localhost tmp]# cat getip.sh
#
#!/bin/bash

# run @ everyday 23:50

cd /tmp/
#对按日生成临时文件中的IP地址进行排序并去除重复行导入按日保存文件
sort -k2n ip.`date +%y%m%d`.tmp |uniq > ip.`date +%y%m%d`.txt

rm -f ip.`date +%y%m%d`.tmp

exit 0;
[root@localhost tmp]#