aboutsummaryrefslogblamecommitdiff
path: root/static/assets/js/monitor.js
blob: 3a670c361adff42d6a6ab3537f666c373d1c7749 (plain) (tree)


























































                                                                     


                                             




                                          




                                                                      
                          
                                                                                    

 

                                                                


                                                     
                                   
                                





                                              




                                                               





                                                
                                   
                                  
                         







                                                 
                                   








                                                                                                   

                                        


                         
                                   
                                         
                                          
     


                                       





                                                                                             
         






                                     







                                                     















                                                                                  
         

            



                                                                            



























                                                                                        
         
     



                                                     
                     

                                                                        







                                                                         

                                                   
                                   
 
                                                       
                                                  

                                             













                                                                                        
                                                     

                                                                          



                                                                


                                
                                                              

                          
                                         
                                  
                       

                                        
 

                    

                                     
                                                                                   


                                               



                                                  
                                                                                 


















                                                                                         



























































































                                                                                                    


















                                                                                 
var ajax_site = 'ajax';
var refresh_rate = 3000;
var send_timeout = 20000;
var retry_rate = 3000;

function Blocker(sleeper) {
    this.counter = 0;
    this.waiting = false;
    this.sleeper = sleeper;
}

Blocker.prototype.setHook = function() {
    var blocker = this;
    return function() {
        blocker.counter++;
    }
}
Blocker.prototype.setNotifier = function(cb) {
    var blocker = this;
    return function() {
        cb.apply(this, arguments);
        if (--blocker.counter == 0 && blocker.waiting)
            blocker.sleeper();
    }
};

Blocker.prototype.go = function() {
    if (this.counter == 0)
        this.sleeper();
    this.waiting = true;
}

function send_request(on_success) {
    $.ajax({
            url: ajax_site,
            type: 'GET',
            cache: false,
            dataType: 'json',
            async: true,
            success: on_success,
            timeout: send_timeout,
            error: function(a, b, c) {
                console.log("failed while connecting, reason: " + b);
                setTimeout(function() {
                        send_request(on_success);
                }, retry_rate);
            }
    });
}

function hex(x) {
    return ("0" + parseInt(x).toString(16)).slice(-2);
}

function random_range(min, max) {
    return Math.random() * (max - min) + min;
}

function random_color() {
    var r = (random_range(0, 200) + 150) / 2;
    var g = (random_range(0, 200) + 150) / 2;
    var b = (random_range(0, 200) + 150) / 2;
    return "#" + hex(r) + hex(g) + hex(b);
}

function LineGraph() {}

LineGraph.prototype.recalc_y