1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.rundeck.api.parser;
17
18 import java.util.Date;
19 import org.apache.commons.lang.StringUtils;
20 import org.dom4j.Node;
21 import org.rundeck.api.domain.RundeckSystemInfo;
22
23
24
25
26
27
28 public class SystemInfoParser extends BaseXpathParser<RundeckSystemInfo> {
29
30
31 public SystemInfoParser(final String xpath) {
32 super(xpath);
33 }
34
35 @Override
36 public RundeckSystemInfo parse(Node infoNode) {
37 RundeckSystemInfo info = new RundeckSystemInfo();
38
39 String timestamp = StringUtils.trimToNull(infoNode.valueOf("timestamp/@epoch"));
40 if (timestamp != null) {
41 info.setDate(new Date(Long.valueOf(timestamp)));
42 }
43 info.setVersion(StringUtils.trimToNull(infoNode.valueOf("rundeck/version")));
44 info.setBuild(StringUtils.trimToNull(infoNode.valueOf("rundeck/build")));
45 info.setNode(StringUtils.trimToNull(infoNode.valueOf("rundeck/node")));
46 info.setBaseDir(StringUtils.trimToNull(infoNode.valueOf("rundeck/base")));
47 info.setOsArch(StringUtils.trimToNull(infoNode.valueOf("os/arch")));
48 info.setOsName(StringUtils.trimToNull(infoNode.valueOf("os/name")));
49 info.setOsVersion(StringUtils.trimToNull(infoNode.valueOf("os/version")));
50 info.setJvmName(StringUtils.trimToNull(infoNode.valueOf("jvm/name")));
51 info.setJvmVendor(StringUtils.trimToNull(infoNode.valueOf("jvm/vendor")));
52 info.setJvmVersion(StringUtils.trimToNull(infoNode.valueOf("jvm/version")));
53 String startDate = StringUtils.trimToNull(infoNode.valueOf("stats/uptime/since/@epoch"));
54 if (startDate != null) {
55 info.setStartDate(new Date(Long.valueOf(startDate)));
56 }
57 info.setUptimeInMillis(Long.valueOf(infoNode.valueOf("stats/uptime/@duration")));
58 info.setCpuLoadAverage(StringUtils.trimToNull(infoNode.valueOf("stats/cpu/loadAverage")));
59 if (info.getCpuLoadAverage() != null) {
60 info.setCpuLoadAverage(info.getCpuLoadAverage() + " %");
61 }
62 info.setMaxMemoryInBytes(Long.valueOf(infoNode.valueOf("stats/memory/max")));
63 info.setFreeMemoryInBytes(Long.valueOf(infoNode.valueOf("stats/memory/free")));
64 info.setTotalMemoryInBytes(Long.valueOf(infoNode.valueOf("stats/memory/total")));
65 info.setRunningJobs(Integer.valueOf(infoNode.valueOf("stats/scheduler/running")));
66 info.setActiveThreads(Integer.valueOf(infoNode.valueOf("stats/threads/active")));
67
68 return info;
69 }
70 }