@Override
  public void run() {

    long startTime = 0;

    while (!sqlt.isInterrupted()) {

      if (mode.equals("tower4clouds")) {

        if (System.currentTimeMillis() - startTime > 10000) {

          metricList = new ArrayList<Metric>();

          List<Integer> periodList = new ArrayList<Integer>();

          for (String metric : getProvidedMetrics()) {

            try {
              InternalComponent resource =
                  new InternalComponent(
                      Config.getInstance().getInternalComponentType(),
                      Config.getInstance().getInternalComponentId());
              if (dcAgent.shouldMonitor(resource, metric)) {

                Map<String, String> parameters = dcAgent.getParameters(resource, metric);

                Metric temp = new Metric();

                temp.setMetricName(metric);

                periodList.add(Integer.valueOf(parameters.get("samplingTime")) * 1000);
                temp.setSamplingProb(Double.valueOf(parameters.get("samplingProbability")));

                metricList.add(temp);
              }
            } catch (NumberFormatException | ConfigurationException e) {
              e.printStackTrace();
            }
          }

          period = Collections.min(periodList);
          startTime = System.currentTimeMillis();
        }
      }
      String query = "SHOW GLOBAL STATUS where ";

      int numMetrics = 0;
      for (Metric metric : metricList) {
        if (numMetrics == 0) {
          query = query + "Variable_name like '" + metric.getMetricName() + "'";
        } else {
          query = query + "or Variable_name like '" + metric.getMetricName() + "'";
        }
        numMetrics++;
      }

      Long t0 = System.currentTimeMillis();
      // TO FIX adding delay
      PreparedStatement ps = null;
      ResultSet rs;

      try {
        try {
          ps = conDb.prepareStatement(query);
        } catch (SQLException e1) {
          e1.printStackTrace();
        }
        rs = ps.executeQuery(query);
        while (rs.next()) {
          String variableName = rs.getString("Variable_name");
          String value = rs.getString("Value");

          try {
            for (Metric metric : metricList) {
              if (metric.getMetricName().equals(variableName)) {
                if (Math.random() < metric.getSamplingProb()) {
                  logger.info("Sending datum: {} {} {}", value, variableName, monitoredTarget);
                  dcAgent.send(
                      new InternalComponent(
                          Config.getInstance().getInternalComponentType(),
                          Config.getInstance().getInternalComponentId()),
                      variableName,
                      Double.valueOf(value));
                }
              }
            }
          } catch (Exception e) {
            e.printStackTrace();
          }
          // sendMonitoringDatum(Double.valueOf(value), ResourceFactory.createResource(MC.getURI() +
          // variableName), monitoredResourceURL, monitoredResource);

          // System.out.println(variableName + ": " + value);
        }
      } catch (SQLException ex) {
        System.out.println("Error execute query" + ex);
        ex.printStackTrace();
        System.exit(0);
      }

      Long t1 = System.currentTimeMillis();
      try {
        // correct sleep time to ensure periodic sampling
        Thread.sleep(Math.max(period * 1000 - (t1 - t0), 0));
      } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        break;
      }
    }
  }