ganglia / ganglia-web

Ganglia Web Frontend
BSD 3-Clause "New" or "Revised" License
316 stars 170 forks source link

[live dashboards] Wrong colors displayed for green thresholds #248

Open docent-net opened 10 years ago

docent-net commented 10 years ago

js/tasseo.js:

       // check our thresholds and update color                                                                                                                                                                                                                                                                              
       var lastValue = datum[j][datum[j].length - 1].y;                                                                                                                                                                                                                                                                      
       var warning = metrics[j].warning;                                                                                                                                                                                                                                                                                     
       var critical = metrics[j].critical;                                                                                                                                                                                                                                                                                   
       if (critical > warning) {                                                                                                                                                                                                                                                                                             
         if (lastValue > critical) {                                                                                                                                                                                                                                                                                         
           graphs[j].series[0].color = '#d59295';                                                                                                                                                                                                                                                                            
         } else if (lastValue > warning) {                                                                                                                                                                                                                                                                                   
           graphs[j].series[0].color = '#f5cb56';                                                                                                                                                                                                                                                                            
         } else {                                                                                                                                                                                                                                                                                                            
           graphs[j].series[0].color = '#afdab1';                                                                                                                                                                                                                                                                            
         }                                                                                                                                                                                                                                                                                                                   
       } else {                                                                                                                                                                                                                                                                                                              
         if (lastValue < critical) {                                                                                                                                                                                                                                                                                         
           graphs[j].series[0].color = '#d59295';                                                                                                                                                                                                                                                                            
         } else if (lastValue < warning) {                                                                                                                                                                                                                                                                                   
           graphs[j].series[0].color = '#f5cb56';                                                                                                                                                                                                                                                                            
         } else {                                                                                                                                                                                                                                                                                                            
           graphs[j].series[0].color = '#afdab1';                                                                                                                                                                                                                                                                            
         }                                                                                                                                                                                                                                                                                                                   
       } 

So in if (critical > warning) { statement everything looks fine. But in else statement for this if the logic is broken (bad colors are inserted to those threshold values).

Instead of fixing this else statement I suggest adding replacing whole if-else statement with:

if (critical < warning) {
    _warning = warning
    warning = critical
    critical = _warning
}
 if (lastValue > critical) {                                                                                                                                                                                                                                                                                         
           graphs[j].series[0].color = '#d59295';                                                                                                                                                                                                                                                                            
         } else if (lastValue > warning) {                                                                                                                                                                                                                                                                                   
           graphs[j].series[0].color = '#f5cb56';                                                                                                                                                                                                                                                                            
         } else {                                                                                                                                                                                                                                                                                                            
           graphs[j].series[0].color = '#afdab1';                                                                                                                                                                                                                                                                            
         }           

This way we are not doubling the logic needed for handling this color - managing statement