2018年6月21日 星期四

tomcat access log

改  server.xml  裡的 AccessLogValue


http://xiaobaoqiu.github.io/blog/2014/12/30/tomcat-access-logpei-zhi/

pattern属性有一系列的字符串参数组成,每个参数都有前缀"%“,目前支持下面这些参数:
%a - 远程IP地址
%A - 本地IP地址
%b - 发送的字节数(Bytes sent), 不包括HTTP headers的字节,如果为0则展示'-'
%B - 发送的字节数(Bytes sent), 不包括HTTP headers的字节
%h - 远程主机名称(如果resolveHosts为false则展示IP)
%H - 请求协议
%l - 远程用户名,始终为'-'(Remote logical username from identd)
%m - 请求的方法(GET, POST等)
%p - 接受请求的本地端口
%q - 查询字符串,如果存在,有一个前置的'?'
%r - 请求的第一行(包括请求方法和请求的URI)
%s - response的HTTP状态码(200,404等)
%S - 用户的session ID
%t - 日期和时间,Common Log Format格式
%u - 被认证的远程用户, 不存在则展示'-'
%U - 请求URL路径
%v - 本地服务名
%D - 处理请求的时间,单位为毫秒
%T - 处理请求的时间,单位为秒
%I - 当前请求的线程名(can compare later with stacktraces)
另外,Access Log中也支持cookie,请求header,响应headers,Session或者其他在ServletRequest中的对象的信息。格式遵循apache语法:
%{xxx}i 请求headers的信息
%{xxx}o 响应headers的信息
%{xxx}c 请求cookie的信息
%{xxx}r xxx是ServletRequest的一个属性
%{xxx}s xxx是HttpSession的一个属性
common模式的pattern(即默认pattern参数)的格式为'%h %l %u %t “%r” %s %b'。
combined模式的pattern可以增加Referer和User-Agent headers的参数形式,每个参数用双引号包起来,引号中的内容还是上面列举的参数。比如"%{User-Agent}i"使其为”%{User-Agent}i“,即请求的User-Agent(客户端,浏览器)。
pattern="%a %{X-Forwarded-For}i %l %u %t %r %s %b %{User-Agent}i %{Referer}i (%I,%S)"











df 與 du 不一致


https://unix.stackexchange.com/questions/13828/df-says-i-have-20g-more-disk-space-used-than-du-why

That's because du and df measure different things.
man du says:
du - estimate file space usage (...) Summarize disk usage of each FILE, recursively for directories.
and man df:
df - report file system disk space usage
File system has inode tables, journals etc. which are not summarized by du. It isn't only Linux-specific, but rather UNIX-specific (or even UNIX-filesystem-specific). Because UNIX's processes uses files to everything (I'm simplifying) i.e. writing to log files, there could be also open file descriptorproblem in this case causing different du and df outputs.

例如 inode Table 也會佔空間

The inode table (as well as a few very much smaller things) is included in the used space. It looks like you have about 18GB of inodes. That's around 6% of the space, which is in the expected ballpark for ext2/ext3/ext4 (filesystems that don't have an inode table are likely to have larger directory entries if nothing else). You can find the precise size used for inodes by running tune2fs -l /dev/mapper/VolGroup00-LogVol00, e.g. here are the relevant lines for one of my 20GB ext3 filesystems:
Inode count:              2622368
Inode size:               128
That partition has 2622368×128 B ≈ 320 MB of inodes.
Additional note: the way you've invoked du, you'll see spaced used by every file even on remote mounts and other non-directly-disked-backed filesystems. Run du -x / to see just what's stored on the root filesystem.
可以用 tune2fs -l /dev/mapper/VolGroup00-LogVol00 看 inode Table 大小
可以用 du -x / 看沒有 mount 之前的大小 (排除  mount 的部分)




如何看 mount point 底下原本的東西
https://community.spiceworks.com/topic/1111816-finding-what-data-is-under-an-nfs-mount-point

Here is an example using the --bind option to "mount".
Starting out with nothing mounted at /mnt/nfs
Text
# ls -l /mnt/nfs
total 0
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.1
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.2
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.3
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.4
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.5

Mount something at /mnt/nfs

Text
# mount -o loop /Archive/ISO/sample.iso  /mnt/nfs
mount: warning: /mnt/nfs seems to be mounted read-only.

Listing the contents of /mnt/nfs  this time confirms the contents of the mounted iso file, not the test files:

Text
# ls -l /mnt/nfs
total 345162
-r-xr-xr-x 1 root root    139264 Jun 24  2011 AUTORUN.EXE
dr-xr-xr-x 1 root root      2048 Jun 24  2011 UNIX
dr-xr-xr-x 1 root root      2048 Jun 24  2011 UTILS
-r-xr-xr-x 1 root root      1954 Jun 24  2011 autorun.inf
-r-xr-xr-x 1 root root        12 Jun 24  2011 media.inf

Mount the root fs using "--bind" to have it appear under a new mount point: 
Text
# mount --bind / /new-root 

Now,  cd'ing to /new-root/mnt/nfs, you are not in the mountpoint directory of the ISO filesystem 

Text
# cd /new-root/mnt/nfs

Confirm by listing the contents of /new-root/mnt/nfs and you will see the contents of /mnt/nfs from before its use a mountpoint.
 
 # ls -l
total 0
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.1
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.2
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.3
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.4
-rw-r--r-- 1 root root 0 Aug  7 09:36 test_file.5


還有一種可能

https://www.ndchost.com/wiki/troubleshooting/df-and-du-show-different-usage

There are times when the du and df commands can show different disk usage stats. The usual reason for this is that a running process still has a file that was removed open. This causes df to still report that space as used. The solution to this issue is to reload or restart that service so that it closes that file handle.
lsof is a tool that can be used to find processes holding onto files. If you do not have lsof installed, you will need to install it using your package manager. Examples of how to do this are below.
# Debian and Ubuntu
apt-get install lsof
 
# CentOS, RHEL, and Fedora
yum install lsof
Next we want to use lsof to find the process
lsof | grep deleted
If you get any output changes are it looks something like this.
httpd     32617    nobody  106w      REG        9,4 1835222944     688166 /var/log/apache/awstats_log (deleted)
In this case, the process httpd is whats holding onto an 18GB file. You can either kill that process, or issue a restart using init.d or systemctl
# systemctl systems
systemctl restart httpd
 
# Older init.d systems
service httpd restart
 
# Even older systems
/etc/init.d/httpd restart
If the process doesn't have an init script you will need to restart it another way, or as a last resort kill the process. The second column output from lsof is the process id.
kill -9 32617
Now when running df again you should now see df reporting correctly.















2018年6月5日 星期二

Oracle LogMiner


SUPPLEMENTAL_LOG_DATA

查詢

select SUPPLEMENTAL_LOG_DATA_MIN min,
       SUPPLEMENTAL_LOG_DATA_PK  pk,
       SUPPLEMENTAL_LOG_DATA_UI  ui,
       SUPPLEMENTAL_LOG_DATA_FK  fk,
       SUPPLEMENTAL_LOG_DATA_ALL "all"
  from v$database;

開 min

alter database add supplemental log data ;

關閉

alter database drop supplemental log data ;


删除SUPPLEMENTAL LOG DATA需要先删除其他的追加日志,可以通过查看v$database检查是否还有没有关闭的

select SUPPLEMENTAL_LOG_DATA_ALL
,SUPPLEMENTAL_LOG_DATA_FK
,SUPPLEMENTAL_LOG_DATA_MIN
,SUPPLEMENTAL_LOG_DATA_PK
,SUPPLEMENTAL_LOG_DATA_UI from v$database;


可以先删除某些键值的追加日志,执行例如:

ALTER DATABASE DROP SUPPLEMENTAL LOG DATA (PRIMARY KEY) COLUMNS;
ALTER DATABASE DROP SUPPLEMENTAL LOG DATA (UNIQUE) COLUMNS;
ALTER DATABASE DROP SUPPLEMENTAL LOG DATA (FOREIGN KEY) COLUMNS;
ALTER DATABASE DROP SUPPLEMENTAL LOG DATA;

ref :
https://hk.saowen.com/a/0a25fb4bedb5e7be62acc321e6c473ef20e7773fb9349bd1c1054e808d78311d

http://blog.51cto.com/sugarlovecxq/1693092 Oracle中的补充日志(supplemental log)


確認是否在 archived mode


select log_mode from v$database;

起始安裝


run as SYSDBA

$ORACLE_HOME/rdbms/admin/dbmslm.sql

$ORACLE_HOME/rdbms/admin/dbmslmd.sql





在本機的場合


execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168869.dbf',options=>dbms_logmnr.new);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168870.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168871.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168872.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168873.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168874.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168875.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168876.dbf',options=>dbms_logmnr.addfile);
execute dbms_logmnr.add_logfile(logfilename=>'/tst/arch1_168877.dbf',options=>dbms_logmnr.addfile);


第一個用 new 之後用 addfile

然後可以在 V_$logmnr_logs 看到剛才放進去的 log

然後
execute dbms_logmnr.start_logmnr(options=>dbms_logmnr.dict_from_online_catalog);

然後可以在 V_logmnr_contents 看到剛剛產生的結果

然後

select operation,table_name from v_$logmnr_contents where operation='DELETE' and table_name='TRACE_LOG';

把需要的資料轉存成table (只有這個session 可以看到 V_$logmnr_* 的內容)

然後

execute dbms_logmnr.end_logmnr;

釋放資源


在別機的場合


CREATE DIRECTORY utlfile AS '/rman_disk/logminer/utlfile';
alter system set utl_file_dir='/rman_disk/logminer/utlfile' scope=spfile;

EXECUTE dbms_logmnr_d.build(dictionary_filename => 'dictionary.ora', dictionary_location =>'/rman_disk/logminer/utlfile');

起始 UTL_FILE 參數位置 沒在 init 時設好的話可能會看到

ERROR at line 1:
ORA-01308: initialization parameter utl_file_dir is not set
ORA-06512: at "SYS.DBMS_LOGMNR_INTERNAL", line 3669
ORA-06512: at "SYS.DBMS_LOGMNR_INTERNAL", line 3747
ORA-06512: at "SYS.DBMS_LOGMNR_D", line 12
ORA-06512: at line 1

--可以用 show parameter UTL_FILE 確認
-- utl_file_dir 是 init param , 不能用 alter system both 設定

SQL> alter system set utl_file_dir='/rman_disk/logminer/utlfile' scope=both;  
alter system set utl_file_dir='/rman_disk/logminer/utlfile' scope=both
                 *
ERROR at line 1:
ORA-02095: specified initialization parameter cannot be modified




然後在 start 的時候用

EXECUTE dbms_logmnr.start_logmnr(dictfilename=>'D:\oracle\oradata\practice\LOGMNR\dictionary.ora');




ref:

图解Oracle Logminer配置使用

https://docs.oracle.com/cd/E18283_01/appdev.112/e16760/d_logmnrd.htm   DBMS_LOGMNR_D

Oracle SCN 轉 Timestamp

REF:  http://www.eygle.com/archives/2007/01/scntimestamp_function.html


首先通过dbms_flashback.get_system_change_number 可以获得系统当前的SCN值:
SQL> col scn for 9999999999999
SQL> select dbms_flashback.get_system_change_number scn from dual;
SCN
--------------
8908390522972
通过scn_to_timestamp函数可以将SCN转换为时间戳:
SQL> select scn_to_timestamp(8908390522972) scn from dual;
SCN
---------------------------------------------------------------------------
05-JAN-07 10.56.30.000000000 AM
再通过timestamp_to_scn可以将时间戳转换为SCN:
SQL> select timestamp_to_scn(scn_to_timestamp(8908390522972)) scn from dual;
SCN
--------------
8908390522972
通过这两个函数,最终Oracle将SCN和时间的关系建立起来,在Oracle10g之前,是没有办法通过函数转换得到SCN和时间的对应关系的,一般可以通过logmnr分析日志获得。
但是这种转换要依赖于数据库内部的数据记录,对于久远的SCN则不能转换,请看以下举例:
SQL> select min(FIRST_CHANGE#) scn,max(FIRST_CHANGE#) scn from v$archived_log;
SCN SCN
------------------ ------------------
8907349093953 8908393582271
SQL> select scn_to_timestamp(8907349093953) scn from dual;
select scn_to_timestamp(8907349093953) scn from dual
*
ERROR at line 1:
ORA-08181: specified number is not a valid system change number
ORA-06512: at "SYS.SCN_TO_TIMESTAMP", line 1
ORA-06512: at line 1

SQL> select scn_to_timestamp(8908393582271) scn from dual;
SCN
---------------------------------------------------------------------------
05-JAN-07 11.45.50.000000000 AM
-The End-