From Fedora Project Wiki

Revision as of 15:55, 2 April 2013 by Eglynn (talk | contribs)

Ceilometer uses mongoDB by default to store metering data (though storage drivers are also supported for sqlalchemy and more recently for HBase too).

In this test we use the mongo client to explore the metering store:

 mongo ceilometer

Show the available collections:

 > show collections
 meter
 project
 resource
 system.indexes
 user

Note the default indices:

 > db.system.indexes.find()
 { "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.resource", "name" : "_id_" }
 { "v" : 1, "key" : { "user_id" : 1, "source" : 1 }, "ns" : "ceilometer.resource", "name" : "resource_idx" }
 { "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.meter", "name" : "_id_" }
 { "v" : 1, "key" : { "resource_id" : 1, "user_id" : 1, "counter_name" : 1, "timestamp" : 1, "source" : 1 },
   "ns" : "ceilometer.meter", "name" : "meter_idx" }
 { "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.user", "name" : "_id_" }
 { "v" : 1, "key" : { "_id" : 1 }, "ns" : "ceilometer.project", "name" : "_id_" }

Show the cpu_util samples retrieved earlier via the ceilometer CLI, sorted in ascending time-order:

 > db.meter.find({'counter_name': 'cpu_util', 'resource_id' : $INSTANCE_ID}).sort({'timestamp': 1})
 { "_id" : ObjectId("515af62a1a63121d32eaa00c"), "counter_name" : "cpu_util", "user_id" : ...

Do some simple map-reduce to determine the average CPU utilization across all instances. First define javascript functions to map the counter volumes and calculate the average respectively:

 > var mapVolumes = function() {
       emit(this.resource_id, this.counter_volume);
   }
 > var reduceAverage =         function (key, values) {
       var total = 0;
       for (var i = 0; i < values.length; i++) {
           total += values[i];
       }
       return total / values.length;
   }

Then apply this to all cpu_util counters, saving the result in the 'average_util' collection:

 
  > db.meter.mapReduce(mapVolumes, reduceAverage, { out: { merge: 'average_util' }, query: {'counter_name': 'cpu_util'}});
  {
	"result" : "average_util",
	"timeMillis" : 110,
	"counts" : {
		"input" : 22,
		"emit" : 22,
		"reduce" : 1,
		"output" : 1
	},
	"ok" : 1,
  }
  

Display this temporary collection:

 > db.average_util.find()
 { "_id" : "738b4794-d5ec-48d0-b669-d31d368986ed", "value" : 5.473252670153079 }