Skip to content

Commit

Permalink
Fixed Redis reads and writes time series
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelceroni committed Feb 11, 2025
1 parent 7dd3681 commit 97aa500
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
38 changes: 33 additions & 5 deletions scripts/callbacks/minute/system/redis_timeseries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,28 @@ local hits_stats = ntop.getCacheStats()
local old_hits_stats = ntop.getCache(hits_key)

-- ##############################################
local read_op = {
num_get = true,
num_hget = true,
num_hgetall = true,
num_hkeys = true,
num_llen = true,
num_lpop_rpop = true,
num_strlen = true,
num_ttl = true,
num_resolver_get_address = true
}

local write_op = {
num_set = true,
num_hset = true,
num_lpush_rpush = true,
num_trim = true,
num_del = true,
num_hdel = true,
num_expire = true,
num_resolver_set_address = true
}

if redis_api.redisTimeseriesEnabled() then
require "ts_minute"
Expand All @@ -26,7 +48,10 @@ if redis_api.redisTimeseriesEnabled() then

local when = os.time()
local stats = redis_api.getStats()


local reads = 0
local writes = 0

if(not isEmptyString(old_hits_stats)) then
old_hits_stats = json.decode(old_hits_stats) or {}
else
Expand All @@ -40,18 +65,21 @@ if redis_api.redisTimeseriesEnabled() then
if stats["dbsize"] then
ts_utils.append("redis:keys", {ifid = ifid, num_keys = stats["dbsize"]}, when)
end
if stats["reads"] and stats["writes"] then
ts_utils.append("redis:reads_writes", {ifid = ifid, num_reads = stats["reads"], num_writes = stats["writes"]}, when)
end

for key, val in pairs(hits_stats) do
if(old_hits_stats[key] ~= nil) then
local delta = math.max(val - old_hits_stats[key], 0)

if read_op[key] then
reads=reads+delta
elseif write_op[key] then
writes=writes+delta
end
-- Dump the delta value as a gauge
ts_utils.append("redis:hits", {ifid = ifid, command = key, num_calls = delta}, when)
end
end

ts_utils.append("redis:reads_writes_v2", {ifid = ifid, num_reads = reads, num_writes = writes}, when)

ntop.setCache(hits_key, json.encode(hits_stats))
end
4 changes: 0 additions & 4 deletions scripts/lua/modules/redis_api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ function redis_api.getStats()
memory = redis_status["used_memory_rss"],
-- The number of keys in the database
dbsize = redis_status["dbsize"],
-- The number of reads in the database
reads = redis_status["total_reads_processed"],
-- The number of writes in the database
writes = redis_status["total_writes_processed"],
-- Health
health = getHealth(redis_status)
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/lua/modules/timeseries/schemas/ts_minute.lua
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@ schema:addMetric("num_keys")

-- ################################################

schema = ts_utils.newSchema("redis:reads_writes", {
metrics_type = ts_utils.metrics.counter,
schema = ts_utils.newSchema("redis:reads_writes_v2", {
metrics_type = ts_utils.metrics.gauge,
is_system_schema = true,
step = 60
})
Expand Down
2 changes: 1 addition & 1 deletion scripts/lua/modules/timeseries/ts_utils_core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ function ts_utils.getPossiblyChangedSchemas()
"host:tcp_rx_stats", "host:udp_sent_unicast", "host:dns_qry_rcvd_rsp_sent", "host:dns_qry_sent_rsp_rcvd",
"host:tcp_tx_stats", "iface:hosts_anomalies", -- Added missing ifid tag
"influxdb:storage_size", "influxdb:exported_points", "influxdb:exports", "influxdb:rtt", "system:cpu_load",
"process:resident_memory", "redis:keys", "redis:memory", "redis:reads_writes", "periodic_script:timeseries_writes",
"process:resident_memory", "redis:keys", "redis:memory", "redis:reads_writes_v2", "periodic_script:timeseries_writes",
"mac:arp_rqst_sent_rcvd_rpls", -- Active Monitoring
"am_host:http_stats_min", "am_host:https_stats_min", "am_host:val_min", "am_host:http_stats_5mins",
"am_host:https_stats_5mins", "am_host:val_5mins", "am_host:http_stats_hour", "am_host:https_stats_hour",
Expand Down
2 changes: 1 addition & 1 deletion scripts/lua/modules/timeseries_info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1893,7 +1893,7 @@ local community_timeseries = { {
}
}
}, {
schema = "redis:reads_writes",
schema = "redis:reads_writes_v2",
id = timeseries_id.redis,
label = i18n("system_stats.redis.redis_reads_writes"),
priority = 0,
Expand Down

0 comments on commit 97aa500

Please sign in to comment.