Update HTTP metrics filter for InfluxDB 0.9

This change modifies the Heka filter computing the HTTP metrics to add
tags to the metric instead of encoding the information in the serie
name.

Change-Id: If1ca1b99ed1fab33dbfce9fa1d915ffbd136c8a7
Implements: blueprint upgrade-influxdb-grafana
This commit is contained in:
Simon Pasquier
2015-07-28 09:33:28 +02:00
parent a81a9a621a
commit 30aff3cadf
4 changed files with 86 additions and 3 deletions

View File

@@ -32,16 +32,20 @@ function process_message ()
-- keep only the first 2 tokens because some services like Neutron report
-- themselves as 'openstack.<service>.server'
local service = string.gsub(read_message("Logger"), '(%w+)%.(%w+).*', '%1.%2')
local service = string.gsub(read_message("Logger"), '(%w+)%.(%w+).*', '%1_%2')
msg.Timestamp = read_message("Timestamp")
msg.Fields = {
hostname = read_message("Hostname"),
source = read_message('Fields[programname]') or service,
name = string.format("%s.http.%s.%s", service, http_method, http_status),
name = service .. '_http_responses',
type = utils.metric_type['GAUGE'],
value = {value = response_time, representation = 's'},
tenant_id = read_message('Fields[tenant_id]'),
user_id = read_message('Fields[user_id]'),
http_method = http_method,
http_status = http_status,
tag_fields = {'http_method', 'http_status'},
}
utils.inject_tags(msg)
inject_message(msg)

View File

@@ -0,0 +1,50 @@
-- Copyright 2015 Mirantis, Inc.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
require 'string'
local utils = require 'lma_utils'
local msg = {
Type = "metric", -- will be prefixed by "heka.sandbox."
Timestamp = nil,
Severity = 6,
Fields = nil
}
function process_message ()
local http_method = read_message("Fields[http_method]")
local http_status = read_message("Fields[http_status]")
local response_time = read_message("Fields[http_response_time]")
if http_method == nil or http_status == nil or response_time == nil then
return -1
end
-- keep only the first 2 tokens because some services like Neutron report
-- themselves as 'openstack.<service>.server'
local service = string.gsub(read_message("Logger"), '(%w+)%.(%w+).*', '%1.%2')
msg.Timestamp = read_message("Timestamp")
msg.Fields = {
source = read_message('Fields[programname]') or service,
name = string.format("%s.http.%s.%s", service, http_method, http_status),
type = utils.metric_type['GAUGE'],
value = {value = response_time, representation = 's'},
tenant_id = read_message('Fields[tenant_id]'),
user_id = read_message('Fields[user_id]'),
}
utils.inject_tags(msg)
inject_message(msg)
return 0
end

View File

@@ -0,0 +1,25 @@
# Copyright 2015 Mirantis, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
class lma_collector::logs::metrics_legacy {
include lma_collector::params
include lma_collector::service
heka::filter::sandbox { 'http_metrics_legacy':
config_dir => $lma_collector::params::config_dir,
filename => "${lma_collector::params::plugins_dir}/filters/http_metrics_legacy.lua",
message_matcher => 'Type == \'log\' && Fields[http_response_time] != NIL',
notify => Class['lma_collector::service'],
}
}