Commit 874079ea authored by Wandenberg Peixoto's avatar Wandenberg Peixoto

adding subscribers count by each worker as part of statistics

parent e95689e0
...@@ -121,6 +121,8 @@ typedef struct { ...@@ -121,6 +121,8 @@ typedef struct {
typedef struct { typedef struct {
ngx_http_push_stream_worker_msg_t messages_queue; ngx_http_push_stream_worker_msg_t messages_queue;
ngx_http_push_stream_worker_subscriber_t worker_subscribers_sentinel; ngx_http_push_stream_worker_subscriber_t worker_subscribers_sentinel;
ngx_uint_t subscribers; // # of subscribers in the worker
pid_t pid;
} ngx_http_push_stream_worker_data_t; } ngx_http_push_stream_worker_data_t;
// shared memory // shared memory
......
...@@ -21,36 +21,47 @@ typedef struct { ...@@ -21,36 +21,47 @@ typedef struct {
ngx_str_t *format_group_last_item; ngx_str_t *format_group_last_item;
ngx_str_t *format_group_tail; ngx_str_t *format_group_tail;
ngx_str_t *format_summarized; ngx_str_t *format_summarized;
ngx_str_t *format_summarized_worker_item;
ngx_str_t *format_summarized_worker_last_item;
} ngx_http_push_stream_content_subtype_t; } ngx_http_push_stream_content_subtype_t;
#define NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN_PATTERN "channel: %s" CRLF"published_messages: %ui" CRLF"stored_messages: %ui" CRLF"active_subscribers: %ui" #define NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN_PATTERN "channel: %s" CRLF"published_messages: %ui" CRLF"stored_messages: %ui" CRLF"active_subscribers: %ui"
#define NGX_HTTP_PUSH_STREAM_WORKER_INFO_PLAIN_PATTERN " pid: %d" CRLF" subscribers: %ui"
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN_PATTERN CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_HEAD_PLAIN = ngx_string("hostname: %s, time: %s, channels: %ui, broadcast_channels: %ui, infos: " CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_HEAD_PLAIN = ngx_string("hostname: %s, time: %s, channels: %ui, broadcast_channels: %ui, infos: " CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_PLAIN = ngx_string(CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_PLAIN = ngx_string(CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_PLAIN = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN_PATTERN "," CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_PLAIN = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN_PATTERN "," CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_PLAIN = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_PLAIN = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_PLAIN_PATTERN);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_PLAIN = ngx_string("hostname: %s" CRLF "time: %s" CRLF "channels: %ui" CRLF "broadcast_channels: %ui" CRLF "published_messages: %ui" CRLF "subscribers: %ui" CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_PLAIN = ngx_string("hostname: %s" CRLF "time: %s" CRLF "channels: %ui" CRLF "broadcast_channels: %ui" CRLF "published_messages: %ui" CRLF "subscribers: %ui" CRLF "by_worker:"CRLF"%s" CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_PLAIN = ngx_string(NGX_HTTP_PUSH_STREAM_WORKER_INFO_PLAIN_PATTERN "," CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_PLAIN = ngx_string(NGX_HTTP_PUSH_STREAM_WORKER_INFO_PLAIN_PATTERN);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_PLAIN = ngx_string("text/plain"); static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_PLAIN = ngx_string("text/plain");
#define NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON_PATTERN "{\"channel\": \"%s\", \"published_messages\": \"%ui\", \"stored_messages\": \"%ui\", \"subscribers\": \"%ui\"}" #define NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON_PATTERN "{\"channel\": \"%s\", \"published_messages\": \"%ui\", \"stored_messages\": \"%ui\", \"subscribers\": \"%ui\"}"
#define NGX_HTTP_PUSH_STREAM_WORKER_INFO_JSON_PATTERN "{\"pid\": \"%d\", \"subscribers\": \"%ui\"}"
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON_PATTERN CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_HEAD_JSON = ngx_string("{\"hostname\": \"%s\", \"time\": \"%s\", \"channels\": \"%ui\", \"broadcast_channels\": \"%ui\", \"infos\": [" CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_HEAD_JSON = ngx_string("{\"hostname\": \"%s\", \"time\": \"%s\", \"channels\": \"%ui\", \"broadcast_channels\": \"%ui\", \"infos\": [" CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_JSON = ngx_string("]}" CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_JSON = ngx_string("]}" CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_JSON = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON_PATTERN "," CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_JSON = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON_PATTERN "," CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_JSON = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_JSON = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON_PATTERN CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_JSON = ngx_string("{\"hostname\": \"%s\", \"time\": \"%s\", \"channels\": \"%ui\", \"broadcast_channels\": \"%ui\", \"published_messages\": \"%ui\", \"subscribers\": \"%ui\"}" CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_JSON = ngx_string("{\"hostname\": \"%s\", \"time\": \"%s\", \"channels\": \"%ui\", \"broadcast_channels\": \"%ui\", \"published_messages\": \"%ui\", \"subscribers\": \"%ui\", \"by_worker\": [" CRLF "%s" CRLF"]}" CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_JSON = ngx_string(NGX_HTTP_PUSH_STREAM_WORKER_INFO_JSON_PATTERN "," CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_JSON = ngx_string(NGX_HTTP_PUSH_STREAM_WORKER_INFO_JSON_PATTERN);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_JSON = ngx_string("application/json"); static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_JSON = ngx_string("application/json");
static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_JSON = ngx_string("text/x-json"); static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_JSON = ngx_string("text/x-json");
#define NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML_PATTERN " channel: %s" CRLF" published_messages: %ui" CRLF" stored_messages: %ui" CRLF" subscribers: %ui" #define NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML_PATTERN " channel: %s" CRLF" published_messages: %ui" CRLF" stored_messages: %ui" CRLF" subscribers: %ui"
#define NGX_HTTP_PUSH_STREAM_WORKER_INFO_YAML_PATTERN " pid: %d" CRLF" subscribers: %ui"
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML_PATTERN CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_HEAD_YAML = ngx_string("hostname: %s" CRLF"time: %s" CRLF"channels: %ui" CRLF"broadcast_channels: %ui" CRLF"infos: "CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_HEAD_YAML = ngx_string("hostname: %s" CRLF"time: %s" CRLF"channels: %ui" CRLF"broadcast_channels: %ui" CRLF"infos: "CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_YAML = ngx_string(CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_YAML = ngx_string(CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_YAML = ngx_string(" -" CRLF NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_YAML = ngx_string(" -" CRLF NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML_PATTERN CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_YAML = ngx_string(" -" CRLF NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_YAML = ngx_string(" -" CRLF NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML_PATTERN);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_YAML = ngx_string(" hostname: %s" CRLF" time: %s" CRLF" channels: %ui" CRLF" broadcast_channels: %ui" CRLF" published_messages: %ui" CRLF" subscribers: %ui" CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_YAML = ngx_string(" hostname: %s" CRLF" time: %s" CRLF" channels: %ui" CRLF" broadcast_channels: %ui" CRLF" published_messages: %ui" CRLF" subscribers: %ui" CRLF " by_worker:"CRLF"%s" CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_YAML = ngx_string(" -" CRLF NGX_HTTP_PUSH_STREAM_WORKER_INFO_YAML_PATTERN CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_YAML = ngx_string(" -" CRLF NGX_HTTP_PUSH_STREAM_WORKER_INFO_YAML_PATTERN);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_YAML = ngx_string("application/yaml"); static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_YAML = ngx_string("application/yaml");
static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_YAML = ngx_string("text/x-yaml"); static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_YAML = ngx_string("text/x-yaml");
...@@ -62,11 +73,16 @@ static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_YAML = ngx_string("text/x- ...@@ -62,11 +73,16 @@ static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_YAML = ngx_string("text/x-
" <stored_messages>%ui</stored_messages>" CRLF \ " <stored_messages>%ui</stored_messages>" CRLF \
" <subscribers>%ui</subscribers>" CRLF \ " <subscribers>%ui</subscribers>" CRLF \
"</channel>" CRLF "</channel>" CRLF
#define NGX_HTTP_PUSH_STREAM_WORKER_INFO_XML_PATTERN \
"<worker>" CRLF \
" <pid>%d</pid>" CRLF \
" <subscribers>%ui</subscribers>" CRLF \
"</worker>" CRLF
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML = ngx_string("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" CRLF NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML = ngx_string("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" CRLF NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML_PATTERN CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_HEAD_XML = ngx_string("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" CRLF "<root>" CRLF" <hostname>%s</hostname>" CRLF" <time>%s</time>" CRLF" <channels>%ui</channels>" CRLF" <broadcast_channels>%ui</broadcast_channels>" CRLF" <infos>" CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_HEAD_XML = ngx_string("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" CRLF "<root>" CRLF" <hostname>%s</hostname>" CRLF" <time>%s</time>" CRLF" <channels>%ui</channels>" CRLF" <broadcast_channels>%ui</broadcast_channels>" CRLF" <infos>" CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_XML = ngx_string(" </infos>" CRLF"</root>" CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_XML = ngx_string(" </infos>" CRLF"</root>" CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_XML = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_XML = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML_PATTERN);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_XML = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML_PATTERN CRLF); static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_XML = ngx_string(NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML_PATTERN);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_XML = ngx_string( static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_XML = ngx_string(
"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" CRLF \ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" CRLF \
"<infos>" CRLF \ "<infos>" CRLF \
...@@ -76,7 +92,10 @@ static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_XML = ngx_string ...@@ -76,7 +92,10 @@ static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_XML = ngx_string
" <broadcast_channels>%ui</broadcast_channels>" CRLF \ " <broadcast_channels>%ui</broadcast_channels>" CRLF \
" <published_messages>%ui</published_messages>" CRLF \ " <published_messages>%ui</published_messages>" CRLF \
" <subscribers>%ui</subscribers>" CRLF\ " <subscribers>%ui</subscribers>" CRLF\
" <by_worker>%s</by_worker>" CRLF\
"</infos>" CRLF); "</infos>" CRLF);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_XML = ngx_string(NGX_HTTP_PUSH_STREAM_WORKER_INFO_XML_PATTERN);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_XML = ngx_string(NGX_HTTP_PUSH_STREAM_WORKER_INFO_XML_PATTERN);
static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_XML = ngx_string("application/xml"); static ngx_str_t NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_XML = ngx_string("application/xml");
static ngx_http_push_stream_content_subtype_t subtypes[] = { static ngx_http_push_stream_content_subtype_t subtypes[] = {
...@@ -87,7 +106,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = { ...@@ -87,7 +106,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = {
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_PLAIN, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_PLAIN,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_PLAIN, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_PLAIN,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_PLAIN, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_PLAIN,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_PLAIN }, &NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_PLAIN,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_PLAIN,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_PLAIN},
{ "json" , 4, { "json" , 4,
&NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_JSON, &NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON,
...@@ -95,7 +116,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = { ...@@ -95,7 +116,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = {
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_JSON, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_JSON, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_JSON, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_JSON }, &NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_JSON },
{ "yaml" , 4, { "yaml" , 4,
&NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_YAML, &NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML,
...@@ -103,7 +126,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = { ...@@ -103,7 +126,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = {
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_YAML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_YAML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_YAML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_YAML }, &NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_YAML },
{ "xml" , 3, { "xml" , 3,
&NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_XML, &NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_XML,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_XML,
...@@ -111,7 +136,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = { ...@@ -111,7 +136,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = {
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_XML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_XML,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_XML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_XML,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_XML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_XML,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_XML }, &NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_XML,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_XML,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_XML },
{ "x-json", 6, { "x-json", 6,
&NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_JSON, &NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_JSON,
...@@ -119,7 +146,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = { ...@@ -119,7 +146,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = {
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_JSON, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_JSON, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_JSON, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_JSON }, &NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_JSON,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_JSON },
{ "x-yaml", 6, { "x-yaml", 6,
&NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_YAML, &NGX_HTTP_PUSH_STREAM_CONTENT_TYPE_X_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_YAML,
...@@ -127,7 +156,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = { ...@@ -127,7 +156,9 @@ static ngx_http_push_stream_content_subtype_t subtypes[] = {
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_YAML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_ITEM_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_YAML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_LAST_ITEM_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_YAML, &NGX_HTTP_PUSH_STREAM_CHANNEL_INFO_GROUP_TAIL_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_YAML } &NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_ITEM_YAML,
&NGX_HTTP_PUSH_STREAM_CHANNELS_INFO_SUMMARIZED_WORKER_LAST_ITEM_YAML }
}; };
static const ngx_str_t NGX_PUSH_STREAM_PING_MESSAGE_ID = ngx_string("-1"); static const ngx_str_t NGX_PUSH_STREAM_PING_MESSAGE_ID = ngx_string("-1");
......
...@@ -119,8 +119,11 @@ ngx_http_push_stream_send_response_all_channels_info_summarized(ngx_http_request ...@@ -119,8 +119,11 @@ ngx_http_push_stream_send_response_all_channels_info_summarized(ngx_http_request
ngx_buf_t *b; ngx_buf_t *b;
ngx_uint_t len; ngx_uint_t len;
ngx_str_t *currenttime, *hostname; ngx_str_t *currenttime, *hostname, *format;
u_char *subscribers_by_workers, *start;
int i;
ngx_http_push_stream_shm_data_t *shm_data; ngx_http_push_stream_shm_data_t *shm_data;
ngx_http_push_stream_worker_data_t *worker_data;
ngx_http_push_stream_content_subtype_t *subtype; ngx_http_push_stream_content_subtype_t *subtype;
subtype = ngx_http_push_stream_match_channel_info_format_and_content_type(r, 1); subtype = ngx_http_push_stream_match_channel_info_format_and_content_type(r, 1);
...@@ -129,7 +132,17 @@ ngx_http_push_stream_send_response_all_channels_info_summarized(ngx_http_request ...@@ -129,7 +132,17 @@ ngx_http_push_stream_send_response_all_channels_info_summarized(ngx_http_request
shm_data = (ngx_http_push_stream_shm_data_t *) ngx_http_push_stream_shm_zone->data; shm_data = (ngx_http_push_stream_shm_data_t *) ngx_http_push_stream_shm_zone->data;
len = 3*NGX_INT_T_LEN + subtype->format_summarized->len + hostname->len + currenttime->len - 16;// minus 16 sprintf len = (subtype->format_summarized_worker_item->len > subtype->format_summarized_worker_last_item->len) ? subtype->format_summarized_worker_item->len : subtype->format_summarized_worker_last_item->len;
len = ngx_http_push_stream_worker_processes * (2*NGX_INT_T_LEN + len - 5); //minus 5 sprintf
subscribers_by_workers = ngx_pcalloc(r->pool, len);
start = subscribers_by_workers;
for (i = 0; i < ngx_http_push_stream_worker_processes; i++) {
format = (i < ngx_http_push_stream_worker_processes - 1) ? subtype->format_summarized_worker_item : subtype->format_summarized_worker_last_item;
worker_data = shm_data->ipc + i;
start = ngx_sprintf(start, (char *) format->data, worker_data->pid, worker_data->subscribers);
}
len = 3*NGX_INT_T_LEN + subtype->format_summarized->len + hostname->len + currenttime->len + ngx_strlen(subscribers_by_workers) - 18;// minus 18 sprintf
if ((b = ngx_create_temp_buf(r->pool, len)) == NULL) { if ((b = ngx_create_temp_buf(r->pool, len)) == NULL) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Failed to allocate response buffer."); ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "Failed to allocate response buffer.");
...@@ -137,7 +150,7 @@ ngx_http_push_stream_send_response_all_channels_info_summarized(ngx_http_request ...@@ -137,7 +150,7 @@ ngx_http_push_stream_send_response_all_channels_info_summarized(ngx_http_request
} }
ngx_memset(b->start, '\0', len); ngx_memset(b->start, '\0', len);
b->last = ngx_sprintf(b->start, (char *) subtype->format_summarized->data, hostname->data, currenttime->data, shm_data->channels, shm_data->broadcast_channels, shm_data->published_messages, shm_data->subscribers); b->last = ngx_sprintf(b->start, (char *) subtype->format_summarized->data, hostname->data, currenttime->data, shm_data->channels, shm_data->broadcast_channels, shm_data->published_messages, shm_data->subscribers, subscribers_by_workers);
return ngx_http_push_stream_send_buf_response(r, b, subtype->content_type, NGX_HTTP_OK); return ngx_http_push_stream_send_buf_response(r, b, subtype->content_type, NGX_HTTP_OK);
} }
......
...@@ -99,12 +99,16 @@ ngx_http_push_stream_init_ipc_shm(ngx_int_t workers) ...@@ -99,12 +99,16 @@ ngx_http_push_stream_init_ipc_shm(ngx_int_t workers)
if (data->ipc != NULL) { if (data->ipc != NULL) {
// already initialized... reset channel subscribers counters and census subscribers // already initialized... reset channel subscribers counters and census subscribers
ngx_http_push_stream_worker_data_t *workers_data = data->ipc; ngx_http_push_stream_worker_data_t *worker_data = NULL;
ngx_http_push_stream_worker_data_t *thisworker_data = workers_data + ngx_process_slot; ngx_http_push_stream_worker_data_t *thisworker_data = data->ipc + ngx_process_slot;
ngx_http_push_stream_worker_subscriber_t *sentinel = &thisworker_data->worker_subscribers_sentinel; ngx_http_push_stream_worker_subscriber_t *sentinel = &thisworker_data->worker_subscribers_sentinel;
ngx_queue_init(&sentinel->queue); ngx_queue_init(&sentinel->queue);
for(i=0; i<workers; i++) {
worker_data = data->ipc + i;
worker_data->subscribers = 0;
}
data->subscribers = 0; data->subscribers = 0;
ngx_http_push_stream_walk_rbtree(ngx_http_push_stream_reset_channel_subscribers_count_locked); ngx_http_push_stream_walk_rbtree(ngx_http_push_stream_reset_channel_subscribers_count_locked);
...@@ -224,6 +228,7 @@ ngx_http_push_stream_census_worker_subscribers(void) ...@@ -224,6 +228,7 @@ ngx_http_push_stream_census_worker_subscribers(void)
cur_subscription->channel->subscribers++; cur_subscription->channel->subscribers++;
} }
data->subscribers++; data->subscribers++;
thisworker_data->subscribers++;
} }
ngx_shmtx_unlock(&shpool->mutex); ngx_shmtx_unlock(&shpool->mutex);
......
...@@ -180,6 +180,10 @@ ngx_http_push_stream_init_worker(ngx_cycle_t *cycle) ...@@ -180,6 +180,10 @@ ngx_http_push_stream_init_worker(ngx_cycle_t *cycle)
return NGX_ERROR; return NGX_ERROR;
} }
ngx_http_push_stream_shm_data_t *data = (ngx_http_push_stream_shm_data_t *) ngx_http_push_stream_shm_zone->data;
ngx_http_push_stream_worker_data_t *thisworker_data = data->ipc + ngx_process_slot;
thisworker_data->pid = ngx_pid;
return ngx_http_push_stream_register_worker_message_handler(cycle); return ngx_http_push_stream_register_worker_message_handler(cycle);
} }
......
...@@ -12,8 +12,8 @@ ngx_http_push_stream_subscriber_handler(ngx_http_request_t *r) ...@@ -12,8 +12,8 @@ ngx_http_push_stream_subscriber_handler(ngx_http_request_t *r)
ngx_pool_t *temp_pool; ngx_pool_t *temp_pool;
ngx_uint_t subscribed_channels_qtd = 0; ngx_uint_t subscribed_channels_qtd = 0;
ngx_uint_t subscribed_broadcast_channels_qtd = 0; ngx_uint_t subscribed_broadcast_channels_qtd = 0;
ngx_http_push_stream_worker_data_t *workers_data = ((ngx_http_push_stream_shm_data_t *) ngx_http_push_stream_shm_zone->data)->ipc; ngx_http_push_stream_shm_data_t *data = (ngx_http_push_stream_shm_data_t *) ngx_http_push_stream_shm_zone->data;
ngx_http_push_stream_worker_data_t *thisworker_data = workers_data + ngx_process_slot; ngx_http_push_stream_worker_data_t *thisworker_data = data->ipc + ngx_process_slot;
ngx_flag_t is_broadcast_channel; ngx_flag_t is_broadcast_channel;
ngx_http_push_stream_channel_t *channel; ngx_http_push_stream_channel_t *channel;
...@@ -140,7 +140,8 @@ ngx_http_push_stream_subscriber_handler(ngx_http_request_t *r) ...@@ -140,7 +140,8 @@ ngx_http_push_stream_subscriber_handler(ngx_http_request_t *r)
ngx_queue_insert_tail(&thisworker_data->worker_subscribers_sentinel.queue, &worker_subscriber->queue); ngx_queue_insert_tail(&thisworker_data->worker_subscribers_sentinel.queue, &worker_subscriber->queue);
// increment global subscribers count // increment global subscribers count
((ngx_http_push_stream_shm_data_t *) ngx_http_push_stream_shm_zone->data)->subscribers++; data->subscribers++;
thisworker_data->subscribers++;
ngx_shmtx_unlock(&shpool->mutex); ngx_shmtx_unlock(&shpool->mutex);
......
...@@ -471,6 +471,7 @@ ngx_http_push_stream_worker_subscriber_cleanup(ngx_http_push_stream_worker_subsc ...@@ -471,6 +471,7 @@ ngx_http_push_stream_worker_subscriber_cleanup(ngx_http_push_stream_worker_subsc
{ {
ngx_http_push_stream_subscription_t *cur, *sentinel; ngx_http_push_stream_subscription_t *cur, *sentinel;
ngx_slab_pool_t *shpool = (ngx_slab_pool_t *) ngx_http_push_stream_shm_zone->shm.addr; ngx_slab_pool_t *shpool = (ngx_slab_pool_t *) ngx_http_push_stream_shm_zone->shm.addr;
ngx_http_push_stream_shm_data_t *data = (ngx_http_push_stream_shm_data_t *) ngx_http_push_stream_shm_zone->data;
ngx_shmtx_lock(&shpool->mutex); ngx_shmtx_lock(&shpool->mutex);
sentinel = &worker_subscriber->subscriptions_sentinel; sentinel = &worker_subscriber->subscriptions_sentinel;
...@@ -484,7 +485,8 @@ ngx_http_push_stream_worker_subscriber_cleanup(ngx_http_push_stream_worker_subsc ...@@ -484,7 +485,8 @@ ngx_http_push_stream_worker_subscriber_cleanup(ngx_http_push_stream_worker_subsc
ngx_queue_remove(&worker_subscriber->queue); ngx_queue_remove(&worker_subscriber->queue);
ngx_queue_init(&worker_subscriber->queue); ngx_queue_init(&worker_subscriber->queue);
worker_subscriber->clndata->worker_subscriber = NULL; worker_subscriber->clndata->worker_subscriber = NULL;
((ngx_http_push_stream_shm_data_t *) ngx_http_push_stream_shm_zone->data)->subscribers--; data->subscribers--;
(data->ipc + ngx_process_slot)->subscribers--;
ngx_shmtx_unlock(&shpool->mutex); ngx_shmtx_unlock(&shpool->mutex);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment