Skip to content
This repository has been archived by the owner on Aug 7, 2021. It is now read-only.

Commit

Permalink
feat(handler) expose dataplane status on control plane
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Sep 15, 2020
1 parent 5ed9738 commit 8a1f0a2
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions kong/plugins/prometheus/exporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ local metrics = {}
-- prometheus.lua instance
local prometheus

-- the clustering module, lazy imported
local clustering
local cp_metrics

-- use the same counter library shipped with Kong
package.loaded['prometheus_resty_counter'] = require("resty.counter")

Expand Down Expand Up @@ -71,6 +75,20 @@ local function init()
"Total bandwidth in bytes " ..
"consumed per service/route in Kong",
{"service", "route", "type"})


-- Hybrid mode status
if kong.version_num >= 2000000 then -- 200.00.00 -> 2.0.0 then
if kong.configuration.role == "control_plane" then
cp_metrics = true

clustering = require("kong.clustering")

metrics.dataplane_last_seen = prometheus:gauge("dataplane_last_seen",
"Last time data plane contacted control plane",
{"node_id", "hostname", "ip", "hash"})
end
end
end

local function init_worker()
Expand Down Expand Up @@ -236,6 +254,17 @@ local function collect()
{res.workers_lua_vms[i].pid})
end

-- Hybrid mode status
if cp_metrics then
-- Cleanup old metrics
metrics.dataplane_last_seen:reset()

local data_planes = clustering.get_status()
for node_id, status in pairs(data_planes) do
metrics.dataplane_last_seen:set(status.last_seen, { node_id, status.hostname, status.ip, status.config_hash })
end
end

prometheus:collect()
end

Expand Down

0 comments on commit 8a1f0a2

Please sign in to comment.