This is an automated email from the ASF dual-hosted git repository.
dmeden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 00ccfac196 traffic_top cleanup - remove unused curl related code.
(#11007)
00ccfac196 is described below
commit 00ccfac1967c025556db201f36d5889e5269c349
Author: Damian Meden <[email protected]>
AuthorDate: Thu Jan 25 09:26:40 2024 +0100
traffic_top cleanup - remove unused curl related code. (#11007)
This features is no longer used by traffic_top so all related code is
now gone.
---
src/traffic_top/stats.h | 131 +++++++++--------------------------------
src/traffic_top/traffic_top.cc | 17 +-----
2 files changed, 31 insertions(+), 117 deletions(-)
diff --git a/src/traffic_top/stats.h b/src/traffic_top/stats.h
index ae68c37788..0ca3f312d9 100644
--- a/src/traffic_top/stats.h
+++ b/src/traffic_top/stats.h
@@ -22,9 +22,6 @@
*/
#pragma once
-#if HAS_CURL
-#include <curl/curl.h>
-#endif
#include <map>
#include <string>
#include <sys/types.h>
@@ -50,9 +47,6 @@ struct LookupItem {
int type;
};
extern size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream);
-#if HAS_CURL
-extern char curl_error[CURL_ERROR_SIZE];
-#endif
extern std::string response;
namespace constant
@@ -83,28 +77,12 @@ class Stats
template <class Key, class T> using map = std::map<Key, T>;
public:
- Stats(const string &url) : _url(url)
+ Stats()
{
- if (url != "") {
- if (_url.substr(0, 4) != "http") {
- // looks like it is a host using it the old way
- _url = "http://" + _url + "/_stats";
- }
-
- // set the host
- size_t start = _url.find(":");
- size_t end = _url.find('/', start + 3);
- _host = _url.substr(start + 3, end - start - 3);
- end = _host.find(":");
- if (end != string::npos) {
- _host = _host.substr(0, end);
- }
- } else {
- char hostname[25];
- hostname[sizeof(hostname) - 1] = '\0';
- gethostname(hostname, sizeof(hostname) - 1);
- _host = hostname;
- }
+ char hostname[25];
+ hostname[sizeof(hostname) - 1] = '\0';
+ gethostname(hostname, sizeof(hostname) - 1);
+ _host = hostname;
_time_diff = 0;
_old_time = 0;
@@ -281,86 +259,36 @@ public:
bool
getStats()
{
- if (_url == "") {
- if (_old_stats != nullptr) {
- delete _old_stats;
- _old_stats = nullptr;
- }
- _old_stats = _stats;
- _stats = new map<string, string>;
-
- gettimeofday(&_time, nullptr);
- double now = _time.tv_sec + (double)_time.tv_usec / 1000000;
-
- // We will lookup for all the metrics on one single request.
- shared::rpc::RecordLookupRequest request;
-
- 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) {
- // Add records names to the rpc request.
- request.emplace_rec(detail::MetricParam{item.name});
- }
- }
- // query the rpc node.
- if (auto const &error = fetch_and_fill_stats(request, _stats);
!error.empty()) {
- fprintf(stderr, "Error getting stats from the RPC node:\n%s",
error.c_str());
- return false;
- }
- _old_time = _now;
- _now = now;
- _time_diff = _now - _old_time;
- } else {
-#if HAS_CURL
- CURL *curl;
- CURLcode res;
-
- curl = curl_easy_init();
- if (curl) {
- CURLcode url, function, buffer;
-
- url = curl_easy_setopt(curl, CURLOPT_URL, _url.c_str());
- function = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
- buffer = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error);
-
- if ((url | function | buffer) != CURLE_OK) {
- fprintf(stderr, "error setting curl 1 or more options. url: %d,
function: %d, buffer: %d", url, function, buffer);
- exit(1);
- }
+ if (_old_stats != nullptr) {
+ delete _old_stats;
+ _old_stats = nullptr;
+ }
+ _old_stats = _stats;
+ _stats = new map<string, string>;
- // update time
- gettimeofday(&_time, nullptr);
- double now = _time.tv_sec + (double)_time.tv_usec / 1000000;
+ gettimeofday(&_time, nullptr);
+ double now = _time.tv_sec + (double)_time.tv_usec / 1000000;
- response.clear();
- response.reserve(32768); // should hopefully be smaller then 32KB
- res = curl_easy_perform(curl);
+ // We will lookup for all the metrics on one single request.
+ shared::rpc::RecordLookupRequest request;
- // only if success update stats and time information
- if (res == 0) {
- if (_old_stats != nullptr) {
- delete _old_stats;
- _old_stats = nullptr;
- }
- _old_stats = _stats;
- _stats = new map<string, string>;
-
- // parse
- parseResponse(response);
- _old_time = _now;
- _now = now;
- _time_diff = _now - _old_time;
- } else {
- fprintf(stderr, "Can't fetch url %s\n", _url.c_str());
- exit(1);
- }
+ for (map<string, LookupItem>::const_iterator lookup_it =
lookup_table.begin(); lookup_it != lookup_table.end(); ++lookup_it) {
+ const LookupItem &item = lookup_it->second;
- /* always cleanup */
- curl_easy_cleanup(curl);
+ if (item.type == 1 || item.type == 2 || item.type == 5 || item.type ==
8) {
+ // Add records names to the rpc request.
+ request.emplace_rec(detail::MetricParam{item.name});
}
-#endif
}
+ // query the rpc node.
+ if (auto const &error = fetch_and_fill_stats(request, _stats);
!error.empty()) {
+ fprintf(stderr, "Error getting stats from the RPC node:\n%s",
error.c_str());
+ return false;
+ }
+ _old_time = _now;
+ _now = now;
+ _time_diff = _now - _old_time;
+
return true;
}
@@ -595,7 +523,6 @@ private:
map<string, string> *_stats;
map<string, string> *_old_stats;
map<string, LookupItem> lookup_table;
- string _url;
string _host;
double _old_time;
double _now;
diff --git a/src/traffic_top/traffic_top.cc b/src/traffic_top/traffic_top.cc
index 57249af2b3..a017d2248d 100644
--- a/src/traffic_top/traffic_top.cc
+++ b/src/traffic_top/traffic_top.cc
@@ -60,9 +60,6 @@
using namespace std;
-#if HAS_CURL
-char curl_error[CURL_ERROR_SIZE];
-#endif
string response;
namespace colorPair
@@ -379,17 +376,11 @@ main_stats_page(Stats &stats)
int
main(int argc, const char **argv)
{
-#if HAS_CURL
- static const char USAGE[] = "Usage: traffic_top [-s seconds]
[URL|hostname|hostname:port]";
-#else
static const char USAGE[] = "Usage: traffic_top [-s seconds]";
-#endif
int sleep_time = 6; // In seconds
bool absolute = false;
- string url;
-
- auto &version = AppVersionInfo::setup_version("traffic_top");
+ auto &version = AppVersionInfo::setup_version("traffic_top");
const ArgumentDescription argument_descriptions[] = {
{"sleep", 's', "Sets the delay between updates (in seconds)", "I",
&sleep_time, nullptr, nullptr},
@@ -404,16 +395,12 @@ main(int argc, const char **argv)
Layout::create();
if (n_file_arguments == 1) {
-#if HAS_CURL
- url = file_arguments[0];
-#else
usage(argument_descriptions, countof(argument_descriptions), USAGE);
-#endif
} else if (n_file_arguments > 1) {
usage(argument_descriptions, countof(argument_descriptions), USAGE);
}
- Stats stats(url);
+ Stats stats;
if (!stats.getStats()) {
return 2;
}