use of com.marcnuri.yakc.model.io.k8s.metrics.pkg.apis.metrics.v1beta1.NodeMetrics in project kubernetes-client by fabric8io.
the class MetricsTest method testNodeMetric.
@Test
void testNodeMetric() {
server.expect().get().withPath("/apis/metrics.k8s.io/v1beta1/nodes/test-node").andReturn(200, getNodeMetric()).once();
NodeMetrics nodeMetrics = client.top().nodes().metrics("test-node");
assertEquals("foo", nodeMetrics.getMetadata().getName());
}
use of com.marcnuri.yakc.model.io.k8s.metrics.pkg.apis.metrics.v1beta1.NodeMetrics in project Taier by DTStack.
the class AbstractK8sResourceInfo method getResource.
public void getResource(KubernetesClient kubernetesClient) {
List<Node> nodes = kubernetesClient.nodes().list().getItems();
Map<String, NodeStatus> nodeStatusMap = new HashMap<>(nodes.size());
for (Node node : nodes) {
nodeStatusMap.put(node.getMetadata().getName(), node.getStatus());
}
NodeMetricOperationsImpl nodeMetricOperations = kubernetesClient.top().nodes();
List<NodeMetrics> nodeMetrics = nodeMetricOperations.metrics().getItems();
for (NodeMetrics nodeMetric : nodeMetrics) {
String nodeName = nodeMetric.getMetadata().getName();
NodeStatus nodeStatus = nodeStatusMap.get(nodeName);
Map<String, Quantity> allocatable = nodeStatus.getAllocatable();
Map<String, Quantity> usage = nodeMetric.getUsage();
BigDecimal cpuAllocatable = Quantity.getAmountInBytes(allocatable.get(CPU));
BigDecimal cpuUsage = Quantity.getAmountInBytes(usage.get(CPU));
BigDecimal menAllocatable = Quantity.getAmountInBytes(allocatable.get(MEMORY));
BigDecimal menUsage = Quantity.getAmountInBytes(usage.get(MEMORY));
double freeCores = cpuAllocatable.subtract(cpuUsage).doubleValue();
double freeMem = menAllocatable.subtract(menUsage).doubleValue();
this.addNodeResource(new AbstractK8sResourceInfo.NodeResourceDetail(nodeName, cpuAllocatable.doubleValue(), cpuUsage.doubleValue(), freeCores, menAllocatable.doubleValue(), menUsage.doubleValue(), freeMem));
}
calc();
}
use of com.marcnuri.yakc.model.io.k8s.metrics.pkg.apis.metrics.v1beta1.NodeMetrics in project yakc by manusa.
the class MetricsV1beta1ApiIT method readNodeMetrics.
@Test
@DisplayName("readNodeMetrics, cluster contains at least a Node with some metrics")
void readNodeMetrics() throws IOException, InterruptedException {
// Given
final String node = KC.create(CoreV1Api.class).listNode().stream().findFirst().map(Node::getMetadata).map(ObjectMeta::getName).orElseThrow(() -> new AssertionError("No nodes found"));
// When
final NodeMetrics result = getWithRetry(() -> KC.create(MetricsV1beta1Api.class).readNodeMetrics(node).get());
// Then
assertThat(result).hasFieldOrPropertyWithValue("metadata.name", node).hasFieldOrProperty("usage.cpu").hasFieldOrProperty("usage.memory").hasFieldOrProperty("window").extracting(NodeMetrics::getTimestamp).isNotNull();
}
Aggregations