forked from zfile-dev/zfile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a24fd1
commit a759d9f
Showing
8 changed files
with
287 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package im.zhaojun.common.model; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author zhaojun | ||
*/ | ||
@Data | ||
public class Jvm { | ||
|
||
/** | ||
* 当前 JVM 占用的内存总数 (M) | ||
*/ | ||
private double total; | ||
|
||
/** | ||
* JVM 最大可用内存总数 (M) | ||
*/ | ||
private double max; | ||
|
||
/** | ||
* JVM 空闲内存 (M) | ||
*/ | ||
private double free; | ||
|
||
/** | ||
* JDK 版本 | ||
*/ | ||
private String version; | ||
|
||
public Jvm() { | ||
Runtime runtime = Runtime.getRuntime(); | ||
this.total = runtime.totalMemory(); | ||
this.free = runtime.freeMemory(); | ||
this.max = runtime.maxMemory(); | ||
this.version = System.getProperty("java.version"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package im.zhaojun.common.model; | ||
|
||
import com.sun.management.OperatingSystemMXBean; | ||
import lombok.Data; | ||
|
||
import java.lang.management.ManagementFactory; | ||
|
||
/** | ||
* @author zhaojun | ||
*/ | ||
@Data | ||
public class Mem { | ||
|
||
/** | ||
* 内存总量 | ||
*/ | ||
private double total; | ||
|
||
/** | ||
* 已用内存 | ||
*/ | ||
private double used; | ||
|
||
/** | ||
* 剩余内存 | ||
*/ | ||
private double free; | ||
|
||
public Mem() { | ||
OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean(); | ||
// 总的物理内存+虚拟内存 | ||
long totalVirtualMemory = operatingSystemMXBean.getTotalSwapSpaceSize(); | ||
// 剩余的物理内存 | ||
long freePhysicalMemorySize = operatingSystemMXBean.getFreePhysicalMemorySize(); | ||
this.total = totalVirtualMemory; | ||
this.free = freePhysicalMemorySize; | ||
this.used = totalVirtualMemory - freePhysicalMemorySize; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package im.zhaojun.common.model; | ||
|
||
import cn.hutool.core.date.BetweenFormater; | ||
import cn.hutool.core.date.DateUtil; | ||
import lombok.Data; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.core.io.Resource; | ||
|
||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
|
||
/** | ||
* @author zhaojun | ||
*/ | ||
@Data | ||
public class Sys { | ||
|
||
/** | ||
* 项目路径 | ||
*/ | ||
private String projectDir; | ||
|
||
/** | ||
* 操作系统 | ||
*/ | ||
private String osName; | ||
|
||
/** | ||
* 系统架构 | ||
*/ | ||
private String osArch; | ||
|
||
/** | ||
* 系统版本 | ||
*/ | ||
private String osVersion; | ||
|
||
/** | ||
* 启动时间 | ||
*/ | ||
private String upTime; | ||
|
||
public Sys() { | ||
this.osName = System.getProperty("os.name"); | ||
this.osArch = System.getProperty("os.arch"); | ||
this.osVersion = System.getProperty("os.version"); | ||
Resource resource = new ClassPathResource(""); | ||
try { | ||
this.projectDir = resource.getFile().getAbsolutePath(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
long uptime = ManagementFactory.getRuntimeMXBean().getUptime(); | ||
this.upTime = DateUtil.formatBetween(uptime, BetweenFormater.Level.SECOND); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/im/zhaojun/common/model/SystemMonitorInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package im.zhaojun.common.model; | ||
|
||
import lombok.Data; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* @author zhaojun | ||
*/ | ||
@Data | ||
public class SystemMonitorInfo implements Serializable { | ||
|
||
/** | ||
* 服务器基本信息 | ||
*/ | ||
private Sys sys; | ||
|
||
/** | ||
* JVM 信息 | ||
*/ | ||
private Jvm jvm; | ||
|
||
/** | ||
* 系统内存 | ||
*/ | ||
private Mem mem; | ||
|
||
public SystemMonitorInfo() { | ||
this.jvm = new Jvm(); | ||
this.sys = new Sys(); | ||
this.mem = new Mem(); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/im/zhaojun/common/service/SystemMonitorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package im.zhaojun.common.service; | ||
|
||
import im.zhaojun.common.model.SystemMonitorInfo; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author zhaojun | ||
*/ | ||
@Service | ||
public class SystemMonitorService { | ||
|
||
public SystemMonitorInfo systemMonitorInfo() { | ||
return new SystemMonitorInfo(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package im.zhaojun.common.util; | ||
|
||
import cn.hutool.core.util.URLUtil; | ||
import org.springframework.core.io.FileSystemResource; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
|
||
import java.io.File; | ||
import java.util.Date; | ||
|
||
/** | ||
* @author zhaojun | ||
*/ | ||
public class FileUtil { | ||
|
||
public static ResponseEntity<Object> export(File file, String fileName) { | ||
if (!file.exists()) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("404 FILE NOT FOUND"); | ||
} | ||
|
||
MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); | ||
|
||
if (StringUtils.isNullOrEmpty(fileName)) { | ||
fileName = file.getName(); | ||
} | ||
|
||
headers.setContentDispositionFormData("attachment", URLUtil.encode(fileName)); | ||
|
||
headers.add("Pragma", "no-cache"); | ||
headers.add("Expires", "0"); | ||
headers.add("Last-Modified", new Date().toString()); | ||
headers.add("ETag", String.valueOf(System.currentTimeMillis())); | ||
return ResponseEntity | ||
.ok() | ||
.headers(headers) | ||
.contentLength(file.length()) | ||
.contentType(mediaType) | ||
.body(new FileSystemResource(file)); | ||
} | ||
|
||
public static ResponseEntity<Object> export(File file) { | ||
if (!file.exists()) { | ||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("404 FILE NOT FOUND"); | ||
} | ||
|
||
MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM; | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); | ||
headers.setContentDispositionFormData("attachment", URLUtil.encode(file.getName())); | ||
|
||
headers.add("Pragma", "no-cache"); | ||
headers.add("Expires", "0"); | ||
headers.add("Last-Modified", new Date().toString()); | ||
headers.add("ETag", String.valueOf(System.currentTimeMillis())); | ||
return ResponseEntity | ||
.ok() | ||
.headers(headers) | ||
.contentLength(file.length()) | ||
.contentType(mediaType) | ||
.body(new FileSystemResource(file)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters