@Override
  public void start() {
    metricList = new ArrayList<Metric>();
    if (mode.equals("tower4clouds")) {

      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);

            JDBC_URL = parameters.get("databaseAddress");
            JDBC_NAME = parameters.get("databaseUser");
            JDBC_PASSWORD = parameters.get("databasePassword");
          }
        } catch (ConfigurationException e) {
          e.printStackTrace();
        }
      }
    } else {
      try {
        String folder = new File(".").getCanonicalPath();
        File file = new File(folder + "/config/configuration_MySQL.xml");

        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder;
        dBuilder = dbFactory.newDocumentBuilder();
        Document doc = dBuilder.parse(file);

        doc.getDocumentElement().normalize();

        NodeList nList = doc.getElementsByTagName("metricName");

        for (int temp = 0; temp < nList.getLength(); temp++) {

          Node nNode = nList.item(temp);

          Metric temp_metric = new Metric();
          temp_metric.setMetricName(nNode.getTextContent());
          temp_metric.setSamplingProb(1);
          metricList.add(temp_metric);
        }

        NodeList nList_jdbc = doc.getElementsByTagName("mysql-metric");

        for (int i = 0; i < nList_jdbc.getLength(); i++) {

          Node nNode = nList_jdbc.item(i);

          if (nNode.getNodeType() == Node.ELEMENT_NODE) {

            Element eElement = (Element) nNode;
            JDBC_URL = eElement.getElementsByTagName("databaseAddress").item(0).getTextContent();
            JDBC_NAME = eElement.getElementsByTagName("databaseUser").item(0).getTextContent();
            JDBC_PASSWORD =
                eElement.getElementsByTagName("databasePassword").item(0).getTextContent();
            monitoredTarget =
                eElement.getElementsByTagName("monitoredTarget").item(0).getTextContent();
            period =
                Integer.valueOf(
                    eElement.getElementsByTagName("monitorPeriod").item(0).getTextContent());
          }
        }

      } catch (ParserConfigurationException e1) {
        e1.printStackTrace();
      } catch (SAXException e) {
        e.printStackTrace();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    try {
      Class.forName(JDBC_DRIVER);
    } catch (Exception ex) {
      System.out.println("Error Class.forName" + ex);
      ex.printStackTrace();
      System.exit(0);
    }

    try {
      conDb = DriverManager.getConnection(JDBC_URL, JDBC_NAME, JDBC_PASSWORD);
    } catch (Exception ex) {
      System.out.println("Error getConnection" + ex);
      ex.printStackTrace();
      System.exit(0);
    }

    sqlt = new Thread(this, "mysql-mon");
  }
  @Override
  public void run() {
    String monitoredMachineAddress = null;
    String user = null;
    String password = null;
    String host = null;

    for (String metric : getProvidedMetrics()) {
      try {
        if (dcAgent.shouldMonitor(
            new VM(Config.getInstance().getVmType(), Config.getInstance().getVmId()), metric)) {
          Map<String, String> parameters = dcAgent.getParameters(metric);

          monitoredMachineAddress = parameters.get("monitoredMachineAddress");
          user = parameters.get("user");
          password = parameters.get("password");
          host = parameters.get("host");
        }
      } catch (ConfigurationException e) {
        e.printStackTrace();
      }
    }

    JSch jsch = new JSch();

    try {
      session = jsch.getSession(user, host, 22);

      session.setPassword(password);

      session.setConfig("StrictHostKeyChecking", "no");

      session.connect(10 * 1000);

      long startTime = 0;

      while (!fmt.isInterrupted()) {
        if (System.currentTimeMillis() - startTime > 60000) {

          for (String metric : getProvidedMetrics()) {
            if (dcAgent.shouldMonitor(
                new VM(Config.getInstance().getVmType(), Config.getInstance().getVmId()), metric)) {
              Map<String, String> parameters = dcAgent.getParameters(metric);

              period = Integer.valueOf(parameters.get("samplingTime"));
              samplingProb = Double.valueOf(parameters.get("samplingProbability"));
            }
          }

          startTime = System.currentTimeMillis();
        }

        boolean isSent = false;
        if (Math.random() < samplingProb) {
          isSent = true;
        }
        channel = session.openChannel("exec");

        String command =
            "snmpwalk -c public -v 1 " + monitoredMachineAddress + " .1.3.6.1.4.1.2021.51";
        // command = "ls -l";
        ((ChannelExec) channel).setCommand(command);
        channel.setInputStream(null);
        ((ChannelExec) channel).setErrStream(System.err);
        channel.setOutputStream(System.out);
        InputStream in = channel.getInputStream();

        channel.connect();

        BufferedReader buf = new BufferedReader(new InputStreamReader(in));
        String line = "";

        int count = 0;
        boolean isFirst = true;
        String metricName = null;

        while ((line = buf.readLine()) != null) {
          Pattern p = Pattern.compile("\"([^\"]*)\"");
          Matcher m = p.matcher(line);

          while (m.find()) {
            if (isFirst) {
              if (m.group(1).equals("NodeID")) {
                count++;
                metricName = "NodeID";
                System.out.println("NodeID");
                isFirst = false;
              }
              continue;
            } else {
              if (count % 2 == 1) {
                try {
                  if (isSent) {
                    logger.info("Sending datum: {} {} {}", m.group(1), metricName, monitoredTarget);
                    dcAgent.send(
                        new VM(Config.getInstance().getVmType(), Config.getInstance().getVmId()),
                        metricName,
                        m.group(1));
                  }
                } catch (Exception e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
                // sendMonitoringDatum(Double.valueOf(m.group(1)),
                // ResourceFactory.createResource(MC.getURI() + metricName), monitoredResourceURL,
                // monitoredResource);
                // System.out.println(metricName+"   "+m.group(1));
                count++;
              } else {
                metricName = m.group(1);
                count++;
              }
            }
          }
        }

        Thread.sleep(period);
      }

    } catch (JSchException e1) {
      e1.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    } catch (NumberFormatException e) {
      e.printStackTrace();
    } catch (ConfigurationException e) {
      e.printStackTrace();
    }
  }