summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJulien Danjou <julien@danjou.info>2017-10-17 18:14:01 +0200
committerJulien Danjou <julien@danjou.info>2017-10-26 09:35:14 +0200
commit9323f07f977f320882f8b536c3b54835274826fc (patch)
tree5a9485d4ee46cc94eed7bd79c9051e538919b030 /tools
parent22138b59880c67914d3f7c2f4806c8ea7ed54f3e (diff)
downloadceilometer-9323f07f977f320882f8b536c3b54835274826fc.tar.gz
Remove deprecated storage drivers
Change-Id: I6b262dd440a72f25662b64d938ab9e5328709a97
Diffstat (limited to 'tools')
-rwxr-xr-xtools/make_test_data.py229
-rwxr-xr-xtools/make_test_data.sh77
-rwxr-xr-xtools/migrate_data_to_gnocchi.py193
3 files changed, 0 insertions, 499 deletions
diff --git a/tools/make_test_data.py b/tools/make_test_data.py
deleted file mode 100755
index 00715e7d..00000000
--- a/tools/make_test_data.py
+++ /dev/null
@@ -1,229 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2012 New Dream Network, LLC (DreamHost)
-#
-# 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 test data for Ceilometer.
-
-Usage:
-
-Generate testing data for e.g. for default time span
-
-source .tox/py27/bin/activate
-./tools/make_test_data.py --user 1 --project 1 --resource 1 --counter cpu_util
---volume 20
-"""
-import argparse
-import datetime
-import random
-import uuid
-
-from oslo_utils import timeutils
-
-from ceilometer.publisher import utils
-from ceilometer import sample
-from ceilometer import service
-from ceilometer import storage
-
-
-def make_test_data(conf, name, meter_type, unit, volume, random_min,
- random_max, user_id, project_id, resource_id, start,
- end, interval, resource_metadata=None, source='artificial'):
- resource_metadata = resource_metadata or {'display_name': 'toto',
- 'host': 'tata',
- 'image_ref': 'test',
- 'instance_flavor_id': 'toto',
- 'server_group': 'toto',
- }
- # Compute start and end timestamps for the new data.
- if isinstance(start, datetime.datetime):
- timestamp = start
- else:
- timestamp = timeutils.parse_strtime(start)
-
- if not isinstance(end, datetime.datetime):
- end = timeutils.parse_strtime(end)
-
- increment = datetime.timedelta(minutes=interval)
-
- print('Adding new samples for meter %s.' % (name))
- # Generate samples
- n = 0
- total_volume = volume
- while timestamp <= end:
- if (random_min >= 0 and random_max >= 0):
- # If there is a random element defined, we will add it to
- # user given volume.
- if isinstance(random_min, int) and isinstance(random_max, int):
- total_volume += random.randint(random_min, random_max)
- else:
- total_volume += random.uniform(random_min, random_max)
-
- c = sample.Sample(name=name,
- type=meter_type,
- unit=unit,
- volume=total_volume,
- user_id=user_id,
- project_id=project_id,
- resource_id=resource_id,
- timestamp=timestamp.isoformat(),
- resource_metadata=resource_metadata,
- source=source,
- )
- data = utils.meter_message_from_counter(
- c, conf.publisher.telemetry_secret)
- # timestamp should be string when calculating signature, but should be
- # datetime object when calling record_metering_data.
- data['timestamp'] = timestamp
- yield data
- n += 1
- timestamp = timestamp + increment
-
- if (meter_type == 'gauge' or meter_type == 'delta'):
- # For delta and gauge, we don't want to increase the value
- # in time by random element. So we always set it back to
- # volume.
- total_volume = volume
-
- print('Added %d new samples for meter %s.' % (n, name))
-
-
-def record_test_data(conf, conn, *args, **kwargs):
- for data in make_test_data(conf, *args, **kwargs):
- conn.record_metering_data(data)
-
-
-def get_parser():
- parser = argparse.ArgumentParser(
- description='generate metering data',
- )
- parser.add_argument(
- '--interval',
- default=10,
- type=int,
- help='The period between samples, in minutes.',
- )
- parser.add_argument(
- '--start',
- default=31,
- help='Number of days to be stepped back from now or date in the past ('
- '"YYYY-MM-DDTHH:MM:SS" format) to define timestamps start range.',
- )
- parser.add_argument(
- '--end',
- default=2,
- help='Number of days to be stepped forward from now or date in the '
- 'future ("YYYY-MM-DDTHH:MM:SS" format) to define timestamps end '
- 'range.',
- )
- parser.add_argument(
- '--type',
- choices=('gauge', 'cumulative'),
- default='gauge',
- dest='meter_type',
- help='Counter type.',
- )
- parser.add_argument(
- '--unit',
- default=None,
- help='Counter unit.',
- )
- parser.add_argument(
- '--project',
- dest='project_id',
- help='Project id of owner.',
- )
- parser.add_argument(
- '--user',
- dest='user_id',
- help='User id of owner.',
- )
- parser.add_argument(
- '--random_min',
- help='The random min border of amount for added to given volume.',
- type=int,
- default=0,
- )
- parser.add_argument(
- '--random_max',
- help='The random max border of amount for added to given volume.',
- type=int,
- default=0,
- )
- parser.add_argument(
- '--resource',
- dest='resource_id',
- default=str(uuid.uuid4()),
- help='The resource id for the meter data.',
- )
- parser.add_argument(
- '--counter',
- default='instance',
- dest='name',
- help='The counter name for the meter data.',
- )
- parser.add_argument(
- '--volume',
- help='The amount to attach to the meter.',
- type=int,
- default=1,
- )
- return parser
-
-
-def main():
-
- args = get_parser().parse_args()
- conf = service.prepare_service([])
-
- # Connect to the metering database
- conn = storage.get_connection_from_config(conf)
-
- # Find the user and/or project for a real resource
- if not (args.user_id or args.project_id):
- for r in conn.get_resources():
- if r.resource_id == args.resource_id:
- args.user_id = r.user_id
- args.project_id = r.project_id
- break
-
- # Compute the correct time span
- format = '%Y-%m-%dT%H:%M:%S'
-
- try:
- start = datetime.datetime.utcnow() - datetime.timedelta(
- days=int(args.start))
- except ValueError:
- try:
- start = datetime.datetime.strptime(args.start, format)
- except ValueError:
- raise
-
- try:
- end = datetime.datetime.utcnow() + datetime.timedelta(
- days=int(args.end))
- except ValueError:
- try:
- end = datetime.datetime.strptime(args.end, format)
- except ValueError:
- raise
- args.start = start
- args.end = end
- record_test_data(conf, conn=conn, **args.__dict__)
-
- return 0
-
-
-if __name__ == '__main__':
- main()
diff --git a/tools/make_test_data.sh b/tools/make_test_data.sh
deleted file mode 100755
index 23a93e88..00000000
--- a/tools/make_test_data.sh
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/bin/bash
-
-bindir=$(dirname $0)
-
-project_name="$1"
-if [ -z "$project_name" ]
-then
- project_name=demo
-fi
-
-if [ -z "$OS_USERNAME" ]
-then
- user=demo
-else
- user=$OS_USERNAME
-fi
-
-# Convert a possible project name to an id, if we have
-# openstack cli installed.
-if which openstack >/dev/null
-then
- project=$(openstack project show "$project_name" -c id -f value)
-else
- # Assume they gave us the project id as argument.
- project="$project_name"
-fi
-
-if [ -z "$project" ]
-then
- echo "Could not determine project id for \"$project_name\"" 1>&2
- exit 1
-fi
-
-early1="2012-08-27T07:00:00"
-early2="2012-08-27T17:00:00"
-
-start="2012-08-28T00:00:00"
-
-middle1="2012-08-28T08:00:00"
-middle2="2012-08-28T18:00:00"
-middle3="2012-08-29T09:00:00"
-middle4="2012-08-29T19:00:00"
-
-end="2012-08-31T23:59:00"
-
-late1="2012-08-31T10:00:00"
-late2="2012-08-31T20:00:00"
-
-mkdata() {
- ${bindir}/make_test_data.py --project "$project" \
- --user "$user" --start "$2" --end "$3" \
- --resource "$1" --counter instance --volume 1
-}
-
-dates=(early1 early2 start middle1 middle2 middle3 middle4 end late1 late2)
-
-echo $project
-
-for i in $(seq 0 $((${#dates[@]} - 2)) )
-do
-
- iname=${dates[$i]}
- eval "ivalue=\$$iname"
-
- for j in $(seq $((i + 1)) $((${#dates[@]} - 1)) )
- do
- jname=${dates[$j]}
- eval "jvalue=\$$jname"
-
- resource_id="${project_name}-$iname-$jname"
- echo "$resource_id"
-
- mkdata "$resource_id" "$ivalue" "$jvalue"
- [ $? -eq 0 ] || exit $?
- done
- echo
-done
diff --git a/tools/migrate_data_to_gnocchi.py b/tools/migrate_data_to_gnocchi.py
deleted file mode 100755
index 27c87d97..00000000
--- a/tools/migrate_data_to_gnocchi.py
+++ /dev/null
@@ -1,193 +0,0 @@
-#
-# Copyright 2017 Huawei Technologies Co.,LTD.
-#
-# 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 migrating metrics data from ceilometer native
-storage backend to Gnocchi.
-
-Usage:
-python migrate_data_to_gnocchi.py --native-metering-connection "mysql+pymysql:
-//root:password@127.0.0.1/ceilometer?charset=utf8"
-
-NOTE:
-You may need to install *tqdm* python lib to support progress bar in migration.
-
-"""
-
-import sys
-
-try:
- from tqdm import tqdm as progress_bar
-except ImportError:
- progress_bar = None
-
-import argparse
-from oslo_config import cfg
-from oslo_db import options as db_options
-from oslo_log import log
-
-from ceilometer.publisher import gnocchi
-from ceilometer import service
-from ceilometer import storage
-from ceilometer.storage import impl_mongodb
-from ceilometer.storage import impl_sqlalchemy
-from ceilometer.storage.mongo import utils as pymongo_utils
-from ceilometer import utils
-
-
-def get_parser():
- parser = argparse.ArgumentParser(
- description='For migrating metrics data from ceilometer built-in '
- 'storage backends to Gnocchi.')
- parser.add_argument(
- '--native-metering-connection',
- required=True,
- help='The database connection url of native storage backend. '
- 'e.g. mysql+pymysql://root:password@127.0.0.1/ceilometer?charset'
- '=utf8',
- )
- parser.add_argument(
- '--ceilometer-config-file',
- help="The config file of ceilometer, it is main used for gnocchi "
- "publisher to init gnocchiclient with the service credentials "
- "defined in the ceilometer config file. Default as "
- "/etc/ceilometer/ceilometer.conf",
- )
- parser.add_argument(
- '--log-file',
- default='gnocchi-data-migration.log',
- help="The log file to record messages during migration.", )
- parser.add_argument(
- '--batch-migration-size',
- default=300,
- help="The amount of samples that will be posted to gnocchi per batch",)
- parser.add_argument(
- '--start-timestamp',
- default=None,
- help="The stat timestamp of metrics data to be migrated, with ISO8601 "
- "format, e.g. 2016-01-25 11:58:00",
- )
- parser.add_argument(
- '--end-timestamp',
- default=None,
- help="The end timestamp of metrics data to be migrated, with ISO8601 "
- "format, e.g. 2017-01-25 11:58:00",
- )
- return parser
-
-
-def count_samples(storage_conn, start_timestamp=None, end_timestamp=None):
- if start_timestamp:
- start_timestamp = utils.sanitize_timestamp(start_timestamp)
- if start_timestamp:
- end_timestamp = utils.sanitize_timestamp(end_timestamp)
- if isinstance(storage_conn, impl_sqlalchemy.Connection):
- from ceilometer.storage.sqlalchemy import models
- session = storage_conn._engine_facade.get_session()
- query = session.query(models.Sample.id)
- if start_timestamp:
- query = query.filter(models.Sample.timestamp >= start_timestamp)
- if end_timestamp:
- query = query.filter(models.Sample.timestamp < end_timestamp)
- return query.count()
- elif isinstance(storage_conn, impl_mongodb.Connection):
- ts_range = pymongo_utils.make_timestamp_range(start_timestamp,
- end_timestamp)
- return storage_conn.db.meter.count(ts_range)
- else:
- print("Unsupported type of storage connection: %s" % storage_conn)
- sys.exit(1)
-
-
-def get_native_storage_conn(metering_connection):
- storage_conf = cfg.ConfigOpts()
- db_options.set_defaults(storage_conf)
- storage_conf.register_opts(storage.OPTS, 'database')
- storage_conf.set_override('metering_connection',
- metering_connection, 'database')
- storage_conn = storage.get_connection_from_config(storage_conf)
- return storage_conn
-
-
-def main():
- args = get_parser().parse_args()
-
- storage_conn = get_native_storage_conn(args.native_metering_connection)
- total_amount = count_samples(storage_conn, args.start_timestamp,
- args.end_timestamp)
- print('%s samples will be migrated to Gnocchi.' % total_amount)
-
- # NOTE: we need service credentials to init gnocchiclient
- config_file = ([args.ceilometer_config_file] if
- args.ceilometer_config_file else None)
- gnocchi_conf = service.prepare_service([], config_file)
- logger = log.getLogger()
- log_conf = cfg.ConfigOpts()
- log.register_options(log_conf)
- log_conf.set_override('log_file', args.log_file)
- log_conf.set_override('debug', True)
- log.setup(log_conf, 'ceilometer_migration')
- time_filters = []
- if args.start_timestamp:
- time_filters.append({">=": {'timestamp': args.start_timestamp}})
- if args.end_timestamp:
- time_filters.append({"<": {'timestamp': args.end_timestamp}})
-
- gnocchi_publisher = gnocchi.GnocchiPublisher(gnocchi_conf, "gnocchi://")
-
- batch_size = args.batch_migration_size
- if total_amount == 'Unknown':
- total_amount = None
- orderby = [{"message_id": "asc"}]
- last_message_id = None
- migrated_amount = 0
- if progress_bar:
- pbar = progress_bar(total=total_amount, ncols=100, unit='samples')
- else:
- pbar = None
- while migrated_amount < total_amount:
- if time_filters and last_message_id:
- filter_expr = {
- 'and': time_filters + [{">": {"message_id": last_message_id}}]}
- elif time_filters and not last_message_id:
- if len(time_filters) == 1:
- filter_expr = time_filters[0]
- else:
- filter_expr = {'and': time_filters}
- elif not time_filters and last_message_id:
- filter_expr = {">": {"message_id": last_message_id}}
- else:
- filter_expr = None
- samples = storage_conn.query_samples(
- filter_expr=filter_expr, orderby=orderby, limit=batch_size)
- samples = list(samples)
- if not samples:
- break
- last_message_id = samples[-1].message_id
- for sample in samples:
- logger.info('Migrating sample with message_id: %s, meter: %s, '
- 'resource_id: %s' % (sample.message_id,
- sample.counter_name,
- sample.resource_id))
- samples_dict = [sample.as_dict() for sample in samples]
- gnocchi_publisher.publish_samples(samples_dict)
- length = len(samples)
- migrated_amount += length
- if pbar:
- pbar.update(length)
- logger.info("=========== %s metrics data migration done ============" %
- total_amount)
-
-if __name__ == '__main__':
- sys.exit(main())