mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-07 14:11:46 +00:00
added --emperor-stats
This commit is contained in:
@@ -8,6 +8,8 @@ extern char **environ;
|
||||
int emperor_queue;
|
||||
char *emperor_absolute_dir;
|
||||
|
||||
void emperor_send_stats(int);
|
||||
|
||||
struct uwsgi_instance {
|
||||
struct uwsgi_instance *ui_prev;
|
||||
struct uwsgi_instance *ui_next;
|
||||
@@ -430,6 +432,8 @@ void emperor_loop() {
|
||||
int interesting_fd;
|
||||
char notification_message[64];
|
||||
|
||||
uwsgi.emperor_stats_fd = -1;
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
uwsgi_unix_signal(SIGINT, royal_death);
|
||||
uwsgi_unix_signal(SIGTERM, royal_death);
|
||||
@@ -450,6 +454,23 @@ void emperor_loop() {
|
||||
uwsgi_log("*** starting uWSGI Emperor ***\n");
|
||||
}
|
||||
|
||||
if (uwsgi.emperor_stats) {
|
||||
char *tcp_port = strchr(uwsgi.emperor_stats, ':');
|
||||
if (tcp_port) {
|
||||
// disable deferred accept for this socket
|
||||
int current_defer_accept = uwsgi.no_defer_accept;
|
||||
uwsgi.no_defer_accept = 1;
|
||||
uwsgi.emperor_stats_fd = bind_to_tcp(uwsgi.emperor_stats, uwsgi.listen_queue, tcp_port);
|
||||
uwsgi.no_defer_accept = current_defer_accept;
|
||||
}
|
||||
else {
|
||||
uwsgi.emperor_stats_fd = bind_to_unix(uwsgi.emperor_stats, uwsgi.listen_queue, uwsgi.chmod_socket, uwsgi.abstract_socket);
|
||||
}
|
||||
|
||||
event_queue_add_fd_read(emperor_queue, uwsgi.emperor_stats_fd);
|
||||
uwsgi_log("*** Emperor stats server enabled on %s fd: %d ***\n", uwsgi.emperor_stats, uwsgi.emperor_stats_fd);
|
||||
}
|
||||
|
||||
amqp_port = strchr(uwsgi.emperor_dir, ':');
|
||||
|
||||
if (amqp_port) {
|
||||
@@ -591,6 +612,11 @@ reconnect:
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (uwsgi.emperor_stats && uwsgi.emperor_stats_fd > -1) {
|
||||
if (interesting_fd == uwsgi.emperor_stats_fd) {
|
||||
emperor_send_stats(uwsgi.emperor_stats_fd);
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui_current = emperor_get_by_fd(interesting_fd);
|
||||
if (ui_current) {
|
||||
@@ -794,3 +820,72 @@ reconnect:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define stats_send_llu(x, y) fprintf(output, x, (long long unsigned int) y)
|
||||
#define stats_send(x, y) fprintf(output, x, y)
|
||||
|
||||
void emperor_send_stats(int fd) {
|
||||
|
||||
struct sockaddr_un client_src;
|
||||
socklen_t client_src_len = 0;
|
||||
int client_fd = accept(fd, (struct sockaddr *) &client_src, &client_src_len);
|
||||
if (client_fd < 0) {
|
||||
uwsgi_error("accept()");
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *output = fdopen(client_fd, "w");
|
||||
if (!output) {
|
||||
uwsgi_error("fdopen()");
|
||||
close(client_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
stats_send("{ \"version\": \"%s\",\n", UWSGI_VERSION);
|
||||
|
||||
fprintf(output,"\"uid\": %d,\n", (int)(getuid()));
|
||||
fprintf(output,"\"gid\": %d,\n", (int)(getgid()));
|
||||
|
||||
char *cwd = uwsgi_get_cwd();
|
||||
stats_send("\"cwd\": \"%s\",\n", cwd);
|
||||
free(cwd);
|
||||
|
||||
stats_send("\"emperor\": \"%s\",\n", uwsgi.emperor_dir);
|
||||
|
||||
fprintf(output,"\"emperor_tyrant\": %d,\n", uwsgi.emperor_tyrant);
|
||||
|
||||
|
||||
fprintf(output, "\"vassals\": [\n");
|
||||
|
||||
struct uwsgi_instance *c_ui = ui->ui_next;
|
||||
|
||||
while (c_ui) {
|
||||
fprintf(output,"\t{");
|
||||
stats_send("\"id\": \"%s\", ", c_ui->name);
|
||||
fprintf(output,"\"pid\": %d, ", (int) c_ui->pid);
|
||||
|
||||
stats_send_llu( "\"born\": %llu, ", c_ui->born);
|
||||
stats_send_llu( "\"last_mod\": %llu, ", c_ui->last_mod);
|
||||
|
||||
fprintf(output,"\"loyal\": %d, ", c_ui->loyal);
|
||||
fprintf(output,"\"zerg\": %d, ", c_ui->zerg);
|
||||
|
||||
fprintf(output,"\"uid\": %d, ", (int)c_ui->uid);
|
||||
fprintf(output,"\"gid\": %d, ", (int)c_ui->gid);
|
||||
|
||||
stats_send_llu( "\"respawns\": %llu ", c_ui->respawns);
|
||||
c_ui = c_ui->ui_next;
|
||||
|
||||
if (c_ui) {
|
||||
fprintf(output,"},\n");
|
||||
}
|
||||
else {
|
||||
fprintf(output,"}\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fprintf(output,"]}\n");
|
||||
fclose(output);
|
||||
|
||||
}
|
||||
|
||||
+9
-5
@@ -310,6 +310,13 @@ void uwsgi_send_stats(int fd) {
|
||||
stats_send_llu("\"listen_queue\": %llu,\n", uwsgi.shared->ti.tcpi_unacked);
|
||||
#endif
|
||||
|
||||
fprintf(output,"\"uid\": %d,\n", (int)(getuid()));
|
||||
fprintf(output,"\"gid\": %d,\n", (int)(getgid()));
|
||||
|
||||
char *cwd = uwsgi_get_cwd();
|
||||
stats_send("\"cwd\": \"%s\",\n", cwd);
|
||||
free(cwd);
|
||||
|
||||
fprintf(output, "\"workers\": [\n");
|
||||
|
||||
for (i = 0; i < uwsgi.numproc; i++) {
|
||||
@@ -319,6 +326,7 @@ void uwsgi_send_stats(int fd) {
|
||||
fprintf(output,"\"pid\": %d, ", (int) uwsgi.workers[i+1].pid);
|
||||
stats_send_llu("\"requests\": %llu, ", uwsgi.workers[i+1].requests);
|
||||
stats_send_llu("\"exceptions\": %llu, ", uwsgi.workers[i+1].exceptions);
|
||||
stats_send_llu("\"signals\": %llu, ", uwsgi.workers[i+1].signals);
|
||||
|
||||
if (uwsgi.workers[i + 1].cheaped) {
|
||||
fprintf(output,"\"status\": \"cheap\", ");
|
||||
@@ -339,15 +347,11 @@ void uwsgi_send_stats(int fd) {
|
||||
stats_send_llu("\"vsz\": %llu, ", uwsgi.workers[i+1].vsz_size);
|
||||
|
||||
stats_send_llu("\"running_time\": %llu, ", uwsgi.workers[i+1].running_time);
|
||||
|
||||
stats_send_llu("\"last_spawn\": %llu, ", uwsgi.workers[i+1].last_spawn);
|
||||
|
||||
stats_send_llu("\"respawn_count\": %llu, ", uwsgi.workers[i+1].respawn_count);
|
||||
|
||||
stats_send_llu("\"tx\": %llu, ", uwsgi.workers[i+1].tx);
|
||||
|
||||
stats_send_llu("\"avg_rt\": %llu, ", uwsgi.workers[i+1].avg_response_time);
|
||||
|
||||
|
||||
fprintf(output,"\"apps\": [\n");
|
||||
|
||||
for(j=0;j<uwsgi.workers[i+1].apps_cnt;j++) {
|
||||
|
||||
@@ -2272,6 +2272,12 @@ PyObject *py_uwsgi_workers(PyObject * self, PyObject * args) {
|
||||
}
|
||||
Py_DECREF(zero);
|
||||
|
||||
zero = PyLong_FromUnsignedLongLong(uwsgi.workers[i + 1].signals);
|
||||
if (PyDict_SetItemString(worker_dict, "signals", zero)) {
|
||||
goto clear;
|
||||
}
|
||||
Py_DECREF(zero);
|
||||
|
||||
zero = PyLong_FromUnsignedLongLong(uwsgi.workers[i + 1].exceptions);
|
||||
if (PyDict_SetItemString(worker_dict, "exceptions", zero)) {
|
||||
goto clear;
|
||||
|
||||
@@ -457,12 +457,13 @@ void log_syslog(char *syslog_opts) {
|
||||
|
||||
char *uwsgi_get_cwd() {
|
||||
|
||||
size_t newsize = 256;
|
||||
// set this to static to avoid useless reallocations in stats mode
|
||||
static size_t newsize = 256;
|
||||
|
||||
char *cwd = uwsgi_malloc(newsize);
|
||||
|
||||
if (getcwd(cwd, newsize) == NULL) {
|
||||
newsize = errno;
|
||||
if (getcwd(cwd, newsize) == NULL && errno == ERANGE) {
|
||||
newsize += 256;
|
||||
uwsgi_log("need a bigger buffer (%d bytes) for getcwd(). doing reallocation.\n", newsize);
|
||||
free(cwd);
|
||||
cwd = uwsgi_malloc(newsize);
|
||||
|
||||
@@ -82,6 +82,7 @@ static struct option long_base_options[] = {
|
||||
{"master", no_argument, 0, 'M'},
|
||||
{"emperor", required_argument, 0, LONG_ARGS_EMPEROR},
|
||||
{"emperor-tyrant", no_argument, &uwsgi.emperor_tyrant, 1},
|
||||
{"emperor-stats", required_argument, 0, LONG_ARGS_EMPEROR_STATS},
|
||||
{"early-emperor", no_argument, &uwsgi.early_emperor, 1},
|
||||
{"emperor-broodlord", required_argument, 0, LONG_ARGS_EMPEROR_BROODLORD},
|
||||
{"emperor-amqp-vhost", required_argument, 0, LONG_ARGS_EMPEROR_AMQP_VHOST},
|
||||
@@ -1358,6 +1359,8 @@ int main(int argc, char *argv[], char *envp[]) {
|
||||
|
||||
}
|
||||
|
||||
uwsgi_log("current working directory: %s\n", uwsgi.cwd);
|
||||
|
||||
if (uwsgi.screen_session) {
|
||||
uwsgi_log("*** running under screen session %s ***\n", uwsgi.screen_session);
|
||||
}
|
||||
@@ -3311,6 +3314,9 @@ static int manage_base_opt(int i, char *optarg) {
|
||||
uwsgi.stats = optarg;
|
||||
uwsgi.master_process = 1;
|
||||
return 1;
|
||||
case LONG_ARGS_EMPEROR_STATS:
|
||||
uwsgi.emperor_stats = optarg;
|
||||
return 1;
|
||||
case LONG_ARGS_CACHE_SERVER_THREADS:
|
||||
uwsgi.cache_server_threads = atoi(optarg);
|
||||
return 1;
|
||||
|
||||
@@ -1031,6 +1031,8 @@ struct uwsgi_server {
|
||||
pid_t emperor_pid;
|
||||
int emperor_broodlord;
|
||||
int emperor_broodlord_count;
|
||||
char *emperor_stats;
|
||||
int emperor_stats_fd;
|
||||
struct uwsgi_config_template *vassals_templates;
|
||||
// true if loyal to the emperor
|
||||
int loyal;
|
||||
|
||||
@@ -268,8 +268,10 @@ $(document).ready(function() {
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>pid</th>
|
||||
<th>status</th>
|
||||
<th>requests</th>
|
||||
<th>exceptions</th>
|
||||
<th>signals</th>
|
||||
<th>running time</th>
|
||||
<th>avg response time</th>
|
||||
{% if 'memory-report' in uwsgi.opt %}
|
||||
@@ -282,8 +284,10 @@ $(document).ready(function() {
|
||||
<tr class="{{ loop.cycle('odd', 'even') }}">
|
||||
<td>{{w.id}}</td>
|
||||
<td>{{w.pid}}</td>
|
||||
<td>{{w.status}}</td>
|
||||
<td>{{w.requests}}</td>
|
||||
<td>{{w.exceptions}}</td>
|
||||
<td>{{w.signals}}</td>
|
||||
<td>{{w.running_time/1000}}</td>
|
||||
<td>{{w.avg_rt/1000}}</td>
|
||||
{% if 'memory-report' in uwsgi.opt %}
|
||||
|
||||
Reference in New Issue
Block a user