Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions usage/src/main/java/com/cloud/usage/UsageSanityChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,19 @@ protected void checkMaxUsage() throws SQLException {
}
int aggregationHours = aggregationRange / 60;

addCheckCase("SELECT count(*) FROM `cloud_usage`.`cloud_usage` cu where usage_type not in (4,5) and raw_usage > "
+ aggregationHours,
addCheckCase("SELECT count(*) FROM `cloud_usage`.`cloud_usage` cu where usage_type not in (4,5,13) and raw_usage > " + aggregationHours,
"usage records with raw_usage > " + aggregationHours,
lastCheckId);

addCheckCase("SELECT count(*) " +
" FROM ( SELECT cu.id, max(cu.raw_usage)/count(n.id) as avg_usage " +
" FROM `cloud_usage`.`cloud_usage` AS cu " +
" INNER JOIN cloud.nics AS n ON (n.instance_id = cu.vm_instance_id) " +
" WHERE cu.usage_type = 13 AND ((n.created <= cu.end_date) AND (n.removed is null OR n.removed > cu.start_date)) " +
" GROUP BY cu.id) as cu " +
" WHERE cu.avg_usage > " + aggregationHours,
"network offering usage records with raw_usage > " + aggregationHours,
lastCheckId);
}

private static int getAggregationRange(int aggregationRange, PreparedStatement pstmt) {
Expand Down Expand Up @@ -175,8 +184,17 @@ protected void checkVolumeUsage() {
}

protected void checkTemplateISOUsage() {
addCheckCase("select count(*) from cloud_usage.cloud_usage cu inner join cloud.template_zone_ref tzr where "
+ "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 ",
addCheckCase("SELECT count(*) " +
" FROM cloud_usage.cloud_usage AS cu " +
" INNER JOIN cloud.template_zone_ref AS c_tzr ON ( c_tzr.template_id = cu.usage_id " +
" AND c_tzr.zone_id = cu.zone_id) " +
" WHERE cu.usage_type in (7,8) " +
" AND cu.start_date > c_tzr.removed " +
" AND NOT EXISTS ( SELECT 1 " +
" FROM cloud.template_zone_ref c_tzr_internal " +
" WHERE c_tzr_internal.template_id = c_tzr.template_id " +
" AND c_tzr_internal.zone_id = c_tzr.zone_id " +
" AND c_tzr_internal.removed IS NULL) ",
"template/ISO usage records which are created after it is removed",
lastCheckId);
}
Expand All @@ -196,6 +214,7 @@ protected void readLastCheckId(){
String lastIdText = null;
lastId = -1;
if ((lastIdText = reader.readLine()) != null) {
LOGGER.info("Read {} as lastId for Usage sanity checking.", lastIdText);
lastId = Integer.parseInt(lastIdText);
}
} catch (Exception e) {
Expand All @@ -214,7 +233,9 @@ protected void readMaxId() throws SQLException {
maxId = -1;
if (rs.next() && (rs.getInt(1) > 0)) {
maxId = rs.getInt(1);
LOGGER.info("Read {} as maxId for Usage sanity checking.", maxId);
if (maxId > lastId) {
LOGGER.info("The max id {} is greater than the last id {}; adding id check to the query.", maxId, lastId);
lastCheckId += " and cu.id <= ?";
}
}
Expand Down