summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Larson <slioch@eng-140.vyatta.com>2008-02-01 14:32:25 -0800
committerMichael Larson <slioch@eng-140.vyatta.com>2008-02-01 14:32:25 -0800
commit181b7cc450cc2ad1865d5275a7a2a6b59baf01d2 (patch)
tree784c7c341ca63736f6fad983c2f7eacf92e10f64 /src
parente150f133e0b982acf67310e926bf10c143838f39 (diff)
downloadvyatta-wanloadbalance-181b7cc450cc2ad1865d5275a7a2a6b59baf01d2.tar.gz
vyatta-wanloadbalance-181b7cc450cc2ad1865d5275a7a2a6b59baf01d2.zip
init script fix. set up show commands. create output file for wan lb status and provide show status cmd.
Diffstat (limited to 'src')
-rw-r--r--src/lbdecision.cc4
-rw-r--r--src/lboutput.cc39
-rw-r--r--src/lboutput.hh4
-rw-r--r--src/loadbalance.cc4
-rw-r--r--src/loadbalance.hh2
-rw-r--r--src/main.cc11
6 files changed, 48 insertions, 16 deletions
diff --git a/src/lbdecision.cc b/src/lbdecision.cc
index 7f9fb55..0d256fb 100644
--- a/src/lbdecision.cc
+++ b/src/lbdecision.cc
@@ -207,8 +207,6 @@ LBDecision::run(LBData &lb_data)
void
LBDecision::shutdown()
{
- cout << "LBDecision::shutdown(): " << _iface_mark_coll.size() << endl;
-
char buf[20];
//then if we do, flush all
@@ -219,8 +217,6 @@ LBDecision::shutdown()
while (iter != _iface_mark_coll.end()) {
sprintf(buf,"%d",iter->second);
- cout << "LBDecision::shutdown(): removing " << buf << endl;
-
execute(string("ip rule del fwmark ") + buf);
++iter;
}
diff --git a/src/lboutput.cc b/src/lboutput.cc
index 7434446..e2ea39b 100644
--- a/src/lboutput.cc
+++ b/src/lboutput.cc
@@ -27,6 +27,7 @@
*/
#include <sys/time.h>
#include <time.h>
+#include <syslog.h>
#include <iostream>
@@ -39,15 +40,45 @@ LBOutput::write(const LBData &lbdata)
timeval tv;
gettimeofday(&tv,NULL);
+ string wlb_out = _output_path + "/wlb.out";
+ string wlb_app_out = _output_path + "/wlb_app.out";
+
+ //open file
+ FILE *fp = fopen(wlb_out.c_str(), "w");
+ if (fp == NULL) {
+ if (_debug) {
+ cerr << "Error opening output file: " << wlb_out << endl;
+ }
+ syslog(LOG_ERR, "wan_lb: error ordering output file %s", wlb_out.c_str());
+ return;
+ }
+
//dump out the health data
LBData::InterfaceHealthConstIter iter = lbdata._iface_health_coll.begin();
while (iter != lbdata._iface_health_coll.end()) {
- 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
+ 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 << endl;
+ }
+ ++iter;
+ }
+
+ string line("Interface\tStatus\tLast Success\tLast Failure\tNum Failure\n");
+ fputs(line.c_str(),fp);
+ iter = lbdata._iface_health_coll.begin();
+ 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";
+ fputs(line.c_str(),fp);
++iter;
}
+ fclose(fp);
+
//dump out the application data
LBData::LBRuleConstIter r_iter = lbdata._lb_rule_coll.begin();
diff --git a/src/lboutput.hh b/src/lboutput.hh
index 33f58bf..1ca2fde 100644
--- a/src/lboutput.hh
+++ b/src/lboutput.hh
@@ -35,7 +35,7 @@ using namespace std;
class LBOutput
{
public:
- LBOutput(bool debug) : _debug(debug) {}
+ LBOutput(bool debug, string &output_path) : _debug(debug), _output_path(output_path) {}
~LBOutput() {}
void
@@ -43,6 +43,6 @@ public:
private:
bool _debug;
-
+ string _output_path;
};
#endif //__LBOUTPUT_HH__
diff --git a/src/loadbalance.cc b/src/loadbalance.cc
index 60a793f..062807a 100644
--- a/src/loadbalance.cc
+++ b/src/loadbalance.cc
@@ -34,12 +34,12 @@ using namespace std;
/**
*
**/
-LoadBalance::LoadBalance(bool debug) :
+LoadBalance::LoadBalance(bool debug, string &output_path) :
_debug(debug),
_lbdata_factory(debug),
_ph(debug),
_decision(debug),
- _output(debug),
+ _output(debug, output_path),
_cycle_interval(5000)
{
}
diff --git a/src/loadbalance.hh b/src/loadbalance.hh
index 47fa7b5..61512ce 100644
--- a/src/loadbalance.hh
+++ b/src/loadbalance.hh
@@ -45,7 +45,7 @@ using namespace std;
class LoadBalance
{
public:
- LoadBalance(bool debug);
+ LoadBalance(bool debug, string &output_path);
~LoadBalance();
bool set_conf(const string &filename);
diff --git a/src/main.cc b/src/main.cc
index e62c6c5..362280c 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -44,6 +44,7 @@ static void usage()
cout << "-t load configuration file only and exit" << endl;
cout << "-v print debug output" << endl;
cout << "-i specify location of pid directory" << endl;
+ cout << "-o specify location of output directory" << endl;
cout << "-d run as daemon" << endl;
cout << "-h help" << endl;
@@ -73,11 +74,12 @@ int main(int argc, char* argv[])
int ch;
bool debug = false;
bool config_debug_mode = false, daemon = false;
- string pid_path;
+ string pid_path = "/var/run";
+ string output_path = "/var/load-balance";
string c_file;
//grab inputs
- while ((ch = getopt(argc, argv, "f:hti:dv")) != -1) {
+ while ((ch = getopt(argc, argv, "f:hti:o:dv")) != -1) {
switch (ch) {
case 'f':
c_file = optarg;
@@ -91,6 +93,9 @@ int main(int argc, char* argv[])
case 'i':
pid_path = optarg;
break;
+ case 'o':
+ output_path = optarg;
+ break;
case 'd':
daemon = true;
break;
@@ -120,7 +125,7 @@ int main(int argc, char* argv[])
pid_output(pid_path.c_str());
}
- g_lb = new LoadBalance(debug);
+ g_lb = new LoadBalance(debug, output_path);
bool success = g_lb->set_conf(c_file);
if (success == false) {