Skip to content

Fix #292: Add server-specific channel statistics #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ h1(#changelog). Changelog

h2. Version 0.6.0

* Fix #292 adding support for server-specific channel statistics to prevent information leakage between different server instances

* Fix #307 adding support for Nginx 1.23.0+
* Update gems and other test dependencies
* [javascript] Remove deprecated javascript event usage (Thanks @d-javu)
Expand Down
80 changes: 41 additions & 39 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -135,45 +135,46 @@ There is a javascript client implementation "here":javascript_client, which is f

h1(#directives). Directives

(1) Defining locations, (2) Main configuration, (3) Subscribers configuration, (4) Publishers configuration, (5) Channels Statistics configuration, (6) WebSocket configuration

(head). | Directive | (1) | (2) | (3) | (4) | (5) | (6) |
| "push_stream_channels_statistics":push_stream_channels_statistics |   x |   - |   - |   - |   - |   - |
| "push_stream_publisher":push_stream_publisher |   x |   - |   - |   - |   - |   - |
| "push_stream_subscriber":push_stream_subscriber |   x |   - |   - |   - |   - |   - |
| "push_stream_shared_memory_size":push_stream_shared_memory_size |   - |   x |   - |   - |   - |   - |
| "push_stream_channel_deleted_message_text":push_stream_channel_deleted_message_text |   - |   x |   - |   - |   - |   - |
| "push_stream_channel_inactivity_time":push_stream_channel_inactivity_time |   - |   x |   - |   - |   - |   - |
| "push_stream_ping_message_text":push_stream_ping_message_text |   - |   x |   - |   - |   - |   - |
| "push_stream_timeout_with_body":push_stream_timeout_with_body |   - |   x |   - |   - |   - |   - |
| "push_stream_message_ttl":push_stream_message_ttl |   - |   x |   - |   - |   - |   - |
| "push_stream_max_subscribers_per_channel":push_stream_max_subscribers_per_channel |   - |   x |   - |   - |   - |   - |
| "push_stream_max_messages_stored_per_channel":push_stream_max_messages_stored_per_channel |   - |   x |   - |   - |   - |   - |
| "push_stream_max_channel_id_length":push_stream_max_channel_id_length |   - |   x |   - |   - |   - |   - |
| "push_stream_max_number_of_channels":push_stream_max_number_of_channels |   - |   x |   - |   - |   - |   - |
| "push_stream_max_number_of_wildcard_channels":push_stream_max_number_of_wildcard_channels |   - |   x |   - |   - |   - |   - |
| "push_stream_wildcard_channel_prefix":push_stream_wildcard_channel_prefix |   - |   x |   - |   - |   - |   - |
| "push_stream_events_channel_id":push_stream_events_channel_id |   - |   x |   - |   - |   - |   - |
| "push_stream_channels_path":push_stream_channels_path |   - |   - |   x |   x |   x |   x |
| "push_stream_store_messages":push_stream_store_messages |   - |   - |   - |   x |   - |   x |
| "push_stream_channel_info_on_publish":push_stream_channel_info_on_publish |   - |   - |   - |   x |   - |   - |
| "push_stream_authorized_channels_only":push_stream_authorized_channels_only |   - |   - |   x |   - |   - |   x |
| "push_stream_header_template_file":push_stream_header_template_file |   - |   - |   x |   - |   - |   x |
| "push_stream_header_template":push_stream_header_template |   - |   - |   x |   - |   - |   x |
| "push_stream_message_template":push_stream_message_template |   - |   - |   x |   - |   - |   x |
| "push_stream_footer_template":push_stream_footer_template |   - |   - |   x |   - |   - |   x |
| "push_stream_wildcard_channel_max_qtd":push_stream_wildcard_channel_max_qtd |   - |   - |   x |   - |   - |   x |
| "push_stream_ping_message_interval":push_stream_ping_message_interval |   - |   - |   x |   - |   - |   x |
| "push_stream_subscriber_connection_ttl":push_stream_subscriber_connection_ttl |   - |   - |   x |   - |   - |   x |
| "push_stream_longpolling_connection_ttl":push_stream_longpolling_connection_ttl |   - |   - |   x |   - |   - |   - |
| "push_stream_websocket_allow_publish":push_stream_websocket_allow_publish |   - |   - |   - |   - |   - |   x |
| "push_stream_last_received_message_time":push_stream_last_received_message_time |   - |   - |   x |   - |   - |   - |
| "push_stream_last_received_message_tag":push_stream_last_received_message_tag |   - |   - |   x |   - |   - |   - |
| "push_stream_last_event_id":push_stream_last_event_id |   - |   - |   x |   - |   - |   - |
| "push_stream_user_agent":push_stream_user_agent |   - |   - |   x |   - |   - |   - |
| "push_stream_padding_by_user_agent":push_stream_padding_by_user_agent |   - |   - |   x |   - |   - |   - |
| "push_stream_allowed_origins":push_stream_allowed_origins |   - |   - |   x |   - |   - |   - |
| "push_stream_allow_connections_to_events_channel":push_stream_allow_connections_to_events_channel |   - |   - |   x |   - |   - |   x |
(1) Defining locations, (2) Main configuration, (3) Subscribers configuration, (4) Publishers configuration, (5) Channels Statistics configuration, (6) WebSocket configuration, (7) Server configuration

(head). | Directive | (1) | (2) | (3) | (4) | (5) | (6) | (7) |
| "push_stream_channels_statistics":push_stream_channels_statistics |   x |   - |   - |   - |   - |   - |   - |
| "push_stream_publisher":push_stream_publisher |   x |   - |   - |   - |   - |   - |   - |
| "push_stream_subscriber":push_stream_subscriber |   x |   - |   - |   - |   - |   - |   - |
| "push_stream_shared_memory_size":push_stream_shared_memory_size |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_channel_deleted_message_text":push_stream_channel_deleted_message_text |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_channel_inactivity_time":push_stream_channel_inactivity_time |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_ping_message_text":push_stream_ping_message_text |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_timeout_with_body":push_stream_timeout_with_body |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_message_ttl":push_stream_message_ttl |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_max_subscribers_per_channel":push_stream_max_subscribers_per_channel |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_max_messages_stored_per_channel":push_stream_max_messages_stored_per_channel |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_max_channel_id_length":push_stream_max_channel_id_length |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_max_number_of_channels":push_stream_max_number_of_channels |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_max_number_of_wildcard_channels":push_stream_max_number_of_wildcard_channels |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_wildcard_channel_prefix":push_stream_wildcard_channel_prefix |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_events_channel_id":push_stream_events_channel_id |   - |   x |   - |   - |   - |   - |   - |
| "push_stream_server_id":push_stream_server_id |   - |   - |   - |   - |   - |   - |   x |
| "push_stream_channels_path":push_stream_channels_path |   - |   - |   x |   x |   x |   x |   - |
| "push_stream_store_messages":push_stream_store_messages |   - |   - |   - |   x |   - |   x |   - |
| "push_stream_channel_info_on_publish":push_stream_channel_info_on_publish |   - |   - |   - |   x |   - |   - |   - |
| "push_stream_authorized_channels_only":push_stream_authorized_channels_only |   - |   - |   x |   - |   - |   x |   - |
| "push_stream_header_template_file":push_stream_header_template_file |   - |   - |   x |   - |   - |   x |   - |
| "push_stream_header_template":push_stream_header_template |   - |   - |   x |   - |   - |   x |   - |
| "push_stream_message_template":push_stream_message_template |   - |   - |   x |   - |   - |   x |   - |
| "push_stream_footer_template":push_stream_footer_template |   - |   - |   x |   - |   - |   x |   - |
| "push_stream_wildcard_channel_max_qtd":push_stream_wildcard_channel_max_qtd |   - |   - |   x |   - |   - |   x |   - |
| "push_stream_ping_message_interval":push_stream_ping_message_interval |   - |   - |   x |   - |   - |   x |   - |
| "push_stream_subscriber_connection_ttl":push_stream_subscriber_connection_ttl |   - |   - |   x |   - |   - |   x |   - |
| "push_stream_longpolling_connection_ttl":push_stream_longpolling_connection_ttl |   - |   - |   x |   - |   - |   - |   - |
| "push_stream_websocket_allow_publish":push_stream_websocket_allow_publish |   - |   - |   - |   - |   - |   x |   - |
| "push_stream_last_received_message_time":push_stream_last_received_message_time |   - |   - |   x |   - |   - |   - |   - |
| "push_stream_last_received_message_tag":push_stream_last_received_message_tag |   - |   - |   x |   - |   - |   - |   - |
| "push_stream_last_event_id":push_stream_last_event_id |   - |   - |   x |   - |   - |   - |   - |
| "push_stream_user_agent":push_stream_user_agent |   - |   - |   x |   - |   - |   - |   - |
| "push_stream_padding_by_user_agent":push_stream_padding_by_user_agent |   - |   - |   x |   - |   - |   - |   - |
| "push_stream_allowed_origins":push_stream_allowed_origins |   - |   - |   x |   - |   - |   - |   - |
| "push_stream_allow_connections_to_events_channel":push_stream_allow_connections_to_events_channel |   - |   - |   x |   - |   - |   x |   - |

h1(#installation). Installation <a name="installation" href="#">&nbsp;</a>

Expand Down Expand Up @@ -284,5 +285,6 @@ h1(#contributors). Contributors
[push_stream_allowed_origins]docs/directives/subscribers.textile#push_stream_allowed_origins
[push_stream_websocket_allow_publish]docs/directives/subscribers.textile#push_stream_websocket_allow_publish
[push_stream_allow_connections_to_events_channel]docs/directives/subscribers.textile#push_stream_allow_connections_to_events_channel
[push_stream_server_id]docs/directives/server.textile#push_stream_server_id
[wiki]https://github.com/wandenberg/nginx-push-stream-module/wiki/_pages
[nginx_debugging]http://wiki.nginx.org/Debugging
26 changes: 26 additions & 0 deletions docs/directives/server.textile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
h1(#server_configuration). Server Configuration

h2(#push_stream_server_id). push_stream_server_id <a name="push_stream_server_id" href="#">&nbsp;</a>

*syntax:* _push_stream_server_id string_

*default:* _none_

*context:* _server_

Sets a unique identifier for the server instance. This is used to separate statistics between different server instances running on the same host. When this directive is set, the channels-stats endpoint will only report published_messages and stored_messages for the current server instance, preventing information leakage between different server instances.

Example:
<pre>
server {
listen 5601;
push_stream_server_id "server_5601";
...
}

server {
listen 5602;
push_stream_server_id "server_5602";
...
}
</pre>
3 changes: 3 additions & 0 deletions include/ngx_http_push_stream_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ struct ngx_http_push_stream_shm_data_s {
ngx_uint_t published_messages; // # of published messagens in all channels
ngx_uint_t stored_messages; // # of messages being stored
ngx_uint_t subscribers; // # of subscribers in all channels
ngx_uint_t server_published_messages; // # of published messages in current server instance
ngx_uint_t server_stored_messages; // # of messages being stored in current server instance
ngx_str_t server_id; // server instance identifier
ngx_queue_t messages_trash;
ngx_shmtx_t messages_trash_mutex;
ngx_shmtx_sh_t messages_trash_lock;
Expand Down
1 change: 1 addition & 0 deletions include/ngx_http_push_stream_module_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static void * ngx_http_push_stream_create_loc_conf(ngx_conf_t *cf);
static char * ngx_http_push_stream_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child);

// shared memory
char * ngx_http_push_stream_set_server_id(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
char * ngx_http_push_stream_set_shm_size_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
ngx_int_t ngx_http_push_stream_init_shm_zone(ngx_shm_zone_t *shm_zone, void *data);
ngx_int_t ngx_http_push_stream_init_global_shm_zone(ngx_shm_zone_t *shm_zone, void *data);
Expand Down
7 changes: 6 additions & 1 deletion src/ngx_http_push_stream_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ ngx_http_push_stream_send_response_all_channels_info_summarized(ngx_http_request
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

ngx_sprintf(text->data, (char *) subtype->format_summarized->data, hostname->data, currenttime->data, data->channels, data->wildcard_channels, data->published_messages, data->stored_messages, data->messages_in_trash, data->channels_in_delete, data->channels_in_trash, data->subscribers, ngx_time() - data->startup, subscribers_by_workers);
// Use server-specific counters if available
if (data->server_id.len > 0) {
ngx_sprintf(text->data, (char *) subtype->format_summarized->data, hostname->data, currenttime->data, data->channels, data->wildcard_channels, data->server_published_messages, data->server_stored_messages, data->messages_in_trash, data->channels_in_delete, data->channels_in_trash, data->subscribers, ngx_time() - data->startup, subscribers_by_workers);
} else {
ngx_sprintf(text->data, (char *) subtype->format_summarized->data, hostname->data, currenttime->data, data->channels, data->wildcard_channels, data->published_messages, data->stored_messages, data->messages_in_trash, data->channels_in_delete, data->channels_in_trash, data->subscribers, ngx_time() - data->startup, subscribers_by_workers);
}
text->len = ngx_strlen(text->data);

return ngx_http_push_stream_send_response(r, text, subtype->content_type, NGX_HTTP_OK);
Expand Down
Loading