mirror of
https://github.com/ntop/ntopng.git
synced 2026-07-09 16:00:51 +00:00
Move ts append for additional speedtest metrics to follow the same path of other metrics. Fix servers URL parsing. Other code cleanups.
This commit is contained in:
parent
4e7028c689
commit
90e0f77f3d
6 changed files with 64 additions and 38 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 1a7d85ddee8f60f459395d68107aa72aa8e48407
|
||||
Subproject commit b09037027b4dd07e47a688519071af1b43a1b139
|
||||
|
|
@ -367,7 +367,7 @@ end
|
|||
|
||||
-- ##############################################
|
||||
|
||||
function am_utils.getAmSchemaForGranularity(granularity)
|
||||
function am_utils.getAmGranularitySuffix(granularity)
|
||||
local str_granularity
|
||||
|
||||
if (tonumber(granularity) ~= nil) then
|
||||
|
|
@ -376,7 +376,14 @@ function am_utils.getAmSchemaForGranularity(granularity)
|
|||
str_granularity = granularity
|
||||
end
|
||||
|
||||
return ("am_host:val_" .. (str_granularity or "min"))
|
||||
return str_granularity or "min"
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
||||
function am_utils.getAmSchemaForGranularity(granularity)
|
||||
local str_granularity = am_utils.getAmGranularitySuffix(granularity)
|
||||
return ("am_host:val_" .. str_granularity)
|
||||
end
|
||||
|
||||
-- ##############################################
|
||||
|
|
@ -914,6 +921,7 @@ end
|
|||
function am_utils.run_am_check(when, all_hosts, granularity)
|
||||
local hosts_am = {}
|
||||
local resolved_unreachable_hosts = {}
|
||||
local str_granularity = am_utils.getAmGranularitySuffix(granularity)
|
||||
local am_schema = am_utils.getAmSchemaForGranularity(granularity)
|
||||
|
||||
when = when - (when % 60)
|
||||
|
|
@ -1005,6 +1013,31 @@ function am_utils.run_am_check(when, all_hosts, granularity)
|
|||
end
|
||||
|
||||
ts_utils.append(am_schema, ts_data, when)
|
||||
|
||||
-- Write additional timeseries (e.g. speedtest upload/latency)
|
||||
if info.upload_speed ~= nil then
|
||||
local _am_schema = "am_host:upload_" .. str_granularity
|
||||
|
||||
ts_data = {
|
||||
ifid = getSystemInterfaceId(),
|
||||
host = host.host,
|
||||
speed = info.upload_speed * 1000000 / 8
|
||||
}
|
||||
|
||||
ts_utils.append(_am_schema, ts_data, when)
|
||||
end
|
||||
|
||||
if info.latency ~= nil then
|
||||
local _am_schema = "am_host:latency_" .. str_granularity
|
||||
|
||||
ts_data = {
|
||||
ifid = getSystemInterfaceId(),
|
||||
host = host.host,
|
||||
latency = info.latency
|
||||
}
|
||||
|
||||
ts_utils.append(_am_schema, ts_data, when)
|
||||
end
|
||||
end
|
||||
|
||||
am_utils.setLastAmUpdate(key, when, host_value, resolved_host, jitter, mean)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ local json = require("dkjson")
|
|||
local ts_utils = require("ts_utils_core")
|
||||
local format_utils = require("format_utils")
|
||||
|
||||
local do_trace = false
|
||||
local collected_results = {}
|
||||
|
||||
-- #################################################################
|
||||
|
|
@ -19,11 +18,7 @@ local collected_results = {}
|
|||
-- see (am_utils.key2host for the details on such format).
|
||||
local function run_speedtest(hosts, granularity)
|
||||
local rsp
|
||||
local do_trace = ntop.getCache("ntopng.prefs.trace.active_monitoring")
|
||||
|
||||
if isEmptyString(do_trace) then
|
||||
do_trace = false
|
||||
end
|
||||
local do_trace = toboolean(ntop.getCache("ntopng.prefs.trace.active_monitoring"))
|
||||
|
||||
if (do_trace) then
|
||||
tprint("[run_speedtest] [" .. granularity .. "]\n")
|
||||
|
|
@ -61,25 +56,11 @@ local function run_speedtest(hosts, granularity)
|
|||
|
||||
collected_results[key] = {
|
||||
value = download_mbit * 1000000 / 8,
|
||||
resolved_addr = isp
|
||||
resolved_addr = isp,
|
||||
upload_speed = rsp["upload.speed"],
|
||||
latency = rsp["server.latency"]
|
||||
}
|
||||
end
|
||||
|
||||
if (rsp["upload.speed"]) then
|
||||
ts_utils.append("am_host:upload_" .. granularity, {
|
||||
ifid = getSystemInterfaceId(),
|
||||
speed = rsp["upload.speed"] * 1000000 / 8,
|
||||
host = host.host
|
||||
})
|
||||
end
|
||||
|
||||
if (rsp["server.latency"]) then
|
||||
ts_utils.append("am_host:latency_" .. granularity, {
|
||||
ifid = getSystemInterfaceId(),
|
||||
latency = rsp["server.latency"],
|
||||
host = host.host
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ local ifname = _POST["ifname"]
|
|||
local threshold = _POST["threshold"]
|
||||
local granularity = _POST["granularity"]
|
||||
|
||||
tprint(action)
|
||||
|
||||
local res = {}
|
||||
local rc = rest_utils.consts.success.ok
|
||||
|
||||
|
|
@ -85,4 +83,4 @@ end
|
|||
|
||||
-- ################################################
|
||||
|
||||
rest_utils.answer(rc, res)
|
||||
rest_utils.answer(rc, res)
|
||||
|
|
|
|||
2
third-party/clickhouse-cpp
vendored
2
third-party/clickhouse-cpp
vendored
|
|
@ -1 +1 @@
|
|||
Subproject commit 7110cb75469915ca5f233eab451351bf877d5846
|
||||
Subproject commit 506248dd049318226805b99ddaf873008762bef4
|
||||
30
third-party/speedtest.c
vendored
30
third-party/speedtest.c
vendored
|
|
@ -908,6 +908,8 @@ static int get_best_server(int *p_index)
|
|||
|
||||
for (i = 0; i < MAX_CLOSEST_SERVER_NUM; i++) {
|
||||
double latency;
|
||||
char *p;
|
||||
size_t len;
|
||||
|
||||
if (minimum != DBL_MAX && i >= MIN_SERVERS_TO_CHECK)
|
||||
break; /* MIN_SERVERS_TO_CHECK evaluated and at least one found */
|
||||
|
|
@ -915,10 +917,15 @@ static int get_best_server(int *p_index)
|
|||
if((strlen(servers[i].url) == 0))
|
||||
continue;
|
||||
|
||||
sscanf(servers[i].url, "http://%[^/]speedtest/upload.%*s", server);
|
||||
if(server[0] == '\0')
|
||||
sscanf(servers[i].url, "https://%[^/]speedtest/upload.%*s", server);
|
||||
|
||||
/* Read base URL (e.g. http://speedtest1.uniconnect.it:8080) by removing /speedtest/.. */
|
||||
p = strstr(servers[i].url, "/speedtest/");
|
||||
server[0] = '\0';
|
||||
if(p == NULL) continue;
|
||||
len = (size_t)(p - servers[i].url);
|
||||
if(len == 0 || len >= URL_LENGTH_MAX) continue;
|
||||
strncpy(server, servers[i].url, len);
|
||||
server[len] = '\0';
|
||||
|
||||
if(server[0] == '\0')
|
||||
continue;
|
||||
|
||||
|
|
@ -954,6 +961,7 @@ json_object* speedtest() {
|
|||
double speed, download_speed;
|
||||
int dsize, sindex;
|
||||
json_object *rc = json_object_new_object();
|
||||
char *p;
|
||||
|
||||
if(rc == NULL) {
|
||||
#ifdef INFO_SPEEDTEST
|
||||
|
|
@ -998,10 +1006,16 @@ json_object* speedtest() {
|
|||
return(rc);
|
||||
}
|
||||
|
||||
sscanf(servers[sindex].url, "http://%[^/]/speedtest/upload.%4s", server_url, ext);
|
||||
|
||||
if(server_url[0] == '\0')
|
||||
sscanf(servers[sindex].url, "https://%[^/]/speedtest/upload.%4s", server_url, ext);
|
||||
/* Read base URL and upload extension */
|
||||
p = strstr(servers[sindex].url, "/speedtest/upload.");
|
||||
if (p != NULL) {
|
||||
size_t len = (size_t)(p - servers[sindex].url);
|
||||
if(len > 0 && len < URL_LENGTH_MAX) {
|
||||
strncpy(server_url, servers[sindex].url, len);
|
||||
server_url[len] = '\0';
|
||||
sscanf(p, "/speedtest/upload.%4s", ext);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_SPEEDTEST
|
||||
printf("Best server: %s (%0.2fKM) [index: %u][%s]\n",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue