diff --git a/docker/hindsight/analysis/afd.lua b/docker/hindsight/analysis/afd.lua index ed9db37..b8dab2b 100644 --- a/docker/hindsight/analysis/afd.lua +++ b/docker/hindsight/analysis/afd.lua @@ -20,28 +20,25 @@ local afd_annotation = require 'stacklight.afd_annotation' -- node or service local afd_type = read_config('afd_type') or error('afd_type must be specified!') -local msg_type -local msg_field_name -local afd_entity +local afd_msg_type +local afd_metric_name if afd_type == 'node' then - msg_type = 'afd_node_metric' - msg_field_name = 'node_status' - afd_entity = 'node_role' + afd_msg_type = 'afd_node_metric' + afd_metric_name = 'node_status' elseif afd_type == 'service' then - msg_type = 'afd_service_metric' - msg_field_name = 'service_status' - afd_entity = 'service' + afd_msg_type = 'afd_service_metric' + afd_metric_name = 'service_status' else error('invalid afd_type value') end -- ie: controller for node AFD / rabbitmq for service AFD -local afd_entity_value = read_config('afd_cluster_name') or +local afd_cluster_name = read_config('afd_cluster_name') or error('afd_cluster_name must be specified!') -- ie: cpu for node AFD / queue for service AFD -local msg_field_source = read_config('afd_logical_name') or +local afd_logical_name = read_config('afd_logical_name') or error('afd_logical_name must be specified!') local hostname = read_config('hostname') or error('hostname must be specified') @@ -101,13 +98,13 @@ function timer_event(ns) -- value = 0, -- hostname = 'node1', -- source = 'cpu', - -- node_role = 'controller', - -- dimensions = {'node_role', 'source', 'hostname'}, + -- cluster = 'system', + -- dimensions = {'cluster', 'source', 'hostname'}, -- } -- } local msg = afd.inject_afd_metric( - msg_type, afd_entity, afd_entity_value, msg_field_name, - state, hostname, msg_field_source) + afd_msg_type, afd_metric_name, afd_cluster_name, afd_logical_name, + state, hostname) if msg then afd_annotation.inject_afd_annotation(msg) diff --git a/docker/hindsight/modules/afd.lua b/docker/hindsight/modules/afd.lua index 1db84ac..df479df 100644 --- a/docker/hindsight/modules/afd.lua +++ b/docker/hindsight/modules/afd.lua @@ -43,6 +43,10 @@ function read_hostname(msg) return read_field(msg, 'hostname') end +function read_cluster(msg) + return read_field(msg, 'cluster') +end + function extract_alarms(msg) local ok, payload = pcall(cjson.decode, msg.Payload) if not ok or not payload.alarms then @@ -135,9 +139,9 @@ function reset_alarms() alarms = {} end --- inject an AFD event into the Heka pipeline -function inject_afd_metric(msg_type, msg_tag_name, msg_tag_value, metric_name, - value, hostname, source) +-- inject an AFD event into the pipeline +function inject_afd_metric(msg_type, metric_name, cluster_name, logical_name, + state, hostname) local payload if #alarms > 0 then @@ -156,13 +160,13 @@ function inject_afd_metric(msg_type, msg_tag_name, msg_tag_value, metric_name, Payload = payload, Fields = { name = metric_name, - value = value, + value = state, hostname = hostname, - source = source, - dimensions = {msg_tag_name, 'hostname', 'source'}, + cluster = cluster_name, + source = logical_name, + dimensions = {'cluster', 'hostname', 'source'}, } } - msg.Fields[msg_tag_name] = msg_tag_value local err_code, err_msg = utils.safe_inject_message(msg) diff --git a/docker/hindsight/modules/afd_annotation.lua b/docker/hindsight/modules/afd_annotation.lua index 1ede301..3e1cef3 100644 --- a/docker/hindsight/modules/afd_annotation.lua +++ b/docker/hindsight/modules/afd_annotation.lua @@ -28,11 +28,12 @@ local annotation_msg = { Type = 'metric', Fields = { name = 'annotation', - dimensions = {'source', 'hostname'}, + dimensions = {'cluster', 'source', 'hostname'}, value_fields = {'title', 'tags', 'text'}, title = nil, tags = nil, text = nil, + cluster = nil, source = nil, hostname = nil, } @@ -46,8 +47,9 @@ function inject_afd_annotation(msg) local status = afd.read_status(msg) local hostname = afd.read_hostname(msg) local alarms = afd.extract_alarms(msg) + local cluster = afd.read_cluster(msg) - if not source or not status or not alarms then + if not source or not status or not hostname or not alarms or not cluster then return -1 end @@ -88,6 +90,7 @@ function inject_afd_annotation(msg) annotation_msg.Fields.text = text annotation_msg.Fields.source = source annotation_msg.Fields.hostname = hostname + annotation_msg.Fields.cluster = cluster -- store the last status and alarm text for future messages previous.status = status