| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  | ! Copyright (C) 2008 Slava Pestov. | 
					
						
							|  |  |  | ! See http://factorcode.org/license.txt for BSD license. | 
					
						
							|  |  |  | USING: kernel sequences namespaces words assocs logging sorting | 
					
						
							| 
									
										
										
										
											2008-07-09 17:34:05 -04:00
										 |  |  | prettyprint io io.styles io.files io.encodings.utf8 | 
					
						
							| 
									
										
										
										
											2008-07-09 18:03:16 -04:00
										 |  |  | strings combinators accessors arrays | 
					
						
							| 
									
										
										
										
											2008-07-09 17:34:05 -04:00
										 |  |  | logging.server logging.parser calendar.format ;
 | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  | IN: logging.analysis | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | SYMBOL: word-names | 
					
						
							|  |  |  | SYMBOL: errors | 
					
						
							|  |  |  | SYMBOL: word-histogram | 
					
						
							|  |  |  | SYMBOL: message-histogram | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : analyze-entry ( entry -- )
 | 
					
						
							| 
									
										
										
										
											2008-07-09 18:03:16 -04:00
										 |  |  |     dup level>> { ERROR CRITICAL } memq? [ dup errors get push ] when
 | 
					
						
							| 
									
										
										
										
											2008-12-09 17:54:48 -05:00
										 |  |  |     dup word-name>> word-histogram get inc-at
 | 
					
						
							| 
									
										
										
										
											2008-07-09 18:03:16 -04:00
										 |  |  |     dup word-name>> word-names get member? [ | 
					
						
							| 
									
										
										
										
											2008-12-09 17:54:48 -05:00
										 |  |  |         dup [ level>> ] [ word-name>> ] [ message>> ] tri 3array
 | 
					
						
							|  |  |  |         message-histogram get inc-at
 | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  |     ] when
 | 
					
						
							|  |  |  |     drop ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : analyze-entries ( entries word-names -- errors word-histogram message-histogram )
 | 
					
						
							|  |  |  |     [ | 
					
						
							|  |  |  |         word-names set
 | 
					
						
							|  |  |  |         V{ } clone errors set
 | 
					
						
							|  |  |  |         H{ } clone word-histogram set
 | 
					
						
							|  |  |  |         H{ } clone message-histogram set
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |             analyze-entry | 
					
						
							|  |  |  |         ] each
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         errors get
 | 
					
						
							|  |  |  |         word-histogram get
 | 
					
						
							|  |  |  |         message-histogram get
 | 
					
						
							|  |  |  |     ] with-scope ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | : histogram. ( assoc quot -- )
 | 
					
						
							|  |  |  |     standard-table-style [ | 
					
						
							| 
									
										
										
										
											2008-12-03 09:46:16 -05:00
										 |  |  |         [ >alist sort-values <reversed> ] dip [ | 
					
						
							|  |  |  |             [ swapd with-cell pprint-cell ] with-row | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  |         ] curry assoc-each
 | 
					
						
							| 
									
										
										
										
											2009-03-15 19:19:29 -04:00
										 |  |  |     ] tabular-output ; inline
 | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-09 03:14:14 -04:00
										 |  |  | : log-entry. ( entry -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-07 18:20:15 -05:00
										 |  |  |     "====== " write
 | 
					
						
							| 
									
										
										
										
											2008-06-09 03:14:14 -04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2008-07-09 18:03:16 -04:00
										 |  |  |         [ date>> (timestamp>string) bl ] | 
					
						
							|  |  |  |         [ level>> pprint bl ] | 
					
						
							|  |  |  |         [ word-name>> write nl ] | 
					
						
							|  |  |  |         [ message>> "\n" join print ] | 
					
						
							| 
									
										
										
										
											2008-06-09 03:14:14 -04:00
										 |  |  |     } cleave ;
 | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : errors. ( errors -- )
 | 
					
						
							| 
									
										
										
										
											2008-03-07 18:20:15 -05:00
										 |  |  |     [ log-entry. ] each ;
 | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | : analysis. ( errors word-histogram message-histogram -- )
 | 
					
						
							|  |  |  |     "==== INTERESTING MESSAGES:" print nl
 | 
					
						
							|  |  |  |     "Total: " write dup values sum . nl
 | 
					
						
							|  |  |  |     [ | 
					
						
							| 
									
										
										
										
											2008-07-09 18:03:16 -04:00
										 |  |  |         dup level>> write ": " write message>> "\n" join write
 | 
					
						
							| 
									
										
										
										
											2008-02-07 18:07:43 -05:00
										 |  |  |     ] histogram. | 
					
						
							|  |  |  |     nl
 | 
					
						
							|  |  |  |     "==== WORDS:" print nl
 | 
					
						
							|  |  |  |     [ write ] histogram. | 
					
						
							|  |  |  |     nl
 | 
					
						
							|  |  |  |     "==== ERRORS:" print nl
 | 
					
						
							|  |  |  |     errors. ;
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 20:51:37 -05:00
										 |  |  | : analyze-log ( lines word-names -- )
 | 
					
						
							| 
									
										
										
										
											2008-12-03 09:46:16 -05:00
										 |  |  |     [ parse-log ] dip analyze-entries analysis. ;
 | 
					
						
							| 
									
										
										
										
											2008-07-09 17:34:05 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | : analyze-log-file ( service word-names -- )
 | 
					
						
							| 
									
										
										
										
											2008-12-03 09:46:16 -05:00
										 |  |  |     [ parse-log-file ] dip analyze-entries analysis. ;
 |