From Fedora Project Wiki

(Created page with "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 ...")
 
No edit summary
Line 29: Line 29:
   > db.meter.find({'counter_name': 'cpu_util', 'resource_id' : $INSTANCE_ID}).sort({'timestamp': 1})
   > db.meter.find({'counter_name': 'cpu_util', 'resource_id' : $INSTANCE_ID}).sort({'timestamp': 1})
   { "_id" : ObjectId("515af62a1a63121d32eaa00c"), "counter_name" : "cpu_util", "user_id" : ...
   { "_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:
<nowiki>
  > db.meter.mapReduce(mapVolumes, reduceAverage, { out: { merge: 'average_util' }, query: {'counter_name': 'cpu_util'}});
  {
"result" : "average_map_reduce",
"timeMillis" : 110,
"counts" : {
"input" : 22,
"emit" : 22,
"reduce" : 1,
"output" : 1
},
"ok" : 1,
  }
</nowiki>
Display this temporary collection:
  > db.average_util.find()
  { "_id" : "738b4794-d5ec-48d0-b669-d31d368986ed", "value" : 5.473252670153079 }

Revision as of 15:53, 2 April 2013

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 retrived 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_map_reduce", "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 }