From 7b13db7aef253c4a2fc6b7c641dbbd73c12ef5b3 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 26 Oct 2012 15:44:05 +0200 Subject: [PATCH] add ceilometer-send-counter This program can be used to send counter manually. Change-Id: I11a7b7b99cf9aea6b6885cdc4640b8c2da54a564 Signed-off-by: Julien Danjou --- bin/ceilometer-send-counter | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 bin/ceilometer-send-counter diff --git a/bin/ceilometer-send-counter b/bin/ceilometer-send-counter new file mode 100755 index 000000000..7765709d1 --- /dev/null +++ b/bin/ceilometer-send-counter @@ -0,0 +1,89 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +# +# Copyright © 2012 Julien Danjou +# +# Author: Julien Danjou +# +# 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. + +"""Command line tool for creating counter for Ceilometer. +""" + +import logging +import sys + +from ceilometer import counter +from ceilometer import publish +from ceilometer.openstack.common import cfg +from ceilometer.openstack.common import timeutils +from ceilometer.openstack.common import context + + +cfg.CONF.register_cli_opts([ + cfg.StrOpt('counter-name', + short='n', + help='counter name', + required=True), + cfg.StrOpt('counter-type', + short='y', + help='counter type (gauge, delta, cumulative)', + default='gauge', + required=True), + cfg.IntOpt('counter-volume', + short='l', + help='counter volume value', + default=1), + cfg.StrOpt('counter-resource', + short='r', + help='counter resource id', + required=True), + cfg.StrOpt('counter-user', + short='u', + help='counter user id'), + cfg.StrOpt('counter-project', + short='p', + help='counter project id'), + cfg.StrOpt('counter-timestamp', + short='i', + help='counter timestamp', + default=timeutils.utcnow().isoformat()), + cfg.StrOpt('counter-metadata', + short='m', + help='counter metadata'), +]) + +cfg.CONF(sys.argv[1:]) + +# Set up logging to use the console +console = logging.StreamHandler(sys.stderr) +console.setLevel(logging.DEBUG) +formatter = logging.Formatter('%(message)s') +console.setFormatter(formatter) +root_logger = logging.getLogger('') +root_logger.addHandler(console) +root_logger.setLevel(logging.DEBUG) + +publish.publish_counter(context.get_admin_context(), + counter.Counter(name=cfg.CONF.counter_name, + type=cfg.CONF.counter_type, + volume=cfg.CONF.counter_volume, + user_id=cfg.CONF.counter_user, + project_id=cfg.CONF.counter_project, + resource_id=cfg.CONF.counter_resource, + timestamp=cfg.CONF.counter_timestamp, + resource_metadata=cfg.CONF.counter_metadata + and eval(cfg.CONF.counter_metadata)), + cfg.CONF.metering_topic, + cfg.CONF.metering_secret, + cfg.CONF.counter_source)