Compare commits

...

5 Commits

Author SHA1 Message Date
J. Nick Koston
2166fb8db3 Update esphome/components/statsd/statsd.cpp
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-18 18:54:44 -10:00
J. Nick Koston
7650c91297 switch back to %f 2026-01-18 18:50:02 -10:00
J. Nick Koston
5934b88d2e Merge remote-tracking branch 'upstream/dev' into statsd_stack 2026-01-16 11:35:55 -10:00
J. Nick Koston
5ce4b0c445 tweak 2026-01-16 11:35:52 -10:00
J. Nick Koston
0ea5d7abff [statsd] Use direct appends and stack buffer instead of str_sprintf 2026-01-14 15:27:04 -10:00

View File

@@ -114,14 +114,22 @@ void StatsdComponent::update() {
// This implies you can't explicitly set a gauge to a negative number without first setting it to zero.
if (val < 0) {
if (this->prefix_) {
out.append(str_sprintf("%s.", this->prefix_));
out.append(this->prefix_);
out.append(".");
}
out.append(str_sprintf("%s:0|g\n", s.name));
out.append(s.name);
out.append(":0|g\n");
}
if (this->prefix_) {
out.append(str_sprintf("%s.", this->prefix_));
out.append(this->prefix_);
out.append(".");
}
out.append(str_sprintf("%s:%f|g\n", s.name, val));
out.append(s.name);
// Buffer for ":" + value + "|g\n".
// %f with -DBL_MAX can produce up to 321 chars, plus ":" and "|g\n" (4) + null = 326
char val_buf[330];
buf_append_printf(val_buf, sizeof(val_buf), 0, ":%f|g\n", val);
out.append(val_buf);
if (out.length() > SEND_THRESHOLD) {
this->send_(&out);