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

fix/wrong_ratelimit_stats: fix random values for vnet; change internal storage...

fix/wrong_ratelimit_stats: fix random values for vnet; change internal storage key for rate-limited matched counter to be compatible to missing values in the older FoD versions; improved color encoding of the graphs
parent cf5695dd
Branches
Tags
No related merge requests found
...@@ -372,8 +372,8 @@ def poll_snmp_statistics(): ...@@ -372,8 +372,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_counter": null_measurement } counter_null = {"ts": rule_last_updated.isoformat(), "value": null_measurement, "value_dropped": null_measurement }
counter_zero = {"ts": rule_last_updated.isoformat(), "value": zero_measurement, "value_counter": zero_measurement } counter_zero = {"ts": rule_last_updated.isoformat(), "value": zero_measurement, "value_dropped": 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)))
...@@ -385,9 +385,9 @@ def poll_snmp_statistics(): ...@@ -385,9 +385,9 @@ def poll_snmp_statistics():
if rule_status=="ACTIVE": if rule_status=="ACTIVE":
try: try:
if xtype==xtype_default: if xtype==xtype_default:
counter = {"ts": nowstr, "value": newdata[flowspec_params_str][xtype]} counter = {"ts": nowstr, "value": newdata[flowspec_params_str][xtype_default]}
else: else:
counter = {"ts": nowstr, "value": newdata[flowspec_params_str][xtype], "value_counter": newdata[flowspec_params_str][xtype_default]} counter = {"ts": nowstr, "value": newdata[flowspec_params_str][xtype_default], "value_dropped": newdata[flowspec_params_str][xtype]}
counter_is_null = False counter_is_null = False
except Exception as e: except Exception as e:
...@@ -499,7 +499,7 @@ def add_initial_zero_value(rule_id, route_obj, zero_or_null=True): ...@@ -499,7 +499,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_counter": zero_measurement } counter = {"ts": nowstr, "value": zero_measurement, "value_dropped": zero_measurement }
samplecount = settings.SNMP_MAX_SAMPLECOUNT samplecount = settings.SNMP_MAX_SAMPLECOUNT
......
...@@ -137,8 +137,14 @@ function myreloadPage() { ...@@ -137,8 +137,14 @@ function myreloadPage() {
<script src="{% static 'js/chartjs/chartjs-plugin-zoom.min.js' %}"></script> <script src="{% static 'js/chartjs/chartjs-plugin-zoom.min.js' %}"></script>
<script type="text/javascript"> <script type="text/javascript">
function plotGraph(data) function plotGraph(route_then_action, data)
{ {
var is_rate_limiting_rule = route_then_action.includes("rate-limit");
var is_drop_rule = route_then_action.includes("discard") || route_then_action.includes("drop");
var is_accept_rule = route_then_action.includes("accept");
//
var xdata = Array(); var xdata = Array();
var ypkgdata = Array(); var ypkgdata = Array();
...@@ -146,12 +152,12 @@ function plotGraph(data) ...@@ -146,12 +152,12 @@ function plotGraph(data)
var ybytesdata = Array(); var ybytesdata = Array();
var ybytesdatarel = Array(); var ybytesdatarel = Array();
var yseenpkgdata = Array(); var ydroppedpkgdata = Array();
var yseenpkgdatarel = Array(); var ydroppedpkgdatarel = Array();
var yseenbytesdata = Array(); var ydroppedbytesdata = Array();
var yseenbytesdatarel = Array(); var ydroppedbytesdatarel = Array();
var yseen_available = false; var ydropped_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];
...@@ -172,21 +178,21 @@ function plotGraph(data) ...@@ -172,21 +178,21 @@ function plotGraph(data)
ybytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0; ybytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0;
} }
if (d.value_counter!=undefined) { if (d.value_dropped!=undefined) {
yseen_available=true ydropped_available=true
yseenpkgdata[i] = d.value_counter.packets; ydroppedpkgdata[i] = d.value_dropped.packets;
yseenbytesdata[i] = d.value_counter.bytes; ydroppedbytesdata[i] = d.value_dropped.bytes;
if (i == 0) { if (i == 0) {
yseenpkgdatarel[i] = 0; ydroppedpkgdatarel[i] = 0;
yseenbytesdatarel[i] = 0; ydroppedbytesdatarel[i] = 0;
} else { } else {
delta = (yseenpkgdata[i]===undefined) ? undefined : (yseenpkgdata[i-1]===undefined) ? yseenpkgdata[i] : (yseenpkgdata[i] - yseenpkgdata[i-1]); delta = (ydroppedpkgdata[i]===undefined) ? undefined : (ydroppedpkgdata[i-1]===undefined) ? ydroppedpkgdata[i] : (ydroppedpkgdata[i] - ydroppedpkgdata[i-1]);
yseenpkgdatarel[i] = (delta===undefined || delta>=0) ? delta : 0; ydroppedpkgdatarel[i] = (delta===undefined || delta>=0) ? delta : 0;
bytesdelta = (yseenbytesdata[i]===undefined) ? undefined : (yseenbytesdata[i-1]===undefined) ? yseenbytesdata[i] : (yseenbytesdata[i] - yseenbytesdata[i-1]); bytesdelta = (ydroppedbytesdata[i]===undefined) ? undefined : (ydroppedbytesdata[i-1]===undefined) ? ydroppedbytesdata[i] : (ydroppedbytesdata[i] - ydroppedbytesdata[i-1]);
yseenbytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0; ydroppedbytesdatarel[i] = (bytesdelta===undefined || bytesdelta>=0) ? bytesdelta : 0;
} }
...@@ -205,73 +211,117 @@ function plotGraph(data) ...@@ -205,73 +211,117 @@ function plotGraph(data)
graphbytesabs.height = 20; graphbytesabs.height = 20;
graphbytesrel.width = 80; graphbytesrel.width = 80;
graphbytesrel.height = 20; graphbytesrel.height = 20;
//
accept__borderColor = "#20ff20"; // green
accept__pointbackgroundColor = "#ccffcc"; // light green
accept__backgroundColor = "#ccffcc"; // light green
drop__borderColor = "#ff2020"; // red
drop__pointbackgroundColor = "#ffcccc"; // light red
drop__backgroundColor = "#ffcccc"; // light red
matched__borderColor = "#ffa500"; // orange
matched__pointbackgroundColor = "#ffff00"; // yellow
matched__backgroundColor = "#ffff00"; // yellow
if (is_drop_rule) {
matched_text = "matched and dropped";
value1__borderColor = drop__borderColor;
value1__pointbackgroundColor = drop__pointbackgroundColor;
value1__backgroundColor = drop__backgroundColor;
} else if (is_accept_rule) {
matched_text = "matched and accepted";
value1__borderColor = accept__borderColor;
value1__pointbackgroundColor = accept__pointbackgroundColor;
value1__backgroundColor = accept__backgroundColor;
} else {
matched_text = "matched";
value1__borderColor = matched__borderColor;
value1__pointbackgroundColor = matched__pointbackgroundColor;
value1__backgroundColor = matched__backgroundColor;
}
var ypkg_datasets = [{ var ypkg_datasets = [{
label: '# packets', label: '# packets '+matched_text,
data: ypkgdata, data: ypkgdata,
borderWidth: 2, borderWidth: 2,
borderColor: "#3c37c6", borderColor: value1__borderColor,
pointBackgroundColor: "#3c37c6", pointBackgroundColor: value1__pointbackgroundColor,
backgroundColor: "#99bfff" backgroundColor: value1__backgroundColor
//borderColor: "#3c37c6",
//pointBackgroundColor: "#3c37c6",
//backgroundColor: "#99bfff"
}]; }];
var ypkgrel_datasets = [{ var ypkgrel_datasets = [{
label: '# packets', label: '# packets '+matched_text,
data: ypkgdatarel, data: ypkgdatarel,
borderWidth: 2, borderWidth: 2,
borderColor: "#c63737", borderColor: value1__borderColor,
pointBackgroundColor: "#c63737", pointBackgroundColor: value1__pointbackgroundColor,
backgroundColor: "#ff877a" backgroundColor: value1__backgroundColor
//borderColor: "#c63737",
//pointBackgroundColor: "#c63737",
//backgroundColor: "#ff877a"
}]; }];
var ybytes_datasets = [{ var ybytes_datasets = [{
label: '# bytes', label: '# bytes '+matched_text,
data: ybytesdata, data: ybytesdata,
borderWidth: 2, borderWidth: 2,
borderColor: "#3c37c6", borderColor: value1__borderColor,
pointBackgroundColor: "#3c37c6", pointBackgroundColor: value1__pointbackgroundColor,
backgroundColor: "#99bfff" backgroundColor: value1__backgroundColor
//borderColor: "#3c37c6",
//pointBackgroundColor: "#3c37c6",
//backgroundColor: "#99bfff"
}]; }];
var ybytesrel_datasets = [{ var ybytesrel_datasets = [{
label: '# bytes', label: '# bytes '+matched_text,
data: ybytesdatarel, data: ybytesdatarel,
borderWidth: 2, borderWidth: 2,
borderColor: "#c63737", borderColor: value1__borderColor,
pointBackgroundColor: "#c63737", pointBackgroundColor: value1__pointbackgroundColor,
backgroundColor: "#ff877a" backgroundColor: value1__backgroundColor
//borderColor: "#c63737",
//pointBackgroundColor: "#c63737",
//backgroundColor: "#ff877a"
}]; }];
if (yseen_available) { if (ydropped_available) {
ypkg_datasets.push({ ypkg_datasets.push({
label: '# packets matched', label: '# packets dropped',
data: yseenpkgdata, data: ydroppedpkgdata,
borderWidth: 2, borderWidth: 2,
borderColor: "#cc37c6", borderColor: drop__borderColor,
pointBackgroundColor: "#3c37c6", pointBackgroundColor: drop__pointbackgroundColor,
backgroundColor: "#59bf6f" backgroundColor: drop__backgroundColor
}); });
ypkgrel_datasets.push({ ypkgrel_datasets.push({
label: '# packets matched', label: '# packets dropped',
data: yseenpkgdatarel, data: ydroppedpkgdatarel,
borderWidth: 2, borderWidth: 2,
borderColor: "#c63737", borderColor: drop__borderColor,
pointBackgroundColor: "#c63737", pointBackgroundColor: drop__pointbackgroundColor,
backgroundColor: "#6f223a" backgroundColor: drop__backgroundColor
}); });
ybytes_datasets.push({ ybytes_datasets.push({
label: '# bytes matched', label: '# bytes dropped',
data: yseenbytesdata, data: ydroppedbytesdata,
borderWidth: 2, borderWidth: 2,
borderColor: "#cc37c6", borderColor: drop__borderColor,
pointBackgroundColor: "#3c37c6", pointBackgroundColor: drop__pointbackgroundColor,
backgroundColor: "#59bf6f" backgroundColor: drop__backgroundColor
}); });
ybytesrel_datasets.push({ ybytesrel_datasets.push({
label: '# bytes matched', label: '# bytes dropped',
data: yseenbytesdatarel, data: ydroppedbytesdatarel,
borderWidth: 2, borderWidth: 2,
borderColor: "#c63737", borderColor: drop__borderColor,
pointBackgroundColor: "#c63737", pointBackgroundColor: drop__pointbackgroundColor,
backgroundColor: "#6f223a" backgroundColor: drop__backgroundColor
}); });
} }
...@@ -375,7 +425,7 @@ $(document).ready(function() { ...@@ -375,7 +425,7 @@ $(document).ready(function() {
$("#traffic-plot-loading").text("No data, try later"); $("#traffic-plot-loading").text("No data, try later");
} else { } else {
$("#traffic-plot-loading").hide(); $("#traffic-plot-loading").hide();
plotGraph(data); plotGraph("{{ route.get_then }}", data);
} }
}); });
}); });
......
...@@ -908,18 +908,48 @@ elif [ "$1" = "--process_ruleinfo" ]; then #arg ...@@ -908,18 +908,48 @@ elif [ "$1" = "--process_ruleinfo" ]; then #arg
## ##
if [ \( -z "$counter_values_drop" -o "$counter_values_drop" = "0 0" \) -a "$use_random_values" = 1 ]; then if [ \( -z "$counter_values_drop" -o "$counter_values_drop" = "0 0" \) -a "$use_random_values" = 1 ]; then
old_random_value1="$(cat "/dev/shm/rule_random_counter-$cookie.val1")"
old_random_value2="$(cat "/dev/shm/rule_random_counter-$cookie.val2")"
[ -n "$old_random_value1" ] || old_random_value1=0
[ -n "$old_random_value2" ] || old_random_value2=0
random_value1=$(( $old_random_value1 + $RANDOM * $RANDOM )) store_file_prefix="/dev/shm/rule_random_counter-$cookie"
random_value2=$(( $old_random_value2 + $RANDOM * $RANDOM / 100 / 100 ))
echo "$random_value1" > "/dev/shm/rule_random_counter-$cookie.val1" old_random_value_read_bytes="$(cat "$store_file_prefix-read-bytes.val")"
echo "$random_value2" > "/dev/shm/rule_random_counter-$cookie.val2" old_random_value_read_pkgs="$(cat "$store_file_prefix-read-pkgs.val")"
[ -n "$old_random_value_read_bytes" ] || old_random_value_read_bytes=0
[ -n "$old_random_value_read_pkgs" ] || old_random_value_read_pkgs=0
random_value_add_read_bytes=$(( $RANDOM * $RANDOM ))
random_value_add_read_pkgs=$(( $RANDOM * $RANDOM / 100 / 100 ))
random_value_read_bytes=$(( $old_random_value_read_bytes + $random_value_add_read_bytes ))
random_value_read_pkgs=$(( $old_random_value_read_pkgs + $random_value_add_read_pkgs ))
echo "$random_value_read_bytes" > "$store_file_prefix-read-bytes.val"
echo "$random_value_read_pkgs" > "$store_file_prefix-read-pkgs.val"
##
if [ "$then" = "${then#rate-limit}" ]; then # not a rate-limiting rule?
random_value_drop_bytes="$random_value_read_bytes"
random_value_drop_pkgs="$random_value_read_pkgs"
else
old_random_value_drop_bytes="$(cat "$store_file_prefix-drop-bytes.val")"
old_random_value_drop_pkgs="$(cat "$store_file_prefix-drop-pkgs.val")"
[ -n "$old_random_value_drop_bytes" ] || old_random_value_drop_bytes=0
[ -n "$old_random_value_drop_pkgs" ] || old_random_value_drop_pkgs=0
random_value_add_drop_bytes=$(( $RANDOM * $random_value_add_read_bytes / 32678 ))
random_value_add_drop_pkgs=$(( $RANDOM * $random_value_add_read_pkgs / 32678 ))
random_value_drop_bytes=$(( $old_random_value_drop_bytes + $random_value_add_drop_bytes ))
random_value_drop_pkgs=$(( $old_random_value_drop_pkgs + $random_value_add_drop_pkgs ))
echo "$random_value_drop_bytes" > "$store_file_prefix-drop-bytes.val"
echo "$random_value_drop_pkgs" > "$store_file_prefix-drop-pkgs.val"
fi
counter_values_drop="$random_value1 $random_value2" counter_values_read="$random_value_read_bytes $random_value_read_pkgs"
counter_values_drop="$random_value_drop_bytes $random_value_drop_pkgs"
fi fi
## ##
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment