4ad1764c62a90e5cb442a73c092ef0dcc175c9c0.svn-base 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package cn.com.goldenwater.target;
  2. import cn.com.goldenwater.dcproj.utils.Arith;
  3. import cn.com.goldenwater.dcproj.utils.DateUtils;
  4. import java.lang.management.ManagementFactory;
  5. import java.util.Date;
  6. /**
  7. * JVM相关信息
  8. *
  9. * @author ruoyi
  10. */
  11. public class Jvm {
  12. /**
  13. * 当前JVM占用的内存总数(M)
  14. */
  15. private double total;
  16. /**
  17. * JVM最大可用内存总数(M)
  18. */
  19. private double max;
  20. /**
  21. * JVM空闲内存(M)
  22. */
  23. private double free;
  24. /**
  25. * JDK版本
  26. */
  27. private String version;
  28. /**
  29. * JDK路径
  30. */
  31. private String home;
  32. public double getTotal() {
  33. return Arith.div(total, (1024 * 1024), 2);
  34. }
  35. public void setTotal(double total) {
  36. this.total = total;
  37. }
  38. public double getMax() {
  39. return Arith.div(max, (1024 * 1024), 2);
  40. }
  41. public void setMax(double max) {
  42. this.max = max;
  43. }
  44. public double getFree() {
  45. return Arith.div(free, (1024 * 1024), 2);
  46. }
  47. public void setFree(double free) {
  48. this.free = free;
  49. }
  50. public double getUsed() {
  51. return Arith.div(total - free, (1024 * 1024), 2);
  52. }
  53. public double getUsage() {
  54. return Arith.mul(Arith.div(total - free, total, 4), 100);
  55. }
  56. /**
  57. * 获取JDK名称
  58. */
  59. public String getName() {
  60. return ManagementFactory.getRuntimeMXBean().getVmName();
  61. }
  62. public String getVersion() {
  63. return version;
  64. }
  65. public void setVersion(String version) {
  66. this.version = version;
  67. }
  68. public String getHome() {
  69. return home;
  70. }
  71. public void setHome(String home) {
  72. this.home = home;
  73. }
  74. /**
  75. * JDK启动时间
  76. */
  77. public String getStartTime() {
  78. return DateUtils.getTodayYMDHMS();
  79. }
  80. /**
  81. * JDK运行时间
  82. */
  83. public String getRunTime() {
  84. return DateUtils.getDatePoor(new Date(), DateUtils.getServerStartDate());
  85. }
  86. @Override
  87. public String toString() {
  88. return "Jvm{" +
  89. "total=" + total +
  90. ", max=" + max +
  91. ", free=" + free +
  92. ", version='" + version + '\'' +
  93. ", home='" + home + '\'' +
  94. '}';
  95. }
  96. }