mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-12-16 01:40:52 +08:00
98 lines
2.1 KiB
C++
98 lines
2.1 KiB
C++
/**
|
|
* Copyright (C) 2015-2018
|
|
* All rights reserved.
|
|
*
|
|
* AUTHOR(S)
|
|
* Zheng Shuxin
|
|
* E-mail: zhengshuxin@qiyi.com
|
|
*
|
|
* VERSION
|
|
* Fri 16 Jun 2017 01:54:45 PM CST
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
#include "master/master_api.h"
|
|
#include "service_stat.h"
|
|
|
|
bool service_stat::stat_one(const char* path, serv_info_t& info)
|
|
{
|
|
ACL_MASTER_SERV *serv = acl_master_lookup(path);
|
|
|
|
if (serv == NULL)
|
|
{
|
|
info.status = 404;
|
|
info.conf = path;
|
|
return false;
|
|
}
|
|
|
|
info.status = 200;
|
|
info.name = serv->name;
|
|
info.type = serv->type;
|
|
info.path = serv->path;
|
|
info.conf = serv->conf;
|
|
info.proc_max = serv->max_proc;
|
|
info.proc_prefork = serv->prefork_proc;
|
|
info.proc_total = serv->total_proc;
|
|
info.proc_avail = serv->avail_proc;
|
|
info.throttle_delay = serv->throttle_delay;
|
|
info.listen_fd_count = serv->listen_fd_count;
|
|
|
|
if (serv->owner && *serv->owner)
|
|
info.owner = serv->owner;
|
|
if (serv->notify_addr && *serv->notify_addr)
|
|
info.notify_addr = serv->notify_addr;
|
|
if (serv->notify_recipients && *serv->notify_recipients)
|
|
info.notify_recipients = serv->notify_recipients;
|
|
|
|
ACL_ITER iter;
|
|
acl_foreach(iter, serv->children_env)
|
|
{
|
|
ACL_MASTER_NV* v = (ACL_MASTER_NV *) iter.data;
|
|
info.env[v->name] = v->value;
|
|
}
|
|
|
|
|
|
ACL_RING_ITER iter2;
|
|
acl_ring_foreach(iter2, &serv->children)
|
|
{
|
|
ACL_MASTER_PROC* proc = (ACL_MASTER_PROC *)
|
|
acl_ring_to_appl(iter2.ptr, ACL_MASTER_PROC, me);
|
|
proc_info_t pi;
|
|
pi.pid = proc->pid;
|
|
pi.start = proc->start;
|
|
info.procs.push_back(pi);
|
|
}
|
|
|
|
info.status = 200;
|
|
return true;
|
|
}
|
|
|
|
bool service_stat::run(const stat_req_t& req, stat_res_t& res)
|
|
{
|
|
size_t n = 0;
|
|
|
|
for (std::vector<stat_req_data_t>::const_iterator
|
|
cit = req.data.begin(); cit != req.data.end(); ++cit)
|
|
{
|
|
serv_info_t info;
|
|
if (stat_one((*cit).path.c_str(), info))
|
|
n++;
|
|
res.data.push_back(info);
|
|
}
|
|
|
|
if (n == req.data.size())
|
|
{
|
|
res.status = 200;
|
|
res.msg = "ok";
|
|
}
|
|
else
|
|
{
|
|
res.status = 500;
|
|
res.msg = "error";
|
|
logger_error("not all service have been started!, n=%d, %d",
|
|
(int) n, (int) req.data.size());
|
|
}
|
|
|
|
return true;
|
|
}
|