The reference Nano node has internal stat counters that are used to monitor a number of aspects of the node such as incoming and outgoing tcp traffic, they can be accessed via the stats RPC. While the node is setup to monitor a large number of elements it may be necessary to add your own custom counters for current or future features.
If we wanted to measure the number of incoming messages from our peers we could setup an internal counter with a custom type as traffic_count
and then add an additional detail traffic_incoming
which would be a subset within this custom type. To setup this custom type we need to edit:
case nano::stat::type::vote_generator:
res = "vote_generator";
break;
+ case nano::stat::type::traffic_count:
+ res = "traffic_count";
+ break;
}
return res;
case nano::stat::detail::invalid_network:
res = "invalid_network";
break;
+ case nano::stat::detail::traffic_incoming:
+ res = "traffic_incoming";
+ break;
}
return res;
type
to this public class requests,
filter,
telemetry,
- vote_generator
+ vote_generator,
+ traffic_count
};
detail
to this public class generator_replies_discarded,
- generator_spacing
+ generator_spacing,
+ traffic_incoming
};
nano/node/network.cpp
inside the nano::network::network function: if (message.header.network == id)
{
process_message (message, channel);
+ this->node.stats.inc (nano::stat::type::traffic_count, nano::stat::detail::traffic_incoming);
}
else
{
When testing on the beta network you can get your custom stats using this command:
curl -d '{ "action" : "stats", "type" : "counters" }' 127.0.0.1:55000
This will give an output for example:
"time": "20:45:33",
"type": "traffic_count",
"detail": "all",
"dir": "in",
"value": "5593"
},
{
"time": "20:45:33",
"type": "traffic_count",
"detail": "traffic_incoming",
"dir": "in",
"value": "5593"
}
],
"stat_duration_seconds": "155"