void on_metrics_request(Message m)
        {
            var req = m.MetricsRequest;
            List <Metrics.Metric> metrics = new List <Metrics.Metric>();

            // filter by name, if necessary
            if (string.IsNullOrEmpty(req.Name))
            {
                foreach (var metric in metrics_manager_.all_metrics())
                {
                    var dims = metric.All_dimensions();
                    if (dims.Count == 0 || dims[0].Key != "MetricName")
                    {
                        return;
                    }

                    if (dims[0].Value == req.Name)
                    {
                        metrics.Add(metric);
                    }
                }
            }
            else
            {
                metrics = metrics_manager_.all_metrics();
            }

            // convert the data into protobuf
            Message reply = new Message();

            reply.Id       = (ulong)new Random().Next();
            reply.SourceId = m.Id;
            var res = reply.MetricsResponse;

            foreach (var metric in metrics)
            {
                var dims = metric.All_dimensions();

                if (dims.Count == 0 || dims[0].Key == "MetricName")
                {
                    return;
                }

                var pm = new Aws.Kinesis.Protobuf.Metric();
                pm.Name = dims[0].Value;
                res.Metrics.Add(pm);

                for (int i = 1; i < dims.Count; i++)
                {
                    var d = new Aws.Kinesis.Protobuf.Dimension();
                    d.Key   = dims[i].Key;
                    d.Value = dims[i].Value;
                    pm.Dimensions.Add(d);
                }

                var accum = metric.Accumulator();
                var stats = pm.Stats;

                if (req.Seconds != 0)
                {
                    int s = (int)req.Seconds;
                    stats.Count = accum.count(s);
                    stats.Sum   = accum.sum(s);
                    stats.Min   = accum.min(s);
                    stats.Max   = accum.max(s);
                    stats.Mean  = accum.mean(s);

                    pm.Seconds = (ulong)s;
                }
                else
                {
                    stats.Count = accum.count();
                    stats.Sum   = accum.sum();
                    stats.Min   = accum.min();
                    stats.Max   = accum.max();
                    stats.Mean  = accum.mean();
                    pm.Seconds  = (ulong)accum.elapsedSeconds();
                }
            }

            ipc_manager_.put(reply);
        }