// added to provide string value of set metric static ngx_str_t ngx_http_statsd_set_get_value(ngx_http_request_t *r, ngx_http_complex_value_t *cv, ngx_str_t v) { ngx_str_t val; if (cv == NULL) { return v; } if (ngx_http_complex_value(r, cv, &val) != NGX_OK) { return (ngx_str_t) ngx_null_string; }; return ngx_http_statsd_key_value(&val); };
static char * ngx_http_statsd_add_stat(ngx_conf_t *cf, ngx_command_t *cmd, void *conf, ngx_uint_t type) { ngx_http_statsd_conf_t *ulcf = conf; ngx_http_complex_value_t key_cv; ngx_http_compile_complex_value_t key_ccv; ngx_http_complex_value_t metric_cv; ngx_http_compile_complex_value_t metric_ccv; ngx_http_complex_value_t valid_cv; ngx_http_compile_complex_value_t valid_ccv; ngx_str_t *value; ngx_statsd_stat_t *stat; ngx_int_t n; ngx_str_t s; ngx_flag_t b; value = cf->args->elts; if (ulcf->stats == NULL) { ulcf->stats = ngx_array_create(cf->pool, 10, sizeof(ngx_statsd_stat_t)); if (ulcf->stats == NULL) { return NGX_CONF_ERROR; } } stat = ngx_array_push(ulcf->stats); if (stat == NULL) { return NGX_CONF_ERROR; } ngx_memzero(stat, sizeof(ngx_statsd_stat_t)); stat->type = type; stat->valid = 1; ngx_memzero(&key_ccv, sizeof(ngx_http_compile_complex_value_t)); key_ccv.cf = cf; key_ccv.value = &value[1]; key_ccv.complex_value = &key_cv; if (ngx_http_compile_complex_value(&key_ccv) != NGX_OK) { return NGX_CONF_ERROR; } if (key_cv.lengths == NULL) { s = ngx_http_statsd_key_value(&value[1]); /*if (n < 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"", &value[2]); return NGX_CONF_ERROR; };*/ stat->key = (ngx_str_t) s; } else { stat->ckey = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); if (stat->ckey == NULL) { return NGX_CONF_ERROR; } *stat->ckey = key_cv; } ngx_memzero(&metric_ccv, sizeof(ngx_http_compile_complex_value_t)); metric_ccv.cf = cf; metric_ccv.value = &value[2]; metric_ccv.complex_value = &metric_cv; if (ngx_http_compile_complex_value(&metric_ccv) != NGX_OK) { return NGX_CONF_ERROR; } if (metric_cv.lengths == NULL) { n = ngx_http_statsd_metric_value(&value[2]); if (n < 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"", &value[2]); return NGX_CONF_ERROR; }; stat->metric = (ngx_uint_t) n; } else { stat->cmetric = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); if (stat->cmetric == NULL) { return NGX_CONF_ERROR; } *stat->cmetric = metric_cv; } if (cf->args->nelts > 3) { ngx_memzero(&valid_ccv, sizeof(ngx_http_compile_complex_value_t)); valid_ccv.cf = cf; valid_ccv.value = &value[3]; valid_ccv.complex_value = &valid_cv; if (ngx_http_compile_complex_value(&valid_ccv) != NGX_OK) { return NGX_CONF_ERROR; } if (valid_cv.lengths == NULL) { b = ngx_http_statsd_valid_value(&value[3]); if (b < 0) { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "invalid parameter \"%V\"", &value[3]); return NGX_CONF_ERROR; }; stat->valid = (ngx_flag_t) b; } else { stat->cvalid = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t)); if (stat->cvalid == NULL) { return NGX_CONF_ERROR; } *stat->cvalid = valid_cv; } } return NGX_CONF_OK; }