提交 9376ef4e 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!615 stats: stats --original show correct container name

Merge pull request !615 from Zhangxiaoyu/master
......@@ -72,6 +72,13 @@ function test_stats_spec()
cat $statslog | grep "${id_init:0:12}"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
container_name_pause=stats_paused
id_pause=`isula run -td -n $container_name_pause $image /bin/sh`
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
isula pause $id_pause
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to pause running container" && ((ret++))
container_name_stop=stats_stopped
id_stop=`isula run -td -n $container_name_stop $image /bin/sh`
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to run container with image: ${image}" && ((ret++))
......@@ -79,19 +86,40 @@ function test_stats_spec()
isula stop $id_stop
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stop running container" && ((ret++))
isula stats --original > $statslog
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats --original" && ((ret++))
cat $statslog | grep "${id_init:0:12}"
[[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - stats the inited container(should not)" && ((ret++))
cat $statslog | grep "${id_running:0:12}" | grep "running"| grep "$container_name_running"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats running container" && ((ret++))
cat $statslog | grep "${id_pause:0:12}" | grep "paused"| grep "$container_name_pause"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats paused container" && ((ret++))
cat $statslog | grep "${id_stop:0:12}"
[[ $? -eq 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats exited container(should not)" && ((ret++))
isula stats --original -a > $statslog
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats with option original" && ((ret++))
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats--original -a" && ((ret++))
cat $statslog | grep "${id_init:0:12}" | grep "inited"
cat $statslog | grep "${id_init:0:12}" | grep "inited" | grep "$container_name_init"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats inited container" && ((ret++))
cat $statslog | grep "${id_running:0:12}" | grep "running"
cat $statslog | grep "${id_running:0:12}" | grep "running"| grep "$container_name_running"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats running container" && ((ret++))
cat $statslog | grep "${id_stop:0:12}" | grep "exited"
cat $statslog | grep "${id_pause:0:12}" | grep "paused"| grep "$container_name_pause"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats paused container" && ((ret++))
cat $statslog | grep "${id_stop:0:12}" | grep "exited"| grep "$container_name_stop"
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to stats exited container" && ((ret++))
isula rm -f "$container_name_init" "$container_name_running" "$container_name_stop"
isula unpause $id_pause
[[ $? -ne 0 ]] && msg_err "${FUNCNAME[0]}:${LINENO} - failed to unpause the paused container" && ((ret++))
isula rm -f "$container_name_init" "$container_name_running" "$container_name_pause" "$container_name_stop"
rm -f $statslog
......
......@@ -81,9 +81,10 @@ message Container_info {
uint64 mem_limit = 11;
uint64 kmem_used = 12;
uint64 kmem_limit = 13;
string status = 14;
uint64 cache = 15;
uint64 cache_total = 16;
string name = 14;
string status = 15;
uint64 cache = 16;
uint64 cache_total = 17;
}
message Event {
......
......@@ -1708,6 +1708,9 @@ public:
response->container_stats[i].mem_limit = gresponse->containers(i).mem_limit();
response->container_stats[i].kmem_used = gresponse->containers(i).kmem_used();
response->container_stats[i].kmem_limit = gresponse->containers(i).kmem_limit();
if (!gresponse->containers(i).name().empty()) {
response->container_stats[i].name = util_strdup_s(gresponse->containers(i).name().c_str());
}
if (!gresponse->containers(i).status().empty()) {
response->container_stats[i].status = util_strdup_s(gresponse->containers(i).status().c_str());
}
......
......@@ -119,6 +119,8 @@ void isula_container_info_free(struct isula_container_info *info)
free(info->id);
info->id = NULL;
free(info->name);
info->name = NULL;
free(info->status);
info->status = NULL;
free(info);
......
......@@ -331,6 +331,7 @@ struct isula_container_info {
uint64_t kmem_used;
uint64_t kmem_limit;
char *name;
char *status;
// Cache usage
uint64_t cache;
......
......@@ -141,7 +141,7 @@ static void stats_print_original_data_header(void)
{
printf("%-16s %-10s %-10s %-20s %-20s %-15s %-15s %-15s %-15s %-15s %-15s %-15s %-40s", "ID", "PIDS", "Status",
"CpuUseNanos", "CpuSystemUse", "OnlineCpus", "BlkioRead", "BlkioWrite", "MemUsed", "MemLimit",
"KmemUsed", "CacheUsage", "NAMES");
"KmemUsed", "CacheUsage", "NAME");
printf("\n");
}
......@@ -158,7 +158,7 @@ static void stats_print_original_data(const struct isula_container_info *stats)
printf("%-16s %-10llu %-10s %-20lu %-20lu %-15u %-15lu %-15lu %-15lu %-15lu %-15lu %-15lu %-40s", short_id,
(unsigned long long)stats->pids_current, stats->status, stats->cpu_use_nanos, stats->cpu_system_use,
stats->online_cpus, stats->blkio_read, stats->blkio_write, stats->mem_used, stats->mem_limit, stats->kmem_used,
stats->cache, stats->id);
stats->cache, stats->name);
free(short_id);
}
......
......@@ -789,6 +789,9 @@ int ContainerServiceImpl::stats_response_to_grpc(const container_stats_response
stats->set_mem_limit(response->container_stats[i]->mem_limit);
stats->set_kmem_used(response->container_stats[i]->kmem_used);
stats->set_kmem_limit(response->container_stats[i]->kmem_limit);
if (response->container_stats[i]->name != nullptr) {
stats->set_name(response->container_stats[i]->name);
}
if (response->container_stats[i]->status != nullptr) {
stats->set_status(response->container_stats[i]->status);
}
......
......@@ -264,6 +264,7 @@ static container_info *get_container_stats(const container_t *cont,
info->image_type = util_strdup_s(cont->common_config->image_type);
info->name = util_strdup_s(cont->common_config->name);
info->status = util_strdup_s(container_state_to_string(container_state_get_status(cont->state)));
info->cache = einfo->cache;
info->cache_total = einfo->cache_total;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册