mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-06 21:51:30 +00:00
Merge pull request #630 from btall/reset-after-push
Implement a new metric option 'reset_after_push' which will make uWSGI.....
This commit is contained in:
@@ -321,6 +321,7 @@ struct uwsgi_metric *uwsgi_register_keyval_metric(char *arg) {
|
||||
char *m_initial_value = NULL;
|
||||
char *m_children = NULL;
|
||||
char *m_alias = NULL;
|
||||
char *m_reset_after_push = NULL;
|
||||
|
||||
if (!strchr(arg, '=')) {
|
||||
m_name = uwsgi_str(arg);
|
||||
@@ -340,6 +341,7 @@ struct uwsgi_metric *uwsgi_register_keyval_metric(char *arg) {
|
||||
"arg3n", &m_arg3n,
|
||||
"children", &m_children,
|
||||
"alias", &m_alias,
|
||||
"reset_after_push", &m_reset_after_push,
|
||||
NULL)) {
|
||||
uwsgi_log("invalid metric keyval syntax: %s\n", arg);
|
||||
exit(1);
|
||||
@@ -354,6 +356,7 @@ struct uwsgi_metric *uwsgi_register_keyval_metric(char *arg) {
|
||||
char *collector = NULL;
|
||||
uint32_t freq = 0;
|
||||
int64_t initial_value = 0;
|
||||
uint8_t reset_after_push = 0;
|
||||
|
||||
if (m_type) {
|
||||
if (!strcmp(m_type, "gauge")) {
|
||||
@@ -381,6 +384,10 @@ struct uwsgi_metric *uwsgi_register_keyval_metric(char *arg) {
|
||||
struct uwsgi_metric* um = uwsgi_register_metric(m_name, m_oid, type, collector, NULL, freq, NULL);
|
||||
um->initial_value = initial_value;
|
||||
|
||||
if (m_reset_after_push){
|
||||
um->reset_after_push = 1;
|
||||
}
|
||||
|
||||
if (m_children) {
|
||||
char *p, *ctx = NULL;
|
||||
uwsgi_foreach_token(m_children, ";", p, ctx) {
|
||||
@@ -427,6 +434,7 @@ struct uwsgi_metric *uwsgi_register_keyval_metric(char *arg) {
|
||||
if (m_initial_value) free(m_initial_value);
|
||||
if (m_children) free(m_children);
|
||||
if (m_alias) free(m_alias);
|
||||
if (m_reset_after_push) free(m_reset_after_push);
|
||||
return um;
|
||||
}
|
||||
|
||||
|
||||
@@ -380,6 +380,11 @@ metrics_loop:
|
||||
uwsgi_rlock(uwsgi.metrics_lock);
|
||||
wok = carbon_write(fd, "%s%s.%s.%.*s %llu %llu\n", u_carbon.root_node, u_carbon.hostname, u_carbon.id, um->name_len, um->name, (unsigned long long) *um->value, (unsigned long long) now);
|
||||
uwsgi_rwunlock(uwsgi.metrics_lock);
|
||||
if (um->reset_after_push){
|
||||
uwsgi_wlock(uwsgi.metrics_lock);
|
||||
*um->value = 0;
|
||||
uwsgi_unlock(uwsgi.metrics_lock);
|
||||
}
|
||||
if (!wok) goto clear;
|
||||
um = um->next;
|
||||
}
|
||||
|
||||
@@ -150,6 +150,11 @@ static void rrdtool_push(struct uwsgi_stats_pusher_instance *uspi, time_t now, c
|
||||
uwsgi_rlock(uwsgi.metrics_lock);
|
||||
int ret = snprintf(buf, 1024, "N:%lld", (long long) (*um->value));
|
||||
uwsgi_rwunlock(uwsgi.metrics_lock);
|
||||
if (um->reset_after_push){
|
||||
uwsgi_wlock(uwsgi.metrics_lock);
|
||||
*um->value = 0;
|
||||
uwsgi_unlock(uwsgi.metrics_lock);
|
||||
}
|
||||
if (ret < 3 || ret >= 1024) {
|
||||
uwsgi_log("unable to update rrdtool metric for %s\n", um->name);
|
||||
goto next;
|
||||
|
||||
@@ -92,6 +92,11 @@ static void stats_pusher_socket(struct uwsgi_stats_pusher_instance *uspi, time_t
|
||||
uwsgi_rlock(uwsgi.metrics_lock);
|
||||
socket_send_metric(ub, uspi, um);
|
||||
uwsgi_rwunlock(uwsgi.metrics_lock);
|
||||
if (um->reset_after_push){
|
||||
uwsgi_wlock(uwsgi.metrics_lock);
|
||||
*um->value = 0;
|
||||
uwsgi_unlock(uwsgi.metrics_lock);
|
||||
}
|
||||
um = um->next;
|
||||
}
|
||||
uwsgi_buffer_destroy(ub);
|
||||
|
||||
@@ -95,6 +95,11 @@ static void stats_pusher_statsd(struct uwsgi_stats_pusher_instance *uspi, time_t
|
||||
statsd_send_metric(ub, uspi, um->name, um->name_len, *um->value, "|m");
|
||||
}
|
||||
uwsgi_rwunlock(uwsgi.metrics_lock);
|
||||
if (um->reset_after_push){
|
||||
uwsgi_wlock(uwsgi.metrics_lock);
|
||||
*um->value = 0;
|
||||
uwsgi_unlock(uwsgi.metrics_lock);
|
||||
}
|
||||
um = um->next;
|
||||
}
|
||||
uwsgi_buffer_destroy(ub);
|
||||
|
||||
@@ -94,6 +94,11 @@ static void stats_pusher_zabbix(struct uwsgi_stats_pusher_instance *uspi, time_t
|
||||
if (uwsgi_buffer_append(zn->ub, "\",\"value\":\"", 11)) { error = 1; goto end;}
|
||||
if (uwsgi_buffer_num64(zn->ub, *um->value)) { error = 1; goto end;}
|
||||
if (uwsgi_buffer_append(zn->ub, "\"}", 2)) { error = 1; goto end;}
|
||||
if (um->reset_after_push){
|
||||
uwsgi_wlock(uwsgi.metrics_lock);
|
||||
*um->value = 0;
|
||||
uwsgi_unlock(uwsgi.metrics_lock);
|
||||
}
|
||||
um = um->next;
|
||||
if (um) {
|
||||
if (uwsgi_buffer_append(zn->ub, ",", 1)) { error = 1; goto end;}
|
||||
|
||||
Reference in New Issue
Block a user