Add InfluxDB stats ajax refresh and trend

This commit is contained in:
emanuele-f 2019-06-21 12:41:31 +02:00
parent 8a239f97f4
commit 6ea2cd0aaa
3 changed files with 47 additions and 16 deletions

View file

@ -78,25 +78,48 @@ if(page == "overview") then
if(probe ~= nil) then
local stats = probe.getExportStats()
print("<tr><th nowrap>".. i18n("system_stats.exported_points") .."</th><td>".. formatValue(stats.points_exported) .."</td></tr>\n")
print("<tr><th nowrap>".. i18n("system_stats.dropped_points") .."</th><td>".. formatValue(stats.points_dropped) .."</td></tr>\n")
print("<tr><th nowrap>".. i18n("system_stats.exported_points") .."</th><td><span id=\"influxdb-exported-points\">".. formatValue(stats.points_exported) .."</span></td></tr>\n")
print("<tr><th nowrap>".. i18n("system_stats.dropped_points") .."</th><td><span id=\"influxdb-dropped-points\">".. formatValue(stats.points_dropped) .."</span></td></tr>\n")
end
print("<tr><th nowrap>".. i18n("system_stats.series_cardinality") .." <a href=\"https://docs.influxdata.com/influxdb/v1.7/concepts/glossary/#series-cardinality\"><i class='fa fa-external-link '></i></a></th><td><img class=\"influxdb-info-load\" border=0 src=".. ntop.getHttpPrefix() .. "/img/throbber.gif style=\"vertical-align:text-top;\" id=throbber><span id=\"influxdb-info-series\"></span><i id=\"high-cardinality-warn\" class=\"fa fa-warning fa-lg\" title=\"".. i18n("system_stats.high_series_cardinality") .."\" style=\"color: orange; display:none\"></td></i></tr>\n")
print[[<script>
$(function() {
$.get("]] print(ntop.getHttpPrefix()) print[[/lua/get_influxdb_info.lua", function(info) {
$(".influxdb-info-load").hide();
$("#influxdb-info-text").html(bytesToVolume(info.db_bytes) + " ");
$("#influxdb-info-memory").html(bytesToVolume(info.memory) + " ");
$("#influxdb-info-series").html(addCommas(info.num_series) + " ");
if(info.num_series >= 950000)
$("#high-cardinality-warn").show();
}).fail(function() {
$(".influxdb-info-load").hide();
});
});
var last_db_bytes, last_memory, last_num_series;
var last_exported_points, last_dropped_points;
function refreshInfluxStats() {
$.get("]] print(ntop.getHttpPrefix()) print[[/lua/get_influxdb_info.lua", function(info) {
$(".influxdb-info-load").hide();
$("#influxdb-info-text").html(bytesToVolume(info.db_bytes) + " ");
$("#influxdb-info-memory").html(bytesToVolume(info.memory) + " ");
$("#influxdb-info-series").html(addCommas(info.num_series) + " ");
$("#influxdb-exported-points").html(addCommas(info.points_exported) + " ");
$("#influxdb-dropped-points").html(addCommas(info.points_dropped) + " ");
if(typeof last_db_bytes !== "undefined") {
$("#influxdb-info-text").append(drawTrend(info.db_bytes, last_db_bytes));
$("#influxdb-info-memory").append(drawTrend(info.memory, last_memory));
$("#influxdb-info-series").append(drawTrend(info.num_series, last_num_series));
$("#influxdb-exported-points").append(drawTrend(info.points_exported, last_exported_points));
$("#influxdb-dropped-points").append(drawTrend(info.points_dropped, last_dropped_points, " style=\"color: #B94A48;\""));
}
last_db_bytes = info.db_bytes;
last_memory = info.memory;
last_num_series = info.num_series;
last_exported_points = info.points_exported;
last_dropped_points = info.points_dropped;
if(info.num_series >= 950000)
$("#high-cardinality-warn").show();
}).fail(function() {
$(".influxdb-info-load").hide();
});
}
setInterval(refreshInfluxStats, 5000);
refreshInfluxStats();
</script>
]]