zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Spring Boot 应用监控: Java获取 CPU,内存, JVM 内部运行状况代码

2023-09-14 09:07:21 时间

package com.bytedance.kunlun.system;

import com.google.common.collect.Maps;

import com.sun.management.OperatingSystemMXBean;

import org.springframework.stereotype.Component;

import oshi.SystemInfo;

import oshi.hardware.CentralProcessor;

import java.io.File;

import java.lang.management.*;

import java.net.InetAddress;

import java.net.UnknownHostException;

import java.text.DecimalFormat;

import java.text.SimpleDateFormat;

import java.util.*;

@Component

public class KunlunSystemInfo {

public Mapenv()throws UnknownHostException {

Map result =Maps.newHashMap();

Runtime r =Runtime.getRuntime();

Properties props =System.getProperties();

InetAddress addr;

addr =InetAddress.getLocalHost();