trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject [2/4] git commit: updated to use the local manager if a hostname is not specified
Date Fri, 04 May 2012 23:18:30 GMT
updated to use the local manager if a hostname is not specified


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/c50f37d4
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/c50f37d4
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/c50f37d4

Branch: refs/heads/master
Commit: c50f37d4f2eaa50df66b62d1d17082f20f53e2b3
Parents: d0b4853
Author: Bryan Call <bryan_call@yahoo.com>
Authored: Fri May 4 16:16:52 2012 -0700
Committer: Bryan Call <bryan_call@yahoo.com>
Committed: Fri May 4 16:16:52 2012 -0700

----------------------------------------------------------------------
 contrib/tstop/src/Makefile |    2 +-
 contrib/tstop/src/stats.h  |   95 ++++++++++++++++++++++++++------------
 contrib/tstop/src/tstop.cc |   17 ++++---
 3 files changed, 75 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c50f37d4/contrib/tstop/src/Makefile
----------------------------------------------------------------------
diff --git a/contrib/tstop/src/Makefile b/contrib/tstop/src/Makefile
index 55d8fc1..6b9a7e6 100644
--- a/contrib/tstop/src/Makefile
+++ b/contrib/tstop/src/Makefile
@@ -1,5 +1,5 @@
 all: tstop.cc
-	$(CXX) $^ -o tstop -lcurl -lcurses -g
+	$(CXX) $^ -o tstop -lcurl -lcurses -g -ltsutil -ltsmgmt -ltsutil -lpthread -Wl,-rpath,/usr/local/lib
 
 clean:
 	rm -f tstop

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c50f37d4/contrib/tstop/src/stats.h
----------------------------------------------------------------------
diff --git a/contrib/tstop/src/stats.h b/contrib/tstop/src/stats.h
index 97c63d2..c7e8c0c 100644
--- a/contrib/tstop/src/stats.h
+++ b/contrib/tstop/src/stats.h
@@ -1,6 +1,12 @@
 #include <curl/curl.h>
 #include <map>
 #include <string>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+//#include <ts/ts.h>
+#include <inttypes.h>
+#include <ts/mgmtapi.h>
 
 using namespace std;
 
@@ -134,37 +140,66 @@ public:
   }
 
   void getStats() {
-    CURL *curl;
-    CURLcode res;
 
-    if (_old_stats != NULL) {
-      delete _old_stats;
-      _old_stats = NULL;
-    }
-    _old_stats = _stats;
-    _stats = new map<string, string>;
-
-    curl = curl_easy_init();
-    if (curl) {
-      string url = "http://" + _host + "/_stats";
-      curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
-      curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
-      curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error);
-
-      // update time
-      _old_time = _now;
-      gettimeofday(&_time, NULL);
-      _now = _time.tv_sec + (double)_time.tv_usec / 1000000;
-      _time_diff = _now - _old_time;
-
-      res = curl_easy_perform(curl);
-      cout << curl_error << endl;
-      assert(res == 0);
-      /* always cleanup */ 
-      curl_easy_cleanup(curl);
-
-      // parse
-      parseResponse(response);
+    if (_host == "") {
+      int64_t value;
+      if (_old_stats != NULL) {
+        delete _old_stats;
+        _old_stats = NULL;
+      }
+      _old_stats = _stats;
+      _stats = new map<string, string>;
+
+      for (map<string, LookupItem>::const_iterator lookup_it = lookup_table.begin();
+           lookup_it != lookup_table.end(); ++lookup_it) {
+        const LookupItem &item = lookup_it->second;
+
+        if (item.type == 1 || item.type == 2 || item.type == 5 || item.type == 8) {
+          assert(TSRecordGetInt(item.name, &value) == TS_ERR_OKAY);
+          cerr << "name" << item.name << " value: " << value <<
endl;
+          string key = item.name;
+          char buffer[32];
+          sprintf(buffer, "%lld", value);
+          string foo = buffer;
+          (*_stats)[key] = foo;
+        }
+      }
+    } else {
+      CURL *curl;
+      CURLcode res;
+
+      curl = curl_easy_init();
+      if (curl) {
+        string url = "http://" + _host + "/_stats";
+        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
+        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
+        curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error);
+
+        // update time
+        gettimeofday(&_time, NULL);
+        double now = _time.tv_sec + (double)_time.tv_usec / 1000000;
+
+        res = curl_easy_perform(curl);
+
+        // only if success update stats and time information
+        if (res == 0) {
+          if (_old_stats != NULL) {
+            delete _old_stats;
+            _old_stats = NULL;
+          }
+          _old_stats = _stats;
+          _stats = new map<string, string>;
+
+          // parse
+          parseResponse(response);
+          _old_time = _now;
+          _now = now;
+          _time_diff = _now - _old_time;
+        }
+
+        /* always cleanup */ 
+        curl_easy_cleanup(curl);
+      }
     }
   }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/c50f37d4/contrib/tstop/src/tstop.cc
----------------------------------------------------------------------
diff --git a/contrib/tstop/src/tstop.cc b/contrib/tstop/src/tstop.cc
index e1556f0..3632feb 100644
--- a/contrib/tstop/src/tstop.cc
+++ b/contrib/tstop/src/tstop.cc
@@ -178,13 +178,16 @@ int main(int argc, char **argv)
       usage(argv);
     }
   }
-    
+
+  string host = "";
   if (optind >= argc) {
-    fprintf(stderr, "Error: missing hostname on command line\n");
-    usage(argv);
+    if (TS_ERR_OKAY != TSInit(NULL, static_cast<TSInitOptionT>(TS_MGMT_OPT_NO_EVENTS
| TS_MGMT_OPT_NO_SOCK_TESTS))) {
+      fprintf(stderr, "Error: missing hostname on command line or error connecting to the
local manager\n");
+      usage(argv);
+    }
+  } else {
+    host = argv[optind];
   }
-
-  string host = argv[optind];
   Stats stats(host);
 
   //cout << response;
@@ -267,7 +270,6 @@ int main(int argc, char **argv)
     response1.push_back("3xx");
     response1.push_back("4xx");
     response1.push_back("5xx");
-    //response1.push_back("response_abort");
     response1.push_back("conn_fail");
     response1.push_back("other_err");
     response1.push_back("abort");
@@ -324,9 +326,8 @@ int main(int argc, char **argv)
     makeTable(62, 17, server2, stats);
 
 
-  curs_set(0);
+    curs_set(0);
     refresh();
-//    sleep(5);
     timeout(sleep_time);
   loop:
     int x = getch();


Mime
View raw message