hq-log-monitor-server 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
| @@ -102,6 +102,12 @@ class Script | |
| 102 102 | 
             
            		@db =
         | 
| 103 103 | 
             
            			@mongo[@db_elem["name"]]
         | 
| 104 104 |  | 
| 105 | 
            +
            		@db["events"].ensure_index \
         | 
| 106 | 
            +
            			"source.service" => Mongo::ASCENDING,
         | 
| 107 | 
            +
            			"source.class" => Mongo::ASCENDING,
         | 
| 108 | 
            +
            			"source.host" => Mongo::ASCENDING,
         | 
| 109 | 
            +
            			"timestamp" => Mongo::ASCENDING
         | 
| 110 | 
            +
             | 
| 105 111 | 
             
            	end
         | 
| 106 112 |  | 
| 107 113 | 
             
            	def init_server
         | 
| @@ -31,26 +31,35 @@ class Script | |
| 31 31 |  | 
| 32 32 | 
             
            		# read from database
         | 
| 33 33 |  | 
| 34 | 
            -
            		 | 
| 34 | 
            +
            		all_events_count =
         | 
| 35 35 | 
             
            			@db["events"]
         | 
| 36 36 | 
             
            				.find({
         | 
| 37 37 | 
             
            					"source.class" => source["class"],
         | 
| 38 38 | 
             
            					"source.host" => source["host"],
         | 
| 39 39 | 
             
            					"source.service" => source["service"],
         | 
| 40 40 | 
             
            				})
         | 
| 41 | 
            -
            				. | 
| 42 | 
            -
            					"timestamp" => -1,
         | 
| 43 | 
            -
            				})
         | 
| 44 | 
            -
            				.to_a
         | 
| 41 | 
            +
            				.count
         | 
| 45 42 |  | 
| 46 43 | 
             
            		page_size = 100
         | 
| 47 44 | 
             
            		page_num = req.GET["page"].to_i
         | 
| 48 45 |  | 
| 49 46 | 
             
            		page_start = page_num * page_size
         | 
| 50 47 | 
             
            		page_end = page_start + page_size
         | 
| 51 | 
            -
            		page_count = ( | 
| 48 | 
            +
            		page_count = (all_events_count + page_size - 1) / page_size
         | 
| 52 49 |  | 
| 53 | 
            -
            		page_events = | 
| 50 | 
            +
            		page_events =
         | 
| 51 | 
            +
            			@db["events"]
         | 
| 52 | 
            +
            				.find({
         | 
| 53 | 
            +
            					"source.class" => source["class"],
         | 
| 54 | 
            +
            					"source.host" => source["host"],
         | 
| 55 | 
            +
            					"source.service" => source["service"],
         | 
| 56 | 
            +
            				})
         | 
| 57 | 
            +
            				.sort({
         | 
| 58 | 
            +
            					"timestamp" => -1,
         | 
| 59 | 
            +
            				})
         | 
| 60 | 
            +
            				.skip(page_start)
         | 
| 61 | 
            +
            				.limit(page_size)
         | 
| 62 | 
            +
            				.to_a
         | 
| 54 63 |  | 
| 55 64 | 
             
            		title =
         | 
| 56 65 | 
             
            			"%s %s \u2014 Log monitor" % [
         | 
| @@ -115,11 +124,11 @@ class Script | |
| 115 124 | 
             
            			esc_ht(title),
         | 
| 116 125 | 
             
            		]
         | 
| 117 126 |  | 
| 118 | 
            -
            		if  | 
| 127 | 
            +
            		if all_events_count > page_size || page_num > 0
         | 
| 119 128 | 
             
            			pagination html, page_count, page_num
         | 
| 120 129 | 
             
            		end
         | 
| 121 130 |  | 
| 122 | 
            -
            		if  | 
| 131 | 
            +
            		if all_events_count == 0
         | 
| 123 132 |  | 
| 124 133 | 
             
            			html << "<p>No events have been logged for this service on this " +
         | 
| 125 134 | 
             
            				"host</p>\n"
         | 
| @@ -196,7 +205,7 @@ class Script | |
| 196 205 | 
             
            			html << "</tbody>\n"
         | 
| 197 206 | 
             
            			html << "</table>\n"
         | 
| 198 207 |  | 
| 199 | 
            -
            			if  | 
| 208 | 
            +
            			if all_events_count > page_size || page_num > 0
         | 
| 200 209 | 
             
            				pagination html, page_count, page_num
         | 
| 201 210 | 
             
            			end
         | 
| 202 211 |  |