forked from dragonwell-project/dragonwell8_jdk
-
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.
Summary: Add ResourceContainerMXBean, currently only support CPU resource amount. Test Plan: jtreg test/com/alibaba/ Reviewed-by: yuleil, zhengxiaolinX Issue: dragonwell-project/dragonwell8#206
- Loading branch information
joeyleeeeeee97
authored and
joeylee.lz
committed
Feb 18, 2021
1 parent
fd35688
commit 5f678ee
Showing
18 changed files
with
338 additions
and
69 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
26 changes: 26 additions & 0 deletions
26
src/share/classes/com/alibaba/management/ResourceContainerMXBean.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,26 @@ | ||
package com.alibaba.management; | ||
|
||
import java.lang.management.PlatformManagedObject; | ||
import java.util.List; | ||
|
||
public interface ResourceContainerMXBean extends PlatformManagedObject { | ||
/** | ||
* Get all running containers uniq id as List | ||
* @return all active containers' id | ||
*/ | ||
List<Long> getAllContainerIds(); | ||
|
||
/** | ||
* Get a specific container's constraints by id | ||
* @param id container id | ||
* @return constraints as list | ||
*/ | ||
List<Long> getConstraintsById(long id); | ||
|
||
/** | ||
* Get the total cpu time consumed by id specified container | ||
* @param id container id | ||
* @return consumed cpu time by nanosecond | ||
*/ | ||
long getCPUResourceConsumedAmount(long id); | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/share/classes/com/alibaba/rcm/ResourceContainerMXBeanImpl.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 com.alibaba.rcm; | ||
|
||
import com.alibaba.management.ResourceContainerMXBean; | ||
import sun.management.Util; | ||
|
||
import javax.management.ObjectName; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ResourceContainerMXBeanImpl implements ResourceContainerMXBean { | ||
private final static String TENANT_CONTAINER_MXBEAN_NAME = "com.alibaba.management:type=ResourceContainer"; | ||
|
||
@Override | ||
public List<Long> getAllContainerIds() { | ||
return ResourceContainerMonitor.getAllContainerIds(); | ||
} | ||
|
||
@Override | ||
public List<Long> getConstraintsById(long id) { | ||
return ResourceContainerMonitor.getConstraintsById(id).stream().map(c -> c.getValues()[0]).collect(Collectors.toList()); | ||
} | ||
|
||
|
||
@Override | ||
public long getCPUResourceConsumedAmount(long id) { | ||
ResourceContainer container = ResourceContainerMonitor.getContainerById(id); | ||
return container.getConsumedAmount(ResourceType.CPU_PERCENT); | ||
} | ||
|
||
@Override | ||
public ObjectName getObjectName() { | ||
return Util.newObjectName(TENANT_CONTAINER_MXBEAN_NAME); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/share/classes/com/alibaba/rcm/ResourceContainerMonitor.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,38 @@ | ||
package com.alibaba.rcm; | ||
|
||
import com.alibaba.rcm.internal.AbstractResourceContainer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
public class ResourceContainerMonitor { | ||
private static Map<Long, ResourceContainer> resourceContainerMap = new HashMap<>(); | ||
private static long idGen = 0; | ||
|
||
public synchronized static long register(ResourceContainer resourceContainer) { | ||
long id = idGen++; | ||
resourceContainerMap.put(id, resourceContainer); | ||
return id; | ||
} | ||
|
||
public synchronized static ResourceContainer getContainerById(long id) { | ||
return resourceContainerMap.get(id); | ||
} | ||
|
||
public synchronized static List<Long> getAllContainerIds() { | ||
return new ArrayList<>(resourceContainerMap.keySet()); | ||
} | ||
|
||
public synchronized static List<Constraint> getConstraintsById(long id) { | ||
AbstractResourceContainer resourceContainer = (AbstractResourceContainer) resourceContainerMap.get(id); | ||
if (resourceContainer == null) | ||
throw new IllegalArgumentException("Invalid ResourceContainer id : " + id); | ||
return StreamSupport | ||
.stream(resourceContainer.getConstraints().spliterator(), false) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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
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
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
Oops, something went wrong.