예제 #1
0
  public void init(PluginManager manager) throws PluginException {
    super.init(manager);

    final String prop = "sigar.mirror.procnet";
    final String enable = manager.getProperty(prop);
    getLog().debug(prop + "=" + enable);
    if (!"true".equals(enable)) {
      return;
    }

    // intended for use on systems with very large connection tables
    // where processing /proc/net/tcp may block or otherwise take much longer
    // than reading a plain 'ol text file
    // should only happen agent-side
    String dir = manager.getProperty(AgentConfig.PROP_TMPDIR[0]);
    ProcFileMirror mirror = null;
    final String[] procnet = {"/proc/net/tcp", "/proc/net/tcp6"};
    for (int i = 0; i < procnet.length; i++) {
      File file = new File(procnet[i]);
      if (!file.exists()) {
        continue;
      }
      if (mirror == null) {
        mirror = new ProcFileMirror(new Sigar(), dir);
      }

      try {
        mirror.add(file);
        getLog().debug("mirroring " + procnet[i]);
      } catch (SigarException e) {
        getLog().warn(e.getMessage());
      }
    }
    if (mirror != null) {
      FileWatcherThread.getInstance().add(mirror);
      FileWatcherThread.getInstance().doStart();
    }
  }