Skip to content

Commit

Permalink
[Metrics] Number of signatures in the last block hyperledger-iroha#919
Browse files Browse the repository at this point in the history
closes hyperledger-iroha#919

Signed-off-by: Ivan Kuvaldin <[email protected]>
  • Loading branch information
kuvadldini-soramitsu committed Apr 19, 2021
1 parent cb376de commit 1cd4302
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
23 changes: 16 additions & 7 deletions irohad/maintenance/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,33 @@ Metrics::Metrics(
.Help("Total number of domains in WSV")
//.Labels({{"label","a_metter"}})
.Register(*registry_);
auto&domains_number_value = domains_number_gauge.Add({});//{{"valueP", "any"}});
auto&domains_number_value = domains_number_gauge.Add({});

auto&number_of_signatures_in_last_block_gauge = BuildGauge()
.Name("number_of_signatures_in_last_block")
.Help("Number of signatures in last block")
//.Labels({{"label","a_metter"}})
.Register(*registry_);
auto&number_of_signatures_in_last_block = number_of_signatures_in_last_block_gauge.Add({});

block_subscriber_ = std::make_shared<BlockSubscriber>(
getSubscription()->getEngine<EventTypes,BlockPtr>());
block_subscriber_->setCallback(
[&block_height_value,&domains_number_value] //Values are stored in registry_
(auto, auto&receiver, auto const event, auto pblock){
[&] //Values are stored in registry_
(auto, auto&receiver, auto const event, BlockPtr pblock){
// block_height_value is captured by reference because it is stored inside registry_, which is shared_ptr
assert(pblock);
block_height_value.Set(pblock->height());
///---
int domain_created = 0;
unsigned signatures_num = 0;
for(auto const& trx : pblock->transactions()){
for(auto const& cmd : trx.commands()){
using shared_model::interface::CreateDomain;
domain_created += boost::get<CreateDomain>(&cmd.get()) != nullptr;
//todo domains_removed += boost::get<RemoveDomain>(&cmd.get()) != nullptr;
domain_created += boost::get<CreateDomain>(&cmd.get()) != nullptr; // Check if command is CreateDomain
//todo domain_created -= boost::get<RemoveDomain>(&cmd.get()) != nullptr;
}
signatures_num += boost::size(trx.signatures());
}
#if 1
domains_number_value.Increment(domain_created);
Expand All @@ -115,7 +124,7 @@ Metrics::Metrics(
}
#endif
///---

number_of_signatures_in_last_block.Set(signatures_num);
});
block_subscriber_->subscribe<SubscriptionEngineHandlers::kMetrics>(
0,EventTypes::kOnBlock); //FIXME: I am not sure what is ID and why 0
Expand All @@ -125,7 +134,7 @@ Metrics::Metrics(
on_proposal_subscription_->setCallback(
[&peers_number_value]
(auto, auto, auto key, network::OrderingEvent const &oe) {
// block_height_value can be captured by reference because it is stored inside registry_
// peers_number_value can be captured by reference because it is stored inside registry_
assert(EventTypes::kOnProposal == key);
peers_number_value.Set(oe.ledger_state->ledger_peers.size());
});
Expand Down
4 changes: 0 additions & 4 deletions irohad/maintenance/metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include "ametsuchi/storage.hpp"
#include "logger/logger_fwd.hpp"


struct io_worker;

class Metrics : public std::enable_shared_from_this<Metrics> {
using OnProposalSubscription = iroha::BaseSubscriber<
bool,iroha::network::OrderingEvent>; //FixMe subscribtion ≠ subscriber
Expand All @@ -33,7 +30,6 @@ class Metrics : public std::enable_shared_from_this<Metrics> {
std::shared_ptr<prometheus::Exposer> exposer_;
std::shared_ptr<prometheus::Registry> registry_;
std::shared_ptr<iroha::ametsuchi::Storage> storage_;
// std::shared_ptr<iroha::ametsuchi::WsvQuery> wsv_;
std::shared_ptr<BlockSubscriber> block_subscriber_;
std::shared_ptr<OnProposalSubscription> on_proposal_subscription_;
logger::LoggerPtr logger_;
Expand Down

0 comments on commit 1cd4302

Please sign in to comment.