Jvm.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.warewms.system.mapper.server;
  2. import com.warewms.common.utils.Arith;
  3. import com.warewms.common.utils.DateUtils;
  4. import java.lang.management.ManagementFactory;
  5. /**
  6. * JVM相关信息
  7. *
  8. * @author ruoyi
  9. */
  10. public class Jvm
  11. {
  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. {
  34. return Arith.div(total, (1024 * 1024), 2);
  35. }
  36. public void setTotal(double total)
  37. {
  38. this.total = total;
  39. }
  40. public double getMax()
  41. {
  42. return Arith.div(max, (1024 * 1024), 2);
  43. }
  44. public void setMax(double max)
  45. {
  46. this.max = max;
  47. }
  48. public double getFree()
  49. {
  50. return Arith.div(free, (1024 * 1024), 2);
  51. }
  52. public void setFree(double free)
  53. {
  54. this.free = free;
  55. }
  56. public double getUsed()
  57. {
  58. return Arith.div(total - free, (1024 * 1024), 2);
  59. }
  60. public double getUsage()
  61. {
  62. return Arith.mul(Arith.div(total - free, total, 4), 100);
  63. }
  64. /**
  65. * 获取JDK名称
  66. */
  67. public String getName()
  68. {
  69. return ManagementFactory.getRuntimeMXBean().getVmName();
  70. }
  71. public String getVersion()
  72. {
  73. return version;
  74. }
  75. public void setVersion(String version)
  76. {
  77. this.version = version;
  78. }
  79. public String getHome()
  80. {
  81. return home;
  82. }
  83. public void setHome(String home)
  84. {
  85. this.home = home;
  86. }
  87. /**
  88. * JDK启动时间
  89. */
  90. public String getStartTime()
  91. {
  92. return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getServerStartDate());
  93. }
  94. /**
  95. * JDK运行时间
  96. */
  97. public String getRunTime()
  98. {
  99. return DateUtils.timeDistance(DateUtils.getNowDate(), DateUtils.getServerStartDate());
  100. }
  101. /**
  102. * 运行参数
  103. */
  104. public String getInputArgs()
  105. {
  106. return ManagementFactory.getRuntimeMXBean().getInputArguments().toString();
  107. }
  108. }