Update resource creation and state metric filters

This change updates the resource creation and instance state filters to
comply with the new metric schema for InfluxDB v0.9.

Change-Id: Ic503d13f21f078cd7c72e57876ce92a8e90536de
Implements: blueprint upgrade-influxdb-grafana
This commit is contained in:
Simon Pasquier
2015-07-29 15:39:44 +02:00
parent 23d5f7a6be
commit fc0551c063
6 changed files with 154 additions and 6 deletions

View File

@@ -31,7 +31,7 @@ function process_message ()
msg.Timestamp = read_message("Timestamp")
msg.Fields = {
source = read_message('Logger'),
name = "openstack.nova.instance_state." .. state,
name = "openstack_nova_instance_state",
-- preserve the original hostname in the Fields attribute because
-- sandboxed filters cannot override the Hostname attribute
hostname = read_message("Fields[hostname]"),
@@ -39,6 +39,8 @@ function process_message ()
value = 1,
tenant_id = read_message("Fields[tenant_id]"),
user_id = read_message("Fields[user_id]"),
state = state,
tag_fields = { 'state' },
}
utils.inject_tags(msg)

View File

@@ -0,0 +1,47 @@
-- 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.
local utils = require 'lma_utils'
local msg = {
Type = "metric", -- will be prefixed by "heka.sandbox."
Timestamp = nil,
Severity = 6,
}
count = 0
function process_message ()
local state = read_message("Fields[state]")
local old_state = read_message("Fields[old_state]")
if old_state ~= nil and state == old_state then
-- nothing to do
return 0
end
msg.Timestamp = read_message("Timestamp")
msg.Fields = {
source = read_message('Logger'),
name = "openstack.nova.instance_state." .. state,
-- preserve the original hostname in the Fields attribute because
-- sandboxed filters cannot override the Hostname attribute
hostname = read_message("Fields[hostname]"),
type = utils.metric_type['COUNTER'],
value = 1,
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

@@ -22,8 +22,8 @@ local msg = {
}
local event_type_to_name = {
["compute.instance.create.end"] = "openstack.nova.instance_creation_time",
["volume.create.end"] = "openstack.cinder.volume_creation_time",
["compute.instance.create.end"] = "openstack_nova_instance_creation_time",
["volume.create.end"] = "openstack_cinder_volume_creation_time",
}
function process_message ()

View File

@@ -0,0 +1,62 @@
-- 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 'math'
local patt = require 'patterns'
local utils = require 'lma_utils'
local msg = {
Type = "metric", -- will be prefixed by "heka.sandbox."
Timestamp = nil,
Severity = 6,
}
local event_type_to_name = {
["compute.instance.create.end"] = "openstack.nova.instance_creation_time",
["volume.create.end"] = "openstack.cinder.volume_creation_time",
}
function process_message ()
local metric_name = event_type_to_name[read_message("Fields[event_type]")]
if not metric_name then
return -1
end
local created_at = read_message("Fields[created_at]") or ''
local launched_at = read_message("Fields[launched_at]") or ''
created_at = patt.Timestamp:match(created_at)
launched_at = patt.Timestamp:match(launched_at)
if created_at == nil or launched_at == nil or created_at == 0 or launched_at == 0 or created_at > launched_at then
return -1
end
msg.Timestamp = read_message("Timestamp")
msg.Fields = {
source = read_message('Logger'),
name = metric_name,
-- preserve the original hostname in the Fields attribute because
-- sandboxed filters cannot override the Hostname attribute
hostname = read_message("Fields[hostname]"),
type = utils.metric_type['GAUGE'],
-- Having a millisecond precision for creation time is good enough given
-- that the created_at field has only a 1-second precision.
value = {value = math.floor((launched_at - created_at)/1e6 + 0.5) / 1e3, 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,34 @@
# 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::notifications::metrics_legacy {
include lma_collector::params
include lma_collector::service
# Filter to compute resource's creation time metric
heka::filter::sandbox { 'resource_creation_time_legacy':
config_dir => $lma_collector::params::config_dir,
filename => "${lma_collector::params::plugins_dir}/filters/resource_creation_time_legacy.lua",
message_matcher => 'Type == \'notification\' && Fields[event_type] =~ /^(compute.instance|volume).create.end$/',
notify => Class['lma_collector::service'],
}
# Filter to compute the instance state change metric
heka::filter::sandbox { 'instance_state_legacy':
config_dir => $lma_collector::params::config_dir,
filename => "${lma_collector::params::plugins_dir}/filters/instance_state_legacy.lua",
message_matcher => 'Type == \'notification\' && Fields[event_type] == \'compute.instance.update\' && Fields[state] != NIL',
notify => Class['lma_collector::service'],
}
}