1 // Copyright 2020 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 #pragma once 15 16 #include <cstring> 17 18 #include "pw_log/log.h" 19 #include "pw_metric/metric.h" 20 #include "pw_metric_proto/metric_service.rpc.pb.h" 21 #include "pw_span/span.h" 22 23 namespace pw::metric { 24 25 // The MetricService will send metrics when requested by Get(). For now, each 26 // Get() request results in a stream of responses, containing the metrics from 27 // the supplied list of groups and metrics. This includes recursive traversal 28 // of subgroups. In the future, filtering will be supported. 29 // 30 // An important limitation of the current implementation is that the Get() 31 // method is blocking, and sends all metrics at once (though batched). In the 32 // future, we may switch to offering an async version where the Get() method 33 // returns immediately, and someone else is responsible for pumping the queue. 34 class MetricService final 35 : public proto::pw_rpc::nanopb::MetricService::Service<MetricService> { 36 public: MetricService(const IntrusiveList<Metric> & metrics,const IntrusiveList<Group> & groups)37 MetricService(const IntrusiveList<Metric>& metrics, 38 const IntrusiveList<Group>& groups) 39 : metrics_(metrics), groups_(groups) {} 40 41 void Get(const pw_metric_proto_MetricRequest& request, 42 ServerWriter<pw_metric_proto_MetricResponse>& response); 43 44 private: 45 const IntrusiveList<Metric>& metrics_; 46 const IntrusiveList<Group>& groups_; 47 }; 48 49 } // namespace pw::metric 50