Permalink
Browse files

Merge pull request #3 from HBOCodeLabs/master

Statsdcc <-> Statsdcc Compatibility Enhancements
  • Loading branch information...
sdomalap committed Aug 11, 2017
2 parents ca1ecb5 + ea0218d commit 1f106c06977a8775b6f4733969e290bb22e9a15c
View
@@ -1 +1,2 @@
build/
.idea/
View
@@ -83,6 +83,8 @@ Example configuration files are in [statsdcc/etc](Logger)
- `name`: A custom name to the program. This name will be prefixed to status metrics generated by statsdcc. The default value is "statsdcc".
- `prefix`: A value that will be appended to all metrics.
- `frequency`: Interval in seconds to flush metrics to each backend. If not specified defaults to 10.
- `percentiles`: For time metrics, calculate the Nth percentile(s). If not specified defaults to [90].
@@ -59,6 +59,9 @@ class Carbon: public statsdcc::backends::Backend {
// prefix for aggregator stats
std::string prefix_stats;
// prefix for all satts
std::string prefix;
};
} // namespace backends
@@ -31,6 +31,8 @@ class AggregatorConfig : public Config {
std::string name; // default: statsdcc
std::string prefix;
int frequency; // default: 10
std::vector<int> percentiles; // default: [90]
View
@@ -43,6 +43,10 @@ void Carbon::flush_stats(const Ledger& ledger, int flusher_id) {
::config->name + ".thread_" +
std::to_string(static_cast<long long int>(flusher_id));
// prefix for all stats
this->prefix =
::config->prefix;
// counters
for (auto counter_itr = ledger.counters.cbegin();
counter_itr != ledger.counters.cend();
@@ -57,7 +61,7 @@ void Carbon::flush_stats(const Ledger& ledger, int flusher_id) {
// get the destination carbon hostport
Hostport n = this->hashring->get(key);
std::string metric_name = this->process_name(key);
std::string metric_name = this->prefix + "counters." + this->process_name(key);
stat_strings[n] +=
metric_name + ".rate"
@@ -79,7 +83,7 @@ void Carbon::flush_stats(const Ledger& ledger, int flusher_id) {
timer_itr != ledger.timer_data.cend();
++timer_itr) {
std::string key = timer_itr->first;
std::string metric_name = this->process_name(key);
std::string metric_name = this->prefix + "timers." + this->process_name(key);
for (auto timer_data_itr = timer_itr->second.cbegin();
timer_data_itr != timer_itr->second.cend();
@@ -104,7 +108,7 @@ void Carbon::flush_stats(const Ledger& ledger, int flusher_id) {
gauge_itr != ledger.gauges.cend();
++gauge_itr) {
std::string key = gauge_itr->first;
std::string metric_name = this->process_name(key);
std::string metric_name = this->prefix + "gauges." + this->process_name(key);
std::string value = std::to_string(
static_cast<long double>(gauge_itr->second));
@@ -123,7 +127,7 @@ void Carbon::flush_stats(const Ledger& ledger, int flusher_id) {
++set_itr) {
std::string key = set_itr->first;
auto value = set_itr->second;
std::string metric_name = this->process_name(key);
std::string metric_name = this->prefix + "sets." + this->process_name(key);
stat_strings[this->hashring->get(key)] +=
metric_name + ".count"
@@ -10,6 +10,10 @@ namespace statsdcc { namespace configs {
AggregatorConfig::AggregatorConfig(const Json::Value& json)
: Config(json) {
this->name = json.get("name", "statsdcc").asString();
this->prefix = json.get("prefix", "").asString();
if(!this->prefix.empty()) {
this->prefix = this->prefix + ".";
}
this->frequency = json.get("frequency", 10).asInt();
View
@@ -168,23 +168,35 @@ void Ledger::process() {
++threshold_itr) {
double pct =
(*threshold_itr < 0) ? -(*threshold_itr) : (*threshold_itr);
// Int is potentially too short since we could have more than 65K metrics in the flush window
unsigned long num_in_threshold = 0;
if (count > 1) {
double num_in_threshold = round(pct / 100 * count);
num_in_threshold = round(pct / 100 * count);
if (0 == num_in_threshold) {
continue;
}
threshold_boundary = values[num_in_threshold - 1];
}
double pct_sum = 0;
for (unsigned long i = 0; i < num_in_threshold; ++i) {
pct_sum += values[i];
}
double pct_mean = pct_sum / num_in_threshold;
// generate pct name
char clean_pct[17] = {0};
snprintf(clean_pct, sizeof(clean_pct), "upper_%g", pct);
snprintf(clean_pct, sizeof(clean_pct), "%g", pct);
for (unsigned int i = 0; i < strlen(clean_pct); ++i) {
clean_pct[i] = ('.' == clean_pct[i]) ? '_' : clean_pct[i];
}
current_timer_data[clean_pct] = threshold_boundary;
current_timer_data[std::string("upper_") + std::string(clean_pct)] = threshold_boundary;
current_timer_data[std::string("count_") + std::string(clean_pct)] = num_in_threshold;
current_timer_data[std::string("sum_") + std::string(clean_pct)] = pct_sum;
current_timer_data[std::string("mean_") + std::string(clean_pct)] = pct_mean;
} // foreach percentile
current_timer_data["upper"] = max;
View
@@ -166,6 +166,9 @@ TEST_F(LedgerTest, timer_data) {
EXPECT_EQ(10, timer_data["timer_data"]["count"]);
EXPECT_EQ(5.5, timer_data["timer_data"]["mean"]);
EXPECT_EQ(9, timer_data["timer_data"]["upper_90"]);
EXPECT_EQ(9, timer_data["timer_data"]["count_90"]);
EXPECT_EQ(45, timer_data["timer_data"]["sum_90"]);
EXPECT_EQ(5, timer_data["timer_data"]["mean_90"]);
}
} // namespace statsdcc

0 comments on commit 1f106c0

Please sign in to comment.