Skip to content
This repository
Browse code

adding many statistics

  • Loading branch information...
commit 282c093dad3b9975aa2f60b29c36773e2d8ef3b4 1 parent 207b1cb
Travis Glenn Hansen authored

Showing 2 changed files with 97 additions and 9 deletions. Show diff stats Hide diff stats

  1. 2  README
  2. 104  fanout.c
2  README
@@ -4,7 +4,7 @@ receiving messages on different channels.
4 4
 Protocol:
5 5
 
6 6
 ping - replies with current timestamp on the server
7  
-stats - replies with some basic info about the server
  7
+info - replies with some basic info about the server
8 8
 subcribe <channel>
9 9
 unsubscribe <channel>
10 10
 announce <channel> <message>
104  fanout.c
@@ -14,7 +14,7 @@
14 14
 #include <time.h>
15 15
 #include <getopt.h>
16 16
 #include <stdarg.h>
17  
-
  17
+#include <limits.h>
18 18
 
19 19
 struct client
20 20
 {
@@ -81,6 +81,32 @@ void unsubscribe (struct client *c, const char *channel_name);
81 81
 // GLOBAL VARS
82 82
 fd_set readset, tempset;
83 83
 u_int max;
  84
+long server_start_time;
  85
+
  86
+//announcement stats
  87
+unsigned long long announcements_count =0;
  88
+unsigned long long announcements_count_multiplier = 0;
  89
+
  90
+//messages stats
  91
+unsigned long long messages_count =0;
  92
+unsigned long long messages_count_multiplier = 0;
  93
+
  94
+//subscription stats
  95
+unsigned long long subscriptions_count =0;
  96
+unsigned long long subscriptions_count_multiplier = 0;
  97
+
  98
+//unsubscription stats
  99
+unsigned long long unsubscriptions_count =0;
  100
+unsigned long long unsubscriptions_count_multiplier = 0;
  101
+
  102
+//ping stats
  103
+unsigned long long pings_count =0;
  104
+unsigned long long pings_count_multiplier = 0;
  105
+
  106
+//connection/client stats
  107
+unsigned long long clients_count =0;
  108
+unsigned long long clients_count_multiplier = 0;
  109
+
84 110
 static int daemonize = 0;
85 111
 
86 112
 FILE *logfile;
@@ -103,6 +129,7 @@ int main (int argc, char *argv[])
103 129
     u_int yes = 1;
104 130
     u_int listen_backlog = 25;
105 131
     FILE *pidfile;
  132
+    server_start_time = (long)time (NULL);
106 133
     char buffer[1025];
107 134
 
108 135
     struct client *client_i = NULL;
@@ -292,6 +319,13 @@ int main (int argc, char *argv[])
292 319
             fanout_debug (2, "client socket connected\n");
293 320
             client_write (client_i, "debug!connected...\n");
294 321
             subscribe (client_i, "all");
  322
+
  323
+            //stats
  324
+            if (clients_count == ULLONG_MAX) {
  325
+                clients_count_multiplier++;
  326
+                clients_count = 0;
  327
+            }
  328
+            clients_count++;
295 329
        }
296 330
 
297 331
         // Process events of other sockets...
@@ -598,7 +632,12 @@ void client_process_input_buffer (struct client *c)
598 632
             client_write (c, message);
599 633
             free (message);
600 634
             message = NULL;
601  
-        } else if ( ! strcmp (line, "stats")) {
  635
+            if (pings_count == ULLONG_MAX) {
  636
+                pings_count_multiplier++;
  637
+                pings_count = 0;
  638
+            }
  639
+            pings_count++;
  640
+        } else if ( ! strcmp (line, "info")) {
602 641
             //max connections
603 642
             u_int max_connection_count = max;
604 643
             if (daemonize) {
@@ -615,13 +654,39 @@ void client_process_input_buffer (struct client *c)
615 654
 
616 655
             //subscriptions
617 656
             u_int current_subscription_count = subscription_count ();
618  
-            //client
619  
-            //messages
620  
-
621  
-            asprintf (&message, "max connections: %d\ncurrent connections: %d\n\
622  
-current channels: %d\ncurrent subscriptions: %d\n", max_connection_count,
  657
+            u_int current_requested_subscriptions = (current_subscription_count
  658
+                                                      - current_client_count);
  659
+            //uptime
  660
+            long uptime = (long)time (NULL) - server_start_time;
  661
+
  662
+            asprintf (&message,
  663
+"uptime: %ldd %ldh %ldm %lds\n\
  664
+max connections: %d\n\
  665
+current connections: %d\n\
  666
+current channels: %d\n\
  667
+current subscriptions: %d\n\
  668
+user-requested subscriptions: %d\n\
  669
+total connections: %llu + (%llu * %llu)\n\
  670
+total announcements: %llu + (%llu * %llu)\n\
  671
+total messages: %llu + (%llu * %llu)\n\
  672
+total subscribes: %llu + (%llu * %llu)\n\
  673
+total unsubscribes: %llu + (%llu * %llu)\n\
  674
+total pings: %llu + (%llu * %llu)\
  675
+\n",                   uptime/3600/24, uptime/3600%24,
  676
+                       uptime/60%60, uptime%60,
  677
+                       max_connection_count,
623 678
                        current_client_count, current_channel_count,
624  
-                       current_subscription_count);
  679
+                       current_subscription_count,
  680
+                       current_requested_subscriptions, clients_count,
  681
+                       ULLONG_MAX, clients_count_multiplier,
  682
+                       announcements_count, ULLONG_MAX,
  683
+                       announcements_count_multiplier,
  684
+                       messages_count, ULLONG_MAX, messages_count_multiplier,
  685
+                       subscriptions_count, ULLONG_MAX,
  686
+                       subscriptions_count_multiplier,
  687
+                       unsubscriptions_count, ULLONG_MAX,
  688
+                       unsubscriptions_count_multiplier, pings_count,
  689
+                       ULLONG_MAX, pings_count_multiplier);
625 690
             client_write (c, message);
626 691
             free (message);
627 692
             message = NULL;
@@ -736,10 +801,21 @@ void announce (const char *channel, const char *message)
736 801
             fanout_debug (3, "announcing message %s to %d on channel %s\n",
737 802
                            message, subscription_i->client->fd, channel);
738 803
             client_write (subscription_i->client, s);
  804
+            //message stats
  805
+            if (messages_count == ULLONG_MAX) {
  806
+                messages_count_multiplier++;
  807
+                messages_count = 0;
  808
+            }
  809
+            messages_count++;
739 810
         }
740 811
         subscription_i = subscription_i->next;
741 812
     }
742 813
     fanout_debug (2, "announced messge %s", s);
  814
+    if (announcements_count == ULLONG_MAX) {
  815
+        announcements_count_multiplier++;
  816
+        announcements_count = 0;
  817
+    }
  818
+    announcements_count++;
743 819
     free (s);
744 820
 }
745 821
 
@@ -766,6 +842,12 @@ void subscribe (struct client *c, const char *channel_name)
766 842
     fanout_debug (2, "subscribed client %d to channel %s\n", c->fd,
767 843
                    subscription_i->channel->name);
768 844
 
  845
+    if (subscriptions_count == ULLONG_MAX) {
  846
+        subscriptions_count_multiplier++;
  847
+        subscriptions_count = 0;
  848
+    }
  849
+    subscriptions_count++;
  850
+
769 851
     subscription_i->next = subscription_head;
770 852
     if (subscription_head != NULL)
771 853
         subscription_head->previous = subscription_i;
@@ -790,6 +872,12 @@ void unsubscribe (struct client *c, const char *channel_name)
790 872
 
791 873
             channel->subscription_count--;
792 874
 
  875
+            if (unsubscriptions_count == ULLONG_MAX) {
  876
+                unsubscriptions_count_multiplier++;
  877
+                unsubscriptions_count = 0;
  878
+            }
  879
+            unsubscriptions_count++;
  880
+
793 881
             if ( ! channel_has_subscription (channel)) {
794 882
                 remove_channel (channel);
795 883
                 destroy_channel (channel);

0 notes on commit 282c093

Please sign in to comment.
Something went wrong with that request. Please try again.