Skip to content

Commit

Permalink
track call metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
USA-RedDragon committed Nov 11, 2023
1 parent 88c0ddd commit 88180fe
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions prometheus_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class Prometheus : public Plugin_Api
prometheus::Family<prometheus::Gauge> *active_calls;
prometheus::Family<prometheus::Counter> *calls_counter;
prometheus::Family<prometheus::Counter> *message_counter;
prometheus::Family<prometheus::Counter> *spike_counter;
prometheus::Family<prometheus::Counter> *error_counter;
prometheus::Family<prometheus::Counter> *call_duration_counter;

public:
// Factory method
Expand All @@ -66,7 +69,7 @@ class Prometheus : public Plugin_Api
this->exposer = new Exposer(std::to_string(this->port));
this->registry = std::make_shared<Registry>();

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

this->active_calls = &BuildGauge()
.Name(prefix+"active_calls")
Expand All @@ -88,6 +91,21 @@ class Prometheus : public Plugin_Api
.Help("Message decode count")
.Register(*registry);

this->spike_counter = &BuildCounter()
.Name(prefix+"call_spike_count")
.Help("Spike count")
.Register(*registry);

this->error_counter = &BuildCounter()
.Name(prefix+"call_error_count")
.Help("Error count")
.Register(*registry);

this->call_duration_counter = &BuildCounter()
.Name(prefix+"call_duration")
.Help("Call duration")
.Register(*registry);

this->exposer->RegisterCollectable(this->registry);

return 0;
Expand All @@ -102,7 +120,6 @@ class Prometheus : public Plugin_Api
{
std::map<std::string, int> callsPerSystem;

auto ret = 0;
for (std::vector<Call *>::iterator it = calls.begin(); it != calls.end(); it++)
{
Call *call = *it;
Expand All @@ -122,12 +139,6 @@ class Prometheus : public Plugin_Api
{"encrypted", std::to_string(call->get_encrypted())},
{"talkgroup", std::to_string(call->get_talkgroup())},
}).Increment();

ret = this->update_call_metrics(call);
if (ret != 0)
{
return ret;
}
}

for (auto& callPerSystem : callsPerSystem)
Expand All @@ -136,17 +147,13 @@ class Prometheus : public Plugin_Api
{"system", callPerSystem.first},
}).Set(callPerSystem.second);
}
return ret;
}

int call_start(Call *call) override
{
return this->update_call_metrics(call);
return 0;
}

int call_end(Call_Data_t call_info) override
{
return 0;
return this->update_call_end_metrics(&call_info);
}

int setup_recorder(Recorder *recorder) override
Expand Down Expand Up @@ -184,9 +191,28 @@ class Prometheus : public Plugin_Api

protected:

int update_call_metrics(Call * call) {
this->http_requests_counter->Add({}).Increment();
BOOST_LOG_TRIVIAL(info) << "Updating call metrics";
int update_call_end_metrics(Call_Data_t *call_info) {
// {"system", call_info->system->get_short_name()},
this->call_duration_counter->Add({
{"encrypted", std::to_string(call_info->encrypted)},
{"talkgroup", std::to_string(call_info->talkgroup)},
{"freq", std::to_string(call_info->freq)},
}).Increment(call_info->length);

// {"system", call_info->system->get_short_name()},
this->spike_counter->Add({
{"encrypted", std::to_string(call_info->encrypted)},
{"talkgroup", std::to_string(call_info->talkgroup)},
{"freq", std::to_string(call_info->freq)},
}).Increment(call_info->spike_count);

// {"system", call_info->system->get_short_name()},
this->error_counter->Add({
{"encrypted", std::to_string(call_info->encrypted)},
{"talkgroup", std::to_string(call_info->talkgroup)},
{"freq", std::to_string(call_info->freq)},
}).Increment(call_info->error_count);

return 0;
}

Expand All @@ -205,5 +231,5 @@ class Prometheus : public Plugin_Api

BOOST_DLL_ALIAS(
Prometheus::create, // <-- this function is exported with...
create_plugin // <-- ...this alias name
create_plugin // <-- ...this alias name
)

0 comments on commit 88180fe

Please sign in to comment.