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 2214fd9
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 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 Down Expand Up @@ -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,27 @@ 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) {
this->call_duration_counter->Add({
{"system", call_info->system->get_short_name()},
{"encrypted", std::to_string(call_info->encrypted)},
{"talkgroup", std::to_string(call_info->talkgroup)},
{"freq", std::to_string(call_info->freq)},
}).Set(call_info->length);

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

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

Expand All @@ -205,5 +230,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 2214fd9

Please sign in to comment.