Skip to content
Snippets Groups Projects
Commit a4e156f4 authored by David Schmitz's avatar David Schmitz
Browse files

fix/wrong_ratelimit_stats: fix broken snmp updates; fix for too verbose snmp...

fix/wrong_ratelimit_stats: fix broken snmp updates; fix for too verbose snmp updates; fix for support of matched vs. dropped packets
parent cb35a56b
No related branches found
No related tags found
No related merge requests found
...@@ -43,7 +43,7 @@ def snmpCallback(snmpEngine, sendRequestHandle, errorIndication, ...@@ -43,7 +43,7 @@ def snmpCallback(snmpEngine, sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBindTable, cbCtx): errorStatus, errorIndex, varBindTable, cbCtx):
try: try:
(authData, transportTarget, results) = cbCtx (authData, transportTarget, results) = cbCtx
logger.error('snmpCallback(): called') #logger.info('snmpCallback(): called {}'.format(transportTarget))
# debug - which router replies: # debug - which router replies:
#print('%s via %s' % (authData, transportTarget)) #print('%s via %s' % (authData, transportTarget))
...@@ -71,7 +71,7 @@ def snmpCallback(snmpEngine, sendRequestHandle, errorIndication, ...@@ -71,7 +71,7 @@ def snmpCallback(snmpEngine, sendRequestHandle, errorIndication,
logger.debug('snmpCallback(): Finished {}.'.format(transportTarget)) logger.debug('snmpCallback(): Finished {}.'.format(transportTarget))
return 0 return 0
last_snmp_var_got__from__transportTarget__hash[tabstoptr(transportTarget)]=name last_snmp_var_got__from__transportTarget__hash[str(transportTarget)]=name
ident = name[identoffset:] ident = name[identoffset:]
ordvals = [int(i) for i in ident.split(".")] ordvals = [int(i) for i in ident.split(".")]
...@@ -84,13 +84,13 @@ def snmpCallback(snmpEngine, sendRequestHandle, errorIndication, ...@@ -84,13 +84,13 @@ def snmpCallback(snmpEngine, sendRequestHandle, errorIndication,
len2 = ordvals[len1] + 1 len2 = ordvals[len1] + 1
routename = "".join([chr(i) for i in ordvals[len1 + 1:len1 + len2]]) routename = "".join([chr(i) for i in ordvals[len1 + 1:len1 + len2]])
logger.error("routename="+str(routename)) #logger.info("routename="+str(routename))
xtype='counter' xtype='counter'
if re.match(r'^[0-9]+[Mk]_', routename): if re.match(r'^[0-9]+[MmKk]_', routename):
ary=re.split(r'_', routename, maxsplit=1) ary=re.split(r'_', routename, maxsplit=1)
xtype=ary[0] xtype=ary[0]
routename=ary[1] routename=ary[1]
logger.error("=> routename="+str(routename)+" xtype="+str(xtype)) #logger.info("=> routename="+str(routename)+" xtype="+str(xtype))
# add value into dict # add value into dict
if routename in results: if routename in results:
...@@ -271,7 +271,7 @@ def helper_get_countertype_of_rule(ruleobj): ...@@ -271,7 +271,7 @@ def helper_get_countertype_of_rule(ruleobj):
for thenaction in ruleobj.then.all(): for thenaction in ruleobj.then.all():
if thenaction.action and thenaction.action=='rate-limit': if thenaction.action and thenaction.action=='rate-limit':
limit_rate=thenaction.action_value limit_rate=thenaction.action_value
xtype=str(limit_rate) xtype=str(limit_rate).upper()
return xtype return xtype
# #
...@@ -398,8 +398,8 @@ def poll_snmp_statistics(): ...@@ -398,8 +398,8 @@ def poll_snmp_statistics():
counter_null = {"ts": rule_last_updated.isoformat(), "value": null_measurement } counter_null = {"ts": rule_last_updated.isoformat(), "value": null_measurement }
counter_zero = {"ts": rule_last_updated.isoformat(), "value": zero_measurement } counter_zero = {"ts": rule_last_updated.isoformat(), "value": zero_measurement }
else: else:
counter_null = {"ts": rule_last_updated.isoformat(), "value": null_measurement, "value_dropped": null_measurement } counter_null = {"ts": rule_last_updated.isoformat(), "value": null_measurement, "value_matched": null_measurement }
counter_zero = {"ts": rule_last_updated.isoformat(), "value": zero_measurement, "value_dropped": zero_measurement } counter_zero = {"ts": rule_last_updated.isoformat(), "value": zero_measurement, "value_matched": zero_measurement }
#logger.info("snmpstats: STATISTICS_PER_RULE ruleobj="+str(ruleobj)) #logger.info("snmpstats: STATISTICS_PER_RULE ruleobj="+str(ruleobj))
#logger.info("snmpstats: STATISTICS_PER_RULE ruleobj.type="+str(type(ruleobj))) #logger.info("snmpstats: STATISTICS_PER_RULE ruleobj.type="+str(type(ruleobj)))
...@@ -416,14 +416,14 @@ def poll_snmp_statistics(): ...@@ -416,14 +416,14 @@ def poll_snmp_statistics():
else: else:
logger.info("poll_snmp_statistics(): 1b STATISTICS_PER_RULE rule_id="+str(rule_id)) logger.info("poll_snmp_statistics(): 1b STATISTICS_PER_RULE rule_id="+str(rule_id))
try: try:
val1 = newdata[flowspec_params_str][xtype_default] val_dropped = newdata[flowspec_params_str][xtype_default]
except Exception: except Exception:
val1 = 1 val_dropped = 1
try: try:
val2 = newdata[flowspec_params_str][xtype] val_matched = newdata[flowspec_params_str][xtype]
except Exception: except Exception:
val2 = 1 val_matched = 1
counter = {"ts": nowstr, "value": val1, "value_dropped": val2} counter = { "ts": nowstr, "value": val_dropped, "value_matched": val_matched }
counter_is_null = False counter_is_null = False
except Exception as e: except Exception as e:
...@@ -536,7 +536,7 @@ def add_initial_zero_value(rule_id, route_obj, zero_or_null=True): ...@@ -536,7 +536,7 @@ def add_initial_zero_value(rule_id, route_obj, zero_or_null=True):
if xtype==xtype_default: if xtype==xtype_default:
counter = {"ts": nowstr, "value": zero_measurement } counter = {"ts": nowstr, "value": zero_measurement }
else: else:
counter = {"ts": nowstr, "value": zero_measurement, "value_dropped": zero_measurement } counter = {"ts": nowstr, "value": zero_measurement, "value_matched": zero_measurement }
samplecount = settings.SNMP_MAX_SAMPLECOUNT samplecount = settings.SNMP_MAX_SAMPLECOUNT
......
...@@ -152,12 +152,12 @@ function plotGraph(route_then_action, data) ...@@ -152,12 +152,12 @@ function plotGraph(route_then_action, data)
var ybytesdata = Array(); var ybytesdata = Array();
var ybytesdatarel = Array(); var ybytesdatarel = Array();
var ydroppedpkgdata = Array(); var ymatchedpkgdata = Array();
var ydroppedpkgdatarel = Array(); var ymatchedpkgdatarel = Array();
var ydroppedbytesdata = Array(); var ymatchedbytesdata = Array();
var ydroppedbytesdatarel = Array(); var ymatchedbytesdatarel = Array();
var ydropped_available = false; var ymatched_available = false;
for (i=0; i<data["data"].length; i++) { for (i=0; i<data["data"].length; i++) {
var d = data["data"][data["data"].length - 1 - i]; var d = data["data"][data["data"].length - 1 - i];
...@@ -178,21 +178,29 @@ function plotGraph(route_then_action, data) ...@@ -178,21 +178,29 @@ function plotGraph(route_then_action, data)
ybytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0; ybytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0;
} }
if (d.value_dropped!=undefined) { if (d.value_matched!=undefined) {
ydropped_available=true ymatched_available=true
ymatched_packets = d.value_matched.packets;
ymatched_bytes = d.value_matched.bytes;
} else if (d.value_dropped!=undefined) { // support for ".value_dropped" which actually really effectively was matched bytes/packets (as having been wrongly used/named, and which was in use for a short time in 2024-02)
ymatched_available=true
ymatched_packets = d.value_dropped.packets;
ymatched_bytes = d.value_dropped.bytes;
}
ydroppedpkgdata[i] = d.value_dropped.packets; if (ymatched_available) {
ydroppedbytesdata[i] = d.value_dropped.bytes; ymatchedpkgdata[i] = ymatched_packets;
ymatchedbytesdata[i] = ymatched_bytes;
if (i == 0) { if (i == 0) {
ydroppedpkgdatarel[i] = 0; ymatchedpkgdatarel[i] = 0;
ydroppedbytesdatarel[i] = 0; ymatchedbytesdatarel[i] = 0;
} else { } else {
delta = (ydroppedpkgdata[i]===undefined) ? undefined : (ydroppedpkgdata[i-1]===undefined) ? ydroppedpkgdata[i] : (ydroppedpkgdata[i] - ydroppedpkgdata[i-1]); delta = (ymatchedpkgdata[i]===undefined) ? undefined : (ymatchedpkgdata[i-1]===undefined) ? ymatchedpkgdata[i] : (ymatchedpkgdata[i] - ymatchedpkgdata[i-1]);
ydroppedpkgdatarel[i] = (delta===undefined || delta>=0) ? delta : 0; ymatchedpkgdatarel[i] = (delta===undefined || delta>=0) ? delta : 0;
bytesdelta = (ydroppedbytesdata[i]===undefined) ? undefined : (ydroppedbytesdata[i-1]===undefined) ? ydroppedbytesdata[i] : (ydroppedbytesdata[i] - ydroppedbytesdata[i-1]); bytesdelta = (ymatchedbytesdata[i]===undefined) ? undefined : (ymatchedbytesdata[i-1]===undefined) ? ymatchedbytesdata[i] : (ymatchedbytesdata[i] - ymatchedbytesdata[i-1]);
ydroppedbytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0; ymatchedbytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0;
} }
...@@ -228,24 +236,24 @@ function plotGraph(route_then_action, data) ...@@ -228,24 +236,24 @@ function plotGraph(route_then_action, data)
if (is_drop_rule) { if (is_drop_rule) {
matched_text = "matched and dropped"; dropped_text = "matched and dropped";
value1__borderColor = drop__borderColor; value1__borderColor = drop__borderColor;
value1__pointbackgroundColor = drop__pointbackgroundColor; value1__pointbackgroundColor = drop__pointbackgroundColor;
value1__backgroundColor = drop__backgroundColor; value1__backgroundColor = drop__backgroundColor;
} else if (is_accept_rule) { } else if (is_accept_rule) {
matched_text = "matched and accepted"; dropped_text = "matched and accepted";
value1__borderColor = accept__borderColor; value1__borderColor = accept__borderColor;
value1__pointbackgroundColor = accept__pointbackgroundColor; value1__pointbackgroundColor = accept__pointbackgroundColor;
value1__backgroundColor = accept__backgroundColor; value1__backgroundColor = accept__backgroundColor;
} else { } else {
matched_text = "matched"; dropped_text = "dropped";
value1__borderColor = matched__borderColor; value1__borderColor = drop__borderColor;
value1__pointbackgroundColor = matched__pointbackgroundColor; value1__pointbackgroundColor = drop__pointbackgroundColor;
value1__backgroundColor = matched__backgroundColor; value1__backgroundColor = drop__backgroundColor;
} }
var ypkg_datasets = [{ var ypkg_datasets = [{
label: '# packets '+matched_text, label: '# packets '+dropped_text,
data: ypkgdata, data: ypkgdata,
borderWidth: 2, borderWidth: 2,
borderColor: value1__borderColor, borderColor: value1__borderColor,
...@@ -256,7 +264,7 @@ function plotGraph(route_then_action, data) ...@@ -256,7 +264,7 @@ function plotGraph(route_then_action, data)
//backgroundColor: "#99bfff" //backgroundColor: "#99bfff"
}]; }];
var ypkgrel_datasets = [{ var ypkgrel_datasets = [{
label: '# packets '+matched_text, label: '# packets '+dropped_text,
data: ypkgdatarel, data: ypkgdatarel,
borderWidth: 2, borderWidth: 2,
borderColor: value1__borderColor, borderColor: value1__borderColor,
...@@ -267,7 +275,7 @@ function plotGraph(route_then_action, data) ...@@ -267,7 +275,7 @@ function plotGraph(route_then_action, data)
//backgroundColor: "#ff877a" //backgroundColor: "#ff877a"
}]; }];
var ybytes_datasets = [{ var ybytes_datasets = [{
label: '# bytes '+matched_text, label: '# bytes '+dropped_text,
data: ybytesdata, data: ybytesdata,
borderWidth: 2, borderWidth: 2,
borderColor: value1__borderColor, borderColor: value1__borderColor,
...@@ -278,7 +286,7 @@ function plotGraph(route_then_action, data) ...@@ -278,7 +286,7 @@ function plotGraph(route_then_action, data)
//backgroundColor: "#99bfff" //backgroundColor: "#99bfff"
}]; }];
var ybytesrel_datasets = [{ var ybytesrel_datasets = [{
label: '# bytes '+matched_text, label: '# bytes '+dropped_text,
data: ybytesdatarel, data: ybytesdatarel,
borderWidth: 2, borderWidth: 2,
borderColor: value1__borderColor, borderColor: value1__borderColor,
...@@ -290,38 +298,38 @@ function plotGraph(route_then_action, data) ...@@ -290,38 +298,38 @@ function plotGraph(route_then_action, data)
}]; }];
if (ydropped_available) { if (ymatched_available) {
ypkg_datasets.push({ ypkg_datasets.push({
label: '# packets dropped', label: '# packets matched',
data: ydroppedpkgdata, data: ymatchedpkgdata,
borderWidth: 2, borderWidth: 2,
borderColor: drop__borderColor, borderColor: matched__borderColor,
pointBackgroundColor: drop__pointbackgroundColor, pointBackgroundColor: matched__pointbackgroundColor,
backgroundColor: drop__backgroundColor backgroundColor: matched__backgroundColor
}); });
ypkgrel_datasets.push({ ypkgrel_datasets.push({
label: '# packets dropped', label: '# packets matched',
data: ydroppedpkgdatarel, data: ymatchedpkgdatarel,
borderWidth: 2, borderWidth: 2,
borderColor: drop__borderColor, borderColor: matched__borderColor,
pointBackgroundColor: drop__pointbackgroundColor, pointBackgroundColor: matched__pointbackgroundColor,
backgroundColor: drop__backgroundColor backgroundColor: matched__backgroundColor
}); });
ybytes_datasets.push({ ybytes_datasets.push({
label: '# bytes dropped', label: '# bytes matched',
data: ydroppedbytesdata, data: ymatchedbytesdata,
borderWidth: 2, borderWidth: 2,
borderColor: drop__borderColor, borderColor: matched__borderColor,
pointBackgroundColor: drop__pointbackgroundColor, pointBackgroundColor: matched__pointbackgroundColor,
backgroundColor: drop__backgroundColor backgroundColor: matched__backgroundColor
}); });
ybytesrel_datasets.push({ ybytesrel_datasets.push({
label: '# bytes dropped', label: '# bytes matched',
data: ydroppedbytesdatarel, data: ymatchedbytesdatarel,
borderWidth: 2, borderWidth: 2,
borderColor: drop__borderColor, borderColor: matched__borderColor,
pointBackgroundColor: drop__pointbackgroundColor, pointBackgroundColor: matched__pointbackgroundColor,
backgroundColor: drop__backgroundColor backgroundColor: matched__backgroundColor
}); });
} }
......
...@@ -948,8 +948,10 @@ elif [ "$1" = "--process_ruleinfo" ]; then #arg ...@@ -948,8 +948,10 @@ elif [ "$1" = "--process_ruleinfo" ]; then #arg
fi fi
counter_values_read="$random_value_read_bytes $random_value_read_pkgs" #counter_values_read="$random_value_read_bytes $random_value_read_pkgs"
counter_values_drop="$random_value_drop_bytes $random_value_drop_pkgs" #counter_values_drop="$random_value_drop_bytes $random_value_drop_pkgs"
counter_values_drop="$random_value_read_bytes $random_value_read_pkgs"
counter_values_read="$random_value_drop_bytes $random_value_drop_pkgs"
fi fi
## ##
......
...@@ -152,7 +152,7 @@ sub get_snmp_rulename ...@@ -152,7 +152,7 @@ sub get_snmp_rulename
if (defined($thenaction)) { if (defined($thenaction)) {
if ($thenaction eq 'discard') { if ($thenaction eq 'discard') {
} elsif ($thenaction =~ /^rate-limit-([0-9]+([Mk]?))$/) { } elsif ($thenaction =~ /^rate-limit-([0-9]+([Mk]?))$/) {
$rulename = $1."_".$rulename; $rulename = uc($1)."_".$rulename;
$counter_type_value = 3; # policer $counter_type_value = 3; # policer
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment