2

我正在编写一个自动化脚本来查找从节点上剩余或已使用的 %age 空间。我确实找到了获取剩余空间的功能(http://javadoc.jenkins-ci.org/hudson/node_monitors/DiskSpaceMonitorDescriptor.DiskSpace.html#toHtml%28%29),但找不到任何东西来获得总数空间或百分比。

只是想知道 jenkins API 中是否有一种方法可以满足我的要求。

4

1 回答 1

1

我遇到了同样的问题,并使用 FilePath 类(http://javadoc.jenkins.io/hudson/FilePath.html)解决了它。

通过此示例,您可以迭代所有从节点以获得可用空间百分比:

    for (slave in hudson.model.Hudson.instance.slaves) {

      FilePath slaveRootPath = slave.getRootPath();

      // Total space on the slave filesystem
      total = slaveRootPath.getTotalDiskSpace();
      // Free space on the slave filesystem
      free = slaveRootPath.getUsableDiskSpace();

      available = (100 * free)/total;

      System.out.println(slave.getDisplayName() + " free space percentage: " + available + "%");
    }

你会得到类似的东西:

SLAVE_NAME 可用空间百分比:N%

希望能帮助到你。

于 2017-01-31T13:59:34.610 回答