summaryrefslogtreecommitdiffstats
path: root/collectors
diff options
context:
space:
mode:
authorCosta Tsaousis <costa@netdata.cloud>2022-06-01 23:38:41 +0300
committerGitHub <noreply@github.com>2022-06-01 23:38:41 +0300
commit81832edce2b2c0cb8a76ae1d69b99086c974005c (patch)
tree56dede491cd093e36cd1cc278ea2da16d810e3fe /collectors
parent7784a16cc7af8260bb8877873a60d7dc6d2c9e73 (diff)
coverity fixes about statsd; removal of strsame (#13049)
Diffstat (limited to 'collectors')
-rw-r--r--collectors/cgroups.plugin/sys_fs_cgroup.c4
-rw-r--r--collectors/statsd.plugin/statsd.c50
2 files changed, 38 insertions, 16 deletions
diff --git a/collectors/cgroups.plugin/sys_fs_cgroup.c b/collectors/cgroups.plugin/sys_fs_cgroup.c
index 40dafc2686..5676ef8ca1 100644
--- a/collectors/cgroups.plugin/sys_fs_cgroup.c
+++ b/collectors/cgroups.plugin/sys_fs_cgroup.c
@@ -3659,7 +3659,7 @@ static inline void update_cpu_limits2(struct cgroup *cg) {
cg->cpuset_cpus = get_system_cpus();
char *s = "max\n\0";
- if(strsame(s, procfile_lineword(ff, 0, 0)) == 0){
+ if(strcmp(s, procfile_lineword(ff, 0, 0)) == 0){
cg->cpu_cfs_quota = cg->cpu_cfs_period * cg->cpuset_cpus;
} else {
cg->cpu_cfs_quota = str2ull(procfile_lineword(ff, 0, 0));
@@ -3707,7 +3707,7 @@ static inline int update_memory_limits(char **filename, RRDSETVAR **chart_var, u
return 0;
}
char *s = "max\n\0";
- if(strsame(s, buffer) == 0){
+ if(strcmp(s, buffer) == 0){
*value = UINT64_MAX;
rrdsetvar_custom_chart_variable_set(*chart_var, (calculated_number)(*value / (1024 * 1024)));
return 1;
diff --git a/collectors/statsd.plugin/statsd.c b/collectors/statsd.plugin/statsd.c
index 8f4f0691d6..63e3316cb8 100644
--- a/collectors/statsd.plugin/statsd.c
+++ b/collectors/statsd.plugin/statsd.c
@@ -774,10 +774,9 @@ static void statsd_process_metric(const char *name, const char *value, const cha
statsd_parse_field_trim(tagkey, tagkey_end);
statsd_parse_field_trim(tagvalue, tagvalue_end);
- if(tagkey && tagkey && tagvalue && *tagvalue) {
- if (!m->units && strcmp(tagkey, "units") == 0) {
+ if(tagkey && *tagkey && tagvalue && *tagvalue) {
+ if (!m->units && strcmp(tagkey, "units") == 0)
m->units = strdupz(tagvalue);
- }
if (!m->dimname && strcmp(tagkey, "name") == 0)
m->dimname = strdupz(tagvalue);
@@ -1546,23 +1545,46 @@ static inline void statsd_readdir(const char *user_path, const char *stock_path,
// extract chart type and chart id from metric name
static inline void statsd_get_metric_type_and_id(STATSD_METRIC *m, char *type, char *id, char *context, const char *metrictype, size_t len) {
- char *s = NULL;
- snprintfz(type, len, "%s_%s", STATSD_CHART_PREFIX, m->name);
- if(sizeof(STATSD_CHART_PREFIX) + 2 < len)
- for(s = &type[sizeof(STATSD_CHART_PREFIX) + 2]; *s ;s++)
- if(unlikely(*s == '.' || *s == '_')) break;
+ // The full chart type.id looks like this:
+ // ${STATSD_CHART_PREFIX} + "_" + ${METRIC_NAME} + "_" + ${METRIC_TYPE}
+ //
+ // where:
+ // STATSD_CHART_PREFIX = "statsd" as defined above
+ // METRIC_NAME = whatever the user gave to statsd
+ // METRIC_TYPE = "gauge", "counter", "meter", "timer", "histogram", "set", "dictionary"
+
+ // for chart type, we want:
+ // ${STATSD_CHART_PREFIX} + "_" + the first word of ${METRIC_NAME}
+
+ // find the first word of ${METRIC_NAME}
+ char firstword[len + 1], *s = "";
+ strncpyz(firstword, m->name, len);
+ for (s = firstword; *s ; s++) {
+ if (unlikely(*s == '.' || *s == '_')) {
+ *s = '\0';
+ s++;
+ break;
+ }
+ }
+ // firstword has the first word of ${METRIC_NAME}
+ // s has the remaining, if any
+
+ // create the chart type:
+ snprintfz(type, len, STATSD_CHART_PREFIX "_%s", firstword);
- if(s && (*s == '.' || *s == '_')) {
- *s++ = '\0';
+ // for chart id, we want:
+ // the remaining of the words of ${METRIC_NAME} + "_" + ${METRIC_TYPE}
+ // or the ${METRIC_NAME} has no remaining words, the ${METRIC_TYPE} alone
+ if(*s)
snprintfz(id, len, "%s_%s", s, metrictype);
- }
- else {
+ else
snprintfz(id, len, "%s", metrictype);
- }
- snprintfz(context, RRD_ID_LENGTH_MAX, "statsd_%s.%s", metrictype, m->name);
+ // for the context, we want the full of both the above, separated with a dot (type.id):
+ snprintfz(context, RRD_ID_LENGTH_MAX, "%s.%s", type, id);
+ // make sure they don't have illegal characters
netdata_fix_chart_id(type);
netdata_fix_chart_id(id);
netdata_fix_chart_id(context);