@@ -118,10 +118,19 @@ protected void checkMaxUsage() throws SQLException {
118
118
}
119
119
int aggregationHours = aggregationRange / 60 ;
120
120
121
- addCheckCase ("SELECT count(*) FROM `cloud_usage`.`cloud_usage` cu where usage_type not in (4,5) and raw_usage > "
122
- + aggregationHours ,
121
+ addCheckCase ("SELECT count(*) FROM `cloud_usage`.`cloud_usage` cu where usage_type not in (4,5,13) and raw_usage > " + aggregationHours ,
123
122
"usage records with raw_usage > " + aggregationHours ,
124
123
lastCheckId );
124
+
125
+ addCheckCase ("SELECT count(*) " +
126
+ " FROM ( SELECT cu.id, max(cu.raw_usage)/count(n.id) as avg_usage " +
127
+ " FROM `cloud_usage`.`cloud_usage` AS cu " +
128
+ " INNER JOIN cloud.nics AS n ON (n.instance_id = cu.vm_instance_id) " +
129
+ " WHERE cu.usage_type = 13 AND ((n.created <= cu.end_date) AND (n.removed is null OR n.removed > cu.start_date)) " +
130
+ " GROUP BY cu.id) as cu " +
131
+ " WHERE cu.avg_usage > " + aggregationHours ,
132
+ "network offering usage records with raw_usage > " + aggregationHours ,
133
+ lastCheckId );
125
134
}
126
135
127
136
private static int getAggregationRange (int aggregationRange , PreparedStatement pstmt ) {
@@ -175,8 +184,17 @@ protected void checkVolumeUsage() {
175
184
}
176
185
177
186
protected void checkTemplateISOUsage () {
178
- addCheckCase ("select count(*) from cloud_usage.cloud_usage cu inner join cloud.template_zone_ref tzr where "
179
- + "cu.usage_id = tzr.template_id and cu.zone_id = tzr.zone_id and cu.usage_type in (7,8) and cu.start_date > tzr.removed " ,
187
+ addCheckCase ("SELECT count(*) " +
188
+ " FROM cloud_usage.cloud_usage AS cu " +
189
+ " INNER JOIN cloud.template_zone_ref AS c_tzr ON ( c_tzr.template_id = cu.usage_id " +
190
+ " AND c_tzr.zone_id = cu.zone_id) " +
191
+ " WHERE cu.usage_type in (7,8) " +
192
+ " AND cu.start_date > c_tzr.removed " +
193
+ " AND NOT EXISTS ( SELECT 1 " +
194
+ " FROM cloud.template_zone_ref c_tzr_internal " +
195
+ " WHERE c_tzr_internal.template_id = c_tzr.template_id " +
196
+ " AND c_tzr_internal.zone_id = c_tzr.zone_id " +
197
+ " AND c_tzr_internal.removed IS NULL) " ,
180
198
"template/ISO usage records which are created after it is removed" ,
181
199
lastCheckId );
182
200
}
@@ -196,6 +214,7 @@ protected void readLastCheckId(){
196
214
String lastIdText = null ;
197
215
lastId = -1 ;
198
216
if ((lastIdText = reader .readLine ()) != null ) {
217
+ LOGGER .info ("Read {} as lastId for Usage sanity checking." , lastIdText );
199
218
lastId = Integer .parseInt (lastIdText );
200
219
}
201
220
} catch (Exception e ) {
@@ -214,7 +233,9 @@ protected void readMaxId() throws SQLException {
214
233
maxId = -1 ;
215
234
if (rs .next () && (rs .getInt (1 ) > 0 )) {
216
235
maxId = rs .getInt (1 );
236
+ LOGGER .info ("Read {} as maxId for Usage sanity checking." , maxId );
217
237
if (maxId > lastId ) {
238
+ LOGGER .info ("The max id {} is greater than the last id {}; adding id check to the query." , maxId , lastId );
218
239
lastCheckId += " and cu.id <= ?" ;
219
240
}
220
241
}
0 commit comments