wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[ljcom] r11536: iLJSUP-11381: Create counters for monito...

Committer: gprochaev
iLJSUP-11381: Create counters for monitoring

U   trunk/cgi-bin/LJ/Hooks/SUP.pm
Modified: trunk/cgi-bin/LJ/Hooks/SUP.pm
===================================================================
--- trunk/cgi-bin/LJ/Hooks/SUP.pm	2012-02-27 12:46:50 UTC (rev 11535)
+++ trunk/cgi-bin/LJ/Hooks/SUP.pm	2012-02-27 13:40:35 UTC (rev 11536)
@@ -11,6 +11,21 @@
 
 my $udp_log;
 
+LJ::register_hook('update_counter', sub {
+    my $args = shift;
+
+    my $counter = $args->{'counter'};
+    my @timers = qw/ 1 5 30 60 /;
+    foreach my $time (@timers) {
+        my $minute_number = int (time / (60 * $time));
+        my $stat_memkey = "stat:$counter:$minute_number";
+        unless (LJ::MemCache::incr($stat_memkey)) {
+            LJ::MemCache::add($stat_memkey, 1, 3600);
+        }
+    }
+
+});
+
 sub create_comment_log {
     my ($journalid, $jitemid, $jtalkid, $event) = @_;
 
@@ -325,9 +340,35 @@
 LJ::register_hook('start_request', sub{
     $LJ::SUP_REQUEST_ID = int(rand(1e9));
     @LJ::SUP_LJ_ENTRY_REQ = ();
+
+    $LJ::TIME_START_REQUEST = time;
+
     return;
 });
 
+LJ::register_hook('end_request', sub{
+
+    return unless LJ::is_web_context();
+
+    my $duration = time - $LJ::TIME_START_REQUEST;
+    my $ext = "";
+    if ($duration <= 2) {
+        $ext = "2";
+    } elsif ($duration >  2 && $duration <= 5) {
+        $ext = "2_5";
+    } elsif ($duration >  5 && $duration <= 10) {
+        $ext = "5_10";
+    } elsif ($duration > 10 && $duration <= 30) {
+        $ext = "10_30";
+    } elsif ($duration > 30) {
+        $ext = "30";
+    }
+
+    LJ::run_hook ("update_counter", {
+        counter => "request_duration_$ext",
+    });
+});
+
 LJ::register_hook('notify_event_displayed', sub{
     my $entry = shift;
     push @LJ::SUP_LJ_ENTRY_REQ, [$entry->journalid, $entry->posterid, $entry->ditemid];

Tags: gprochaev, ljcom, pm, wisest-owl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments