acl/app/master/daemon/manage/action/service_stat.cpp

111 lines
2.5 KiB
C++
Raw Normal View History

2017-06-16 17:00:49 +08:00
/**
* 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 "manage/http_client.h"
2017-06-16 17:00:49 +08:00
#include "service_stat.h"
2017-06-27 17:11:04 +08:00
bool service_stat::stat_one(const char* path, serv_info_t& info)
2017-06-16 17:00:49 +08:00
{
2017-06-27 17:11:04 +08:00
ACL_MASTER_SERV *serv = acl_master_lookup(path);
2017-06-16 17:00:49 +08:00
2017-09-24 21:10:28 +08:00
if (serv == NULL) {
2017-06-16 17:00:49 +08:00
info.status = 404;
2017-07-17 16:19:46 +08:00
info.conf = path;
2017-06-16 17:00:49 +08:00
return false;
}
info.status = 200;
2017-06-16 17:00:49 +08:00
info.name = serv->name;
info.type = serv->type;
2017-06-16 17:00:49 +08:00
info.path = serv->path;
info.conf = serv->conf;
2017-06-16 17:00:49 +08:00
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)
2017-06-27 17:11:04 +08:00
info.owner = serv->owner;
2017-06-16 17:00:49 +08:00
if (serv->notify_addr && *serv->notify_addr)
2017-06-27 17:11:04 +08:00
info.notify_addr = serv->notify_addr;
2017-06-16 17:00:49 +08:00
if (serv->notify_recipients && *serv->notify_recipients)
info.notify_recipients = serv->notify_recipients;
ACL_ITER iter;
2017-09-24 21:10:28 +08:00
acl_foreach(iter, serv->children_env) {
2017-06-16 17:00:49 +08:00
ACL_MASTER_NV* v = (ACL_MASTER_NV *) iter.data;
info.env[v->name] = v->value;
}
ACL_RING_ITER iter2;
2017-09-24 21:10:28 +08:00
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);
}
2017-06-16 17:00:49 +08:00
info.status = 200;
return true;
}
bool service_stat::run(acl::json& json)
{
stat_req_t req;
stat_res_t res;
2017-09-24 21:10:28 +08:00
if (deserialize<stat_req_t>(json, req) == false) {
res.status = 400;
res.msg = "invalid json";
client_.reply<stat_res_t>(res.status, res);
return false;
}
return handle(req, res);
}
bool service_stat::handle(const stat_req_t& req, stat_res_t& res)
2017-06-16 17:00:49 +08:00
{
size_t n = 0;
for (std::vector<stat_req_data_t>::const_iterator
2017-09-24 21:10:28 +08:00
cit = req.data.begin(); cit != req.data.end(); ++cit) {
2017-06-16 17:00:49 +08:00
serv_info_t info;
2017-06-27 17:11:04 +08:00
if (stat_one((*cit).path.c_str(), info))
2017-06-16 17:00:49 +08:00
n++;
res.data.push_back(info);
}
2017-09-24 21:10:28 +08:00
if (n == req.data.size()) {
2017-06-16 17:00:49 +08:00
res.status = 200;
res.msg = "ok";
2017-09-24 21:10:28 +08:00
} else {
2017-06-16 17:00:49 +08:00
res.status = 500;
res.msg = "error";
logger_error("not all service have been started!, n=%d, %d",
(int) n, (int) req.data.size());
}
client_.reply<stat_res_t>(res.status, res);
client_.on_finish();
2017-06-16 17:00:49 +08:00
return true;
}