2016年10月26日 星期三

LogAnalyzer Delete Records

loganalyzer 真是一套不錯的 OpenSource ,
用它來收集與分析 syslog  message 最簡單實用不過了!

官網
http://loganalyzer.adiscon.com/

Demo
http://loganalyzer-demo.adiscon.com/

但這次想做的是,刪除2015年前的舊資料,參考官網上的說明如下:

http://wiki.rsyslog.com/index.php/LogAnalyzer_Delete_Records

.....


Samples

All samples assume that the data to be deleted is contained in logstream 2.

Delete all data
  php maintenance.php cleardata 2 all

Delete all data older then 1 hour
  php maintenance.php cleardata 2 olderthan 3600

Some typical values are
60 - one minute
3,600 - one hour
86400 - one day
2592000 - 30 days, roughly one month

Delete all data before 2008-11-18
  php maintenance.php cleardata 2 date 11 18 2008
....


簡單的說透過 maintenance.php 這支程式即可完成該項作業。

maintenance.php (程式內文節錄如下:)( 這裡也有 Sample )

那個 ID 可透過 WEB 介面去查詢到..


149 // --- BEGIN Custom Code
150         //Additional Includes
151         include($gl_root_path . 'include/functions_debugoutput.php');
152 
153         // Run into Commandline part now!
154         /* Only run if we are in command line mode 
155         *       
156         *       Possible Operation Types:
157         *       cleandata               =       If you want to clear data from a logstream source, you can use the operation type. 
158         *                                               Be carefull using this option, any deletion process cannot be undone!
159         *                                               Sample 1: Delete all data in the logstream with id 2
160         *                                                       php maintenance.php cleandata 2 all
161         *                                               Sample 2: Delete all data older then 60 seconds in the logstream with id 2
162         *                                                       php maintenance.php cleandata 2 olderthan 60
163         *                                               Sample 3: Delete all data before 2008-11-18 in the logstream with id 2
164         *                                                       php maintenance.php cleandata 2 date 11 18 2008 
165         *
166         */


ID 怎麼來圖解如下,官網中也有說明:





該程式放在 cron 這個目錄中.

[root@cacti cron]# pwd
/var/www/html/loganalyzer/cron

[root@cacti cron]# ls -la
total 36
drwxr-xr-x  2 root root 4096 Oct 27 11:39 .
drwxr-xr-x 14 root root 4096 Oct 27 10:35 ..
-rw-r--r--  1 root root 7551 May 17  2013 cmdreportgen.php
-rw-r--r--  1 root root   31 May 17  2013 .htaccess
-rw-r--r--  1 root root   68 May 17  2013 maintenance.bat
-rw-r--r--  1 root root 7251 May 17  2013 maintenance.php
-rw-r--r--  1 root root   89 May 17  2013 maintenance.sh
[root@cacti cron]#

實作吧~

[root@cacti cron]# php maintenance.php cleandata 1 date 1 1 2015 
Num. Facility . Debug Message
1. Information. CleanData. Cleaning data for logstream source 'My Syslog Source'.
2. Information. CleanData. Successfully connected and found '3203148' rows in the logstream source.
3. Information. CleanData. Performing deletion of data entries older then '2015-01-01'.
4. Information. CleanData. Successfully Deleted '446346' rows in the logstream source.'
[root@cacti cron]# 


再透過 mysqlcheck 指令,檢查及優化 MySQL 資料庫 ,並釋放出刪除資料後磁碟空間

[root@cacti cron]# mysqlcheck -a -c  -o -r Syslog 
Syslog.SystemEvents                                OK
Syslog.SystemEventsProperties                      OK
Syslog.logcon_charts                               OK
Syslog.logcon_config                               OK
Syslog.logcon_dbmappings                           OK
Syslog.logcon_fields                               OK
Syslog.logcon_groupmembers                         OK
Syslog.logcon_groups                               OK
Syslog.logcon_savedreports                         OK
Syslog.logcon_searches                             OK
Syslog.logcon_sources                              OK
Syslog.logcon_users                                OK
Syslog.logcon_views                                OK
[root@cacti cron]#

前後對照如下:
(前)
[root@cacti cron]# du /var/lib/mysql/* -hs 
51M /var/lib/mysql/cacti
10M /var/lib/mysql/ibdata1
5.0M /var/lib/mysql/ib_logfile0
5.0M /var/lib/mysql/ib_logfile1
1000K /var/lib/mysql/mysql
0 /var/lib/mysql/mysql.sock
656M /var/lib/mysql/Syslog
4.0K /var/lib/mysql/test

(後)
[root@cacti cron]# du /var/lib/mysql/* -hs 
51M /var/lib/mysql/cacti
10M /var/lib/mysql/ibdata1
5.0M /var/lib/mysql/ib_logfile0
5.0M /var/lib/mysql/ib_logfile1
1000K /var/lib/mysql/mysql
0 /var/lib/mysql/mysql.sock
446M /var/lib/mysql/Syslog
4.0K /var/lib/mysql/test
[root@cacti cron]#

完工

沒有留言:

張貼留言