Skip to content

Commit

Permalink
unit statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
robotastic committed Jan 3, 2024
1 parent aabce26 commit e0fa28c
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion prometheus_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ class Prometheus : public Plugin_Api
uint16_t port;
prometheus::Exposer *exposer;
std::shared_ptr<prometheus::Registry> registry;

prometheus::Family<prometheus::Gauge> *active_units;
prometheus::Family<prometheus::Gauge> *active_calls;
prometheus::Family<prometheus::Gauge> *source_digital_recorders_gauge;
prometheus::Family<prometheus::Gauge> *source_analog_recorders_gauge;
prometheus::Family<prometheus::Counter> *unit_affiliation_counter;
prometheus::Family<prometheus::Counter> *calls_counter;
prometheus::Family<prometheus::Counter> *message_counter;
prometheus::Family<prometheus::Counter> *spike_counter;
Expand Down Expand Up @@ -74,6 +75,11 @@ class Prometheus : public Plugin_Api

auto prefix = std::string("trunk_recorder_");

this->active_units = &BuildGauge()
.Name(prefix+"active_units")
.Help("Number of active units")
.Register(*registry);

this->active_calls = &BuildGauge()
.Name(prefix+"active_calls")
.Help("Number of active calls")
Expand All @@ -93,6 +99,11 @@ class Prometheus : public Plugin_Api
.Name(prefix+"calls")
.Help("Call history")
.Register(*registry);

this->unit_affiliation_counter = &BuildCounter()
.Name(prefix+"units")
.Help("Unit Affiliation history")
.Register(*registry);

this->message_counter = &BuildCounter()
.Name(prefix+"message_decodes")
Expand Down Expand Up @@ -187,6 +198,34 @@ class Prometheus : public Plugin_Api
return ret;
}

int unit_registration(System *sys, long source_id) override
{
this->active_units->Add({
{"system", sys->get_short_name()},
{"source_id", std::to_string(source_id)},
}).Increment();
return 0;
}

int unit_deregistration(System *sys, long source_id) override
{
this->active_units->Add({
{"system", sys->get_short_name()},
{"source_id", std::to_string(source_id)},
}).Decrement();
return 0;
}

int unit_group_affiliation(System *sys, long source_id, long talkgroup_num) override
{
this->unit_affiliation_counter->Add({
{"system", sys->get_short_name()},
{"source_id", std::to_string(source_id)},
{"talkgroup", std::to_string(talkgroup_num)},
}).Increment();
return 0;
}

int system_rates(std::vector<System *> systems, float timeDiff) override
{
for (std::vector<System *>::iterator it = systems.begin(); it != systems.end(); it++)
Expand Down

0 comments on commit e0fa28c

Please sign in to comment.