Skip to content

Commit

Permalink
Request total stats
Browse files Browse the repository at this point in the history
  • Loading branch information
tudor-timcu committed Jan 7, 2025
1 parent 4124040 commit 8d41d97
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/agent/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.23.3

require (
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.69.0
google.golang.org/grpc v1.69.2
google.golang.org/protobuf v1.35.1
)

Expand Down
2 changes: 2 additions & 0 deletions lib/agent/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0=
google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw=
google.golang.org/grpc v1.69.0 h1:quSiOM1GJPmPH5XtU+BCoVXcDVJJAzNcoyfC2cCjGkI=
google.golang.org/grpc v1.69.0/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
Expand Down
20 changes: 17 additions & 3 deletions lib/php-extension/Stats.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
#include "Includes.h"

std::unordered_map<std::string, SinkStats> stats;
static uint64_t requestTotal = 0;

inline void AddToStats(const std::string& key, uint64_t duration) {
SinkStats& sinkStats = stats[key];
sinkStats.timings.push_back(duration);
}

inline void AddRequestTotalToStats() {
AddToStats("request_total", requestTotal);
requestTotal = 0;
}

ScopedTimer::ScopedTimer() {
this->Start();
Expand Down Expand Up @@ -31,8 +42,11 @@ ScopedTimer::~ScopedTimer() {
return;
}
this->Stop();
SinkStats& sinkStats = stats[this->key];
sinkStats.timings.push_back(this->duration);
requestTotal += this->duration;
if (key == "request_shutdown") {
AddRequestTotalToStats();
}
AddToStats(this->key, this->duration);
}

void SinkStats::IncrementAttacksDetected() {
Expand All @@ -49,4 +63,4 @@ void SinkStats::IncrementInterceptorThrewError() {

void SinkStats::IncrementWithoutContext() {
withoutContext += 1;
}
}
2 changes: 1 addition & 1 deletion lib/request-processor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.23.3

require (
github.com/stretchr/testify v1.10.0
google.golang.org/grpc v1.69.0
google.golang.org/grpc v1.69.2
google.golang.org/protobuf v1.35.1
)

Expand Down
2 changes: 2 additions & 0 deletions lib/request-processor/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0=
google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw=
google.golang.org/grpc v1.69.0 h1:quSiOM1GJPmPH5XtU+BCoVXcDVJJAzNcoyfC2cCjGkI=
google.golang.org/grpc v1.69.0/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/grpc v1.69.2 h1:U3S9QEtbXC0bYNvRtcoklF3xGtLViumSYxWykJS+7AU=
google.golang.org/grpc v1.69.2/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
Expand Down

0 comments on commit 8d41d97

Please sign in to comment.