tags.put("host", globalConfiguration.hostname); tags.put("systemName", globalConfiguration.systemName); tags.put("statementType", query.statementType().toString());
/** * Constructor. * * @param configuration Module configuration * @param reporters Reporter list * @param globalConfiguration Global diagnostics configuration * @throws ConfigurationException in case the provided module configuration is not valid */ public SlowQueryModule(ModuleConfiguration configuration, List<Reporter> reporters, final GlobalConfiguration globalConfiguration) throws ConfigurationException { super(configuration, reporters, globalConfiguration); config = SlowQueryConfiguration.create(configuration.options); service = configuration.getMeasurementOrDefault(DEFAULT_MEASUREMENT_NAME); slowQueryCountMeasurementName = service + SLOW_QUERY_COUNT_SUFFIX; slowQueryLogDecider = SlowQueryLogDecider.create(config); slowQueryCounts = new HashMap<>(); for (StatementType statementType : StatementType.values()) { slowQueryCounts.put(statementType, new AtomicCounter()); } if (config.slowQueryCountReportEnabled()) { timer = new Timer(SLOW_QUERY_COUNT_THREAD_NAME); timer.schedule(new SlowQueryReportTask(), 0, config.slowQueryCountReportingRateInMillis()); } else { timer = null; } }
private static void validateRequestsToReport(RequestRateConfiguration conf) throws ConfigurationException { for (String requestToReport : conf.requestsToReport()) { String[] requestMeta = requestToReport.split(REQUEST_META_DELIMITER); if (requestMeta.length != 2) { throw new ConfigurationException( "Only two configuration parameters supported, statement type and consistency level."); } String statementType = requestMeta[0]; String consistencyLevel = requestMeta[1]; try { if (!statementType.equals(ALL_STATEMENT_TYPES)) { Query.StatementType.valueOf(statementType); } } catch (IllegalArgumentException ex) { throw new ConfigurationException("Illegal statement type configured: " + statementType); } try { if (!consistencyLevel.equals(ALL_CONSISTENCY_LEVELS)) { Query.ConsistencyLevel.valueOf(consistencyLevel); } } catch (IllegalArgumentException ex) { throw new ConfigurationException("Illegal consistency level configured: " + consistencyLevel); } } }
private Measurement createSlowQueryCountMeasurement(double count, StatementType statementType) { final Map<String, String> tags = new HashMap<>(2); tags.put("host", globalConfiguration.hostname); tags.put("systemName", globalConfiguration.systemName); tags.put("statementType", statementType.toString()); return Measurement.createSimple(slowQueryCountMeasurementName, count, System.currentTimeMillis(), TimeUnit.MILLISECONDS, tags, new HashMap<String, String>()); } }
@Override public void process(Query query) { final String statementType = query.statementType().name(); final String consistencyLevel = query.consistencyLevel().name(); for (RequestRate requestRate : requestRates) { if (statementMatches(statementType, requestRate) && consistencyLevelMatches(consistencyLevel, requestRate)) { requestRate.increment(); } } }
private boolean typeForLogging(Query query) { logger.trace("Checking if query type is for logging."); boolean logAll = slowQueryConfiguration.queryTypesToLog().contains("ALL"); boolean queryTypeMatches = slowQueryConfiguration.queryTypesToLog().contains(query.statementType().toString()); return logAll || queryTypeMatches; }
@Override public String toString() { return "Query [ " + "startTimeInMilliseconds=" + startTimeInMilliseconds + ", executionTimeInMilliseconds=" + executionTimeInMilliseconds + ", clientAddress=" + clientAddress + ", statementType=" + statementType .name() + ", statement=" + statement + ", keyspace=" + keyspace + ", tableName=" + tableName + ", " + "consistencyLevel=" + consistencyLevel.name() + " ]"; }