diff options
author | Michael Larson <slioch@eng-140.vyatta.com> | 2008-02-01 17:32:08 -0800 |
---|---|---|
committer | Michael Larson <slioch@eng-140.vyatta.com> | 2008-02-01 17:32:08 -0800 |
commit | e357cbea7769efed1fe897dd800507bc55a15231 (patch) | |
tree | 1fb9b454d8b8167188c94a9de0bfb947f66f4e55 /src | |
parent | 181b7cc450cc2ad1865d5275a7a2a6b59baf01d2 (diff) | |
download | vyatta-wanloadbalance-e357cbea7769efed1fe897dd800507bc55a15231.tar.gz vyatta-wanloadbalance-e357cbea7769efed1fe897dd800507bc55a15231.zip |
processing added to compute elapsed time in pretty output format for show commands. time since last failure/success per
interface.
Diffstat (limited to 'src')
-rw-r--r-- | src/lbdata.hh | 14 | ||||
-rw-r--r-- | src/lboutput.cc | 106 |
2 files changed, 108 insertions, 12 deletions
diff --git a/src/lbdata.hh b/src/lbdata.hh index 6d5c5af..012d377 100644 --- a/src/lbdata.hh +++ b/src/lbdata.hh @@ -88,15 +88,19 @@ class LBHealth { _ping_resp_time(0), _hresults(10), _is_active(true), - _state_changed(true), - _last_success(0), - _last_failure(0) + _state_changed(true) {} void put(int rtt); bool - state_changed() {return _state_changed;} + state_changed() const {return _state_changed;} + + unsigned long + last_success() const {return _hresults._last_success;} + + unsigned long + last_failure() const {return _hresults._last_failure;} int _success_ct; int _failure_ct; @@ -105,8 +109,6 @@ class LBHealth { LBHealthHistory _hresults; bool _is_active; bool _state_changed; - unsigned long _last_success; - unsigned long _last_failure; }; diff --git a/src/lboutput.cc b/src/lboutput.cc index e2ea39b..3ab2bdf 100644 --- a/src/lboutput.cc +++ b/src/lboutput.cc @@ -59,8 +59,8 @@ LBOutput::write(const LBData &lbdata) if (_debug) { cout << iter->first << " "; //interface cout << string(iter->second._is_active ? "true" : "false") << " "; //status - cout << tv.tv_sec - iter->second._last_success << " "; //last success - cout << tv.tv_sec - iter->second._last_failure << " "; //last failure + cout << tv.tv_sec - iter->second.last_success() << " "; //last success + cout << tv.tv_sec - iter->second.last_failure() << " "; //last failure cout << endl; } ++iter; @@ -69,11 +69,105 @@ LBOutput::write(const LBData &lbdata) string line("Interface\tStatus\tLast Success\tLast Failure\tNum Failure\n"); fputs(line.c_str(),fp); iter = lbdata._iface_health_coll.begin(); + + timeval cur_t; + gettimeofday(&cur_t,NULL); + while (iter != lbdata._iface_health_coll.end()) { - char buf1[256],buf2[256]; - sprintf(buf1,"%ld",iter->second._last_success); - sprintf(buf2,"%ld",iter->second._last_failure); - line = string(iter->first) + "\t" + string(iter->second._is_active?"true":"false") + "\t" + buf1 + "\t" + buf2 + "\n"; + line = string(iter->first) + "\t\t" + string(iter->second._is_active?"active":"failed") + "\t"; + char btmp[256]; + string time_buf; + + unsigned long diff_t; + if (iter->second.last_success() > 0) { + diff_t = cur_t.tv_sec - iter->second.last_success(); + } + else { + diff_t = 0; + } + + unsigned long days,hours,mins,secs; + + days = diff_t / (60*60*24); + diff_t -= days * (60*60*24); + if (days > 0) { + sprintf(btmp,"%ld",days); + time_buf += string(btmp) + "d"; + } + + hours = diff_t / (60*60); + diff_t -= hours * (60*60); + if (hours > 0) { + sprintf(btmp,"%ld",hours); + time_buf += string(btmp) + "h"; + } + + mins = diff_t / (60); + diff_t -= mins * (60); + if (mins > 0) { + sprintf(btmp,"%ld",mins); + time_buf += string(btmp) + "m"; + } + + secs = diff_t; + if (secs > 0) { + sprintf(btmp,"%ld",secs); + time_buf += string(btmp) + "s"; + } + + if (time_buf.empty() == true) { + line += string("0s") + string("\t\t"); + } + else { + line += time_buf + string("\t"); + } + + time_buf = ""; + + if (iter->second.last_success() > 0) { + diff_t = cur_t.tv_sec - iter->second.last_failure(); + } + else { + diff_t = 0; + } + + days = diff_t / (60*60*24); + diff_t -= days * (60*60*24); + if (days > 0) { + sprintf(btmp,"%ld",days); + time_buf += string(btmp) + "d"; + } + + hours = diff_t / (60*60); + diff_t -= hours * (60*60); + if (hours > 0) { + sprintf(btmp,"%ld",hours); + time_buf += string(btmp) + "h"; + } + + mins = diff_t / (60); + diff_t -= mins * (60); + if (mins > 0) { + sprintf(btmp,"%ld",mins); + time_buf += string(btmp) + "m"; + } + + secs = diff_t; + if (secs > 0) { + sprintf(btmp,"%ld",secs); + time_buf += string(btmp) + "s"; + } + + if (time_buf.empty() == true) { + line += string("0s") + string("\t\t"); + } + else { + line += time_buf + string("\t"); + } + + + line += "\n"; + fputs(line.c_str(),fp); ++iter; } |