2017-01-19 32 views
1

我有下面的日誌文件,正在使用NodeJS編寫日誌監視。我的解析器是基於正則表達式的,所以如果我在日誌文件中收到可以轉換成多條日誌消息的新行,我應該能夠提取它們。對於我需要一個rtegex提取variouys日誌消息提取日誌RegEX中2個時間戳模式之間的消息

Fri Jan 24 05:28:57 2014 
MEMORY_TARGET defaulting to 1128267776. 
* instance_number obtained from CSS = 1, checking for the existence of node 0... 
* node 0 does not exist. instance_number = 1 
Starting ORACLE instance (normal) 
LICENSE_MAX_SESSION = 0 
LICENSE_SESSIONS_WARNING = 0 
Initial number of CPU is 48 
Number of processor cores in the system is 24 
Number of processor sockets in the system is 12 
Private Interface 'nxge20:1' configured from GPnP for use as a private interconnect. 
abc 
    [name='nxge20:1', type=1, ip=169.254.121.29, mac=00-21-28-0e-8c-ae-00-00-00-00-00-00-00-00-00-00-00-2f-ff-ff, net=169.254.0.0/16, mask=255.255.0.0, use=haip:cluster_interconnect/62] 
Public Interface 'nxge0' configured from GPnP for use as a public interface. 
    [name='nxge0', type=1, ip=172.20.70.18, mac=00-21-28-0e-94-ce-00-00-00-00-00-00-00-00-00-00-00-2f-ff-ff, net=172.20.70.0/24, mask=255.255.255.0, use=public/1] 
Public Interface 'nxge21' configured from GPnP for use as a public interface. 
    [name='nxge21', type=1, ip=100.100.100.1, mac=00-21-28-0e-8c-af-00-00-00-00-00-00-00-00-00-00-00-2f-ff-ff, net=100.100.100.0/23, mask=255.255.254.0, use=public/1] 
Shared memory segment for instance monitoring created 
CELL communication is configured to use 0 interface(s): 
CELL IP affinity details: 
    NUMA status: NUMA system w/ 3 process groups 
    cellaffinity.ora status: cannot find affinity map at '/etc/oracle/cell/network-config/cellaffinity.ora' (see trace file for details) 
CELL communication will use 1 IP group(s): 
    Grp 0: 
Picked latch-free SCN scheme 3 
Using LOG_ARCHIVE_DEST_1 parameter default value as /dbtop/grid/dbs/arch 
Autotune of undo retention is turned on. 
LICENSE_MAX_USERS = 0 
SYS auditing is disabled 
NOTE: Volume support enabled 
NUMA system with 3 nodes detected 
Starting up: 
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production 
With the Real Application Clusters and Automatic Storage Management options. 
ORACLE_HOME = /dbtop/grid 
System name: SunOS 
Node name: sec33-e 
Release: 5.10 
Version: Generic_142909-17 
Machine: sun4u 
Using parameter settings in server-side spfile /dbtop/asm/dbs/spfile+ASM.ora 
System parameters with non-default values: 
    large_pool_size   = 12M 
    instance_type   = "asm" 
    remote_login_passwordfile= "EXCLUSIVE" 
    asm_diskstring   = "/dev/rdsk/*" 
    asm_diskgroups   = "WFREC" 
    asm_diskgroups   = "WFDATA" 
    asm_power_limit   = 7 
    diagnostic_dest   = "/dbtop/app/oracle" 
Cluster communication is configured to use the following interface(s) for this instance 
    169.254.121.29 
cluster interconnect IPC version:Oracle UDP/IP (generic) 
IPC Vendor 1 proto 2 
Fri Jan 24 05:29:03 2014 
PMON started with pid=2, OS id=17520 
Fri Jan 24 05:29:04 2014 
PSP0 started with pid=3, OS id=17521 
Fri Jan 24 05:29:05 2014 
VKTM started with pid=4, OS id=17522 at elevated priority 
VKTM running at (10)millisec precision with DBRM quantum (100)ms 

我已經嘗試使用下面的正則表達式來匹配組中的DATATIME和地點:

(\w{1,3} \w{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}) 

其匹配的時間戳,如何我可以GRAP日誌消息的其餘部分在第二組

+0

見['/ ^([AZ] {1,3} [AZ] {1,3} \ d {1,2} \ d {1,2}:\ d {1,2}:\ d {1,2} \ d {4})\ r?\ n(。*(?:\ r?\ n(?![az] {1,3} [az] {1,3} \ d {1,2} \ d {1,2}:\ d {1,2}:\ d {1,2} \ d {4})*)*)/ gmi'](https://regex101.com/r/1hRWqW/1)。 –

+0

非常感謝它的工作:) – user7442303

回答

1

你可以使用

/^([a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4})\r?\n(.*(?:\r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}).*)*)/igm 

查看regex demo

該模式包括您的模式和與該模式或文本結尾匹配的附加部分。

  • ^ - 第1組相匹配的時間戳
  • \r?\n - - 換行符
  • (.*(?:\r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}).*)*) - 組2捕獲0+的序列的線
  • ([a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4})的開始:
    • .* - 任何0+字符儘可能多達到換行符char
    • (?:\r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}).*)* - 零個或多個的:
      • \r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}) - 換行符後面沒有與時間戳圖案
      • .* - 任何0+字符儘可能多至換行符炭。

JS演示:

var rx = /^([a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4})\r?\n(.*(?:\r?\n(?![a-z]{1,3} [a-z]{1,3} \d{1,2} \d{1,2}:\d{1,2}:\d{1,2} \d{4}).*)*)/gmi; 
 
var str = "Fri Jan 24 05:28:57 2014\r\nMEMORY_TARGET defaulting to 1128267776.\r\n* instance_number obtained from CSS = 1, checking for the existence of node 0... \r\n* node 0 does not exist. instance_number = 1 \r\nStarting ORACLE instance (normal)\r\nLICENSE_MAX_SESSION = 0\r\nLICENSE_SESSIONS_WARNING = 0\r\nInitial number of CPU is 48\r\nNumber of processor cores in the system is 24\r\nNumber of processor sockets in the system is 12\r\nPrivate Interface 'nxge20:1' configured from GPnP for use as a private interconnect.\r\nabc\r\n [name='nxge20:1', type=1, ip=169.254.121.29, mac=00-21-28-0e-8c-ae-00-00-00-00-00-00-00-00-00-00-00-2f-ff-ff, net=169.254.0.0/16, mask=255.255.0.0, use=haip:cluster_interconnect/62]\r\nPublic Interface 'nxge0' configured from GPnP for use as a public interface.\r\n [name='nxge0', type=1, ip=172.20.70.18, mac=00-21-28-0e-94-ce-00-00-00-00-00-00-00-00-00-00-00-2f-ff-ff, net=172.20.70.0/24, mask=255.255.255.0, use=public/1]\r\nPublic Interface 'nxge21' configured from GPnP for use as a public interface.\r\n [name='nxge21', type=1, ip=100.100.100.1, mac=00-21-28-0e-8c-af-00-00-00-00-00-00-00-00-00-00-00-2f-ff-ff, net=100.100.100.0/23, mask=255.255.254.0, use=public/1]\r\nShared memory segment for instance monitoring created\r\nCELL communication is configured to use 0 interface(s):\r\nCELL IP affinity details:\r\n NUMA status: NUMA system w/ 3 process groups\r\n cellaffinity.ora status: cannot find affinity map at '/etc/oracle/cell/network-config/cellaffinity.ora' (see trace file for details)\r\nCELL communication will use 1 IP group(s):\r\n Grp 0: \r\nPicked latch-free SCN scheme 3\r\nUsing LOG_ARCHIVE_DEST_1 parameter default value as /dbtop/grid/dbs/arch\r\nAutotune of undo retention is turned on. \r\nLICENSE_MAX_USERS = 0\r\nSYS auditing is disabled\r\nNOTE: Volume support enabled\r\nNUMA system with 3 nodes detected\r\nStarting up:\r\nOracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production\r\nWith the Real Application Clusters and Automatic Storage Management options.\r\nORACLE_HOME = /dbtop/grid\r\nSystem name: SunOS\r\nNode name: sec33-e\r\nRelease: 5.10\r\nVersion: Generic_142909-17\r\nMachine: sun4u\r\nUsing parameter settings in server-side spfile /dbtop/asm/dbs/spfile+ASM.ora\r\nSystem parameters with non-default values:\r\n large_pool_size   = 12M\r\n instance_type   = \"asm\"\r\n remote_login_passwordfile= \"EXCLUSIVE\"\r\n asm_diskstring   = \"/dev/rdsk/*\"\r\n asm_diskgroups   = \"WFREC\"\r\n asm_diskgroups   = \"WFDATA\"\r\n asm_power_limit   = 7\r\n diagnostic_dest   = \"/dbtop/app/oracle\"\r\nCluster communication is configured to use the following interface(s) for this instance\r\n 169.254.121.29\r\ncluster interconnect IPC version:Oracle UDP/IP (generic)\r\nIPC Vendor 1 proto 2\r\nFri Jan 24 05:29:03 2014\r\nPMON started with pid=2, OS id=17520 \r\nFri Jan 24 05:29:04 2014\r\nPSP0 started with pid=3, OS id=17521 \r\nFri Jan 24 05:29:05 2014\r\nVKTM started with pid=4, OS id=17522 at elevated priority\r\nVKTM running at (10)millisec precision with DBRM quantum (100)ms"; 
 
var m, res = []; 
 

 
while ((m = rx.exec(str)) !== null) { 
 
    res.push([m[1], m[2]]); 
 
} 
 
console.log(res);