projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
regex match: Fix unexpected match with empty meta data
[collectd.git]
/
src
/
nginx.c
diff --git
a/src/nginx.c
b/src/nginx.c
index
e320ea7
..
7bb307a
100644
(file)
--- a/
src/nginx.c
+++ b/
src/nginx.c
@@
-28,23
+28,23
@@
#include "collectd.h"
#include "collectd.h"
-#include "common.h"
#include "plugin.h"
#include "plugin.h"
+#include "utils/common/common.h"
#include <curl/curl.h>
#include <curl/curl.h>
-static char *url
= NULL
;
-static char *user
= NULL
;
-static char *pass
= NULL
;
-static char *verify_peer
= NULL
;
-static char *verify_host
= NULL
;
-static char *cacert
= NULL
;
-static char *timeout
= NULL
;
+static char *url;
+static char *user;
+static char *pass;
+static char *verify_peer;
+static char *verify_host;
+static char *cacert;
+static char *timeout;
-static CURL *curl
= NULL
;
+static CURL *curl;
static char nginx_buffer[16384];
static char nginx_buffer[16384];
-static size_t nginx_buffer_len
= 0
;
+static size_t nginx_buffer_len;
static char nginx_curl_error[CURL_ERROR_SIZE];
static const char *config_keys[] = {
static char nginx_curl_error[CURL_ERROR_SIZE];
static const char *config_keys[] = {
@@
-62,13
+62,13
@@
static size_t nginx_curl_callback(void *buf, size_t size, size_t nmemb,
}
if (len == 0)
}
if (len == 0)
- return
(len)
;
+ return
len
;
memcpy(&nginx_buffer[nginx_buffer_len], buf, len);
nginx_buffer_len += len;
nginx_buffer[nginx_buffer_len] = 0;
memcpy(&nginx_buffer[nginx_buffer_len], buf, len);
nginx_buffer_len += len;
nginx_buffer[nginx_buffer_len] = 0;
- return
(len)
;
+ return
len
;
}
static int config_set(char **var, const char *value) {
}
static int config_set(char **var, const char *value) {
@@
-78,28
+78,28
@@
static int config_set(char **var, const char *value) {
}
if ((*var = strdup(value)) == NULL)
}
if ((*var = strdup(value)) == NULL)
- return
(1)
;
+ return
1
;
else
else
- return
(0)
;
+ return
0
;
}
static int config(const char *key, const char *value) {
if (strcasecmp(key, "url") == 0)
}
static int config(const char *key, const char *value) {
if (strcasecmp(key, "url") == 0)
- return
(config_set(&url, value)
);
+ return
config_set(&url, value
);
else if (strcasecmp(key, "user") == 0)
else if (strcasecmp(key, "user") == 0)
- return
(config_set(&user, value)
);
+ return
config_set(&user, value
);
else if (strcasecmp(key, "password") == 0)
else if (strcasecmp(key, "password") == 0)
- return
(config_set(&pass, value)
);
+ return
config_set(&pass, value
);
else if (strcasecmp(key, "verifypeer") == 0)
else if (strcasecmp(key, "verifypeer") == 0)
- return
(config_set(&verify_peer, value)
);
+ return
config_set(&verify_peer, value
);
else if (strcasecmp(key, "verifyhost") == 0)
else if (strcasecmp(key, "verifyhost") == 0)
- return
(config_set(&verify_host, value)
);
+ return
config_set(&verify_host, value
);
else if (strcasecmp(key, "cacert") == 0)
else if (strcasecmp(key, "cacert") == 0)
- return
(config_set(&cacert, value)
);
+ return
config_set(&cacert, value
);
else if (strcasecmp(key, "timeout") == 0)
else if (strcasecmp(key, "timeout") == 0)
- return
(config_set(&timeout, value)
);
+ return
config_set(&timeout, value
);
else
else
- return
(-1)
;
+ return
-1
;
} /* int config */
static int init(void) {
} /* int config */
static int init(void) {
@@
-108,7
+108,7
@@
static int init(void) {
if ((curl = curl_easy_init()) == NULL) {
ERROR("nginx plugin: curl_easy_init failed.");
if ((curl = curl_easy_init()) == NULL) {
ERROR("nginx plugin: curl_easy_init failed.");
- return
(-1)
;
+ return
-1
;
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
}
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
@@
-122,11
+122,11
@@
static int init(void) {
curl_easy_setopt(curl, CURLOPT_PASSWORD, (pass == NULL) ? "" : pass);
#else
static char credentials[1024];
curl_easy_setopt(curl, CURLOPT_PASSWORD, (pass == NULL) ? "" : pass);
#else
static char credentials[1024];
- int status = s
s
nprintf(credentials, sizeof(credentials), "%s:%s", user,
-
pass == NULL ? "" : pass);
+ int status = snprintf(credentials, sizeof(credentials), "%s:%s", user,
+ pass == NULL ? "" : pass);
if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
ERROR("nginx plugin: Credentials would have been truncated.");
if ((status < 0) || ((size_t)status >= sizeof(credentials))) {
ERROR("nginx plugin: Credentials would have been truncated.");
- return
(-1)
;
+ return
-1
;
}
curl_easy_setopt(curl, CURLOPT_USERPWD, credentials);
}
curl_easy_setopt(curl, CURLOPT_USERPWD, credentials);
@@
-161,7
+161,7
@@
static int init(void) {
}
#endif
}
#endif
- return
(0)
;
+ return
0
;
} /* void init */
static void submit(const char *type, const char *inst, long long value) {
} /* void init */
static void submit(const char *type, const char *inst, long long value) {
@@
-178,10
+178,8
@@
static void submit(const char *type, const char *inst, long long value) {
return;
vl.values = values;
return;
vl.values = values;
- vl.values_len = 1;
- sstrncpy(vl.host, hostname_g, sizeof(vl.host));
+ vl.values_len = STATIC_ARRAY_SIZE(values);
sstrncpy(vl.plugin, "nginx", sizeof(vl.plugin));
sstrncpy(vl.plugin, "nginx", sizeof(vl.plugin));
- sstrncpy(vl.plugin_instance, "", sizeof(vl.plugin_instance));
sstrncpy(vl.type, type, sizeof(vl.type));
if (inst != NULL)
sstrncpy(vl.type, type, sizeof(vl.type));
if (inst != NULL)
@@
-200,9
+198,9
@@
static int nginx_read(void) {
int fields_num;
if (curl == NULL)
int fields_num;
if (curl == NULL)
- return
(-1)
;
+ return
-1
;
if (url == NULL)
if (url == NULL)
- return
(-1)
;
+ return
-1
;
nginx_buffer_len = 0;
nginx_buffer_len = 0;
@@
-210,7
+208,7
@@
static int nginx_read(void) {
if (curl_easy_perform(curl) != CURLE_OK) {
WARNING("nginx plugin: curl_easy_perform failed: %s", nginx_curl_error);
if (curl_easy_perform(curl) != CURLE_OK) {
WARNING("nginx plugin: curl_easy_perform failed: %s", nginx_curl_error);
- return
(-1)
;
+ return
-1
;
}
ptr = nginx_buffer;
}
ptr = nginx_buffer;
@@
-226,7
+224,7
@@
static int nginx_read(void) {
/*
* Active connections: 291
* server accepts handled requests
/*
* Active connections: 291
* server accepts handled requests
- * 1
6630948 16630948 31070465
+ * 1
01059015 100422216 347910649
* Reading: 6 Writing: 179 Waiting: 106
*/
for (int i = 0; i < lines_num; i++) {
* Reading: 6 Writing: 179 Waiting: 106
*/
for (int i = 0; i < lines_num; i++) {
@@
-240,7
+238,11
@@
static int nginx_read(void) {
} else if ((atoll(fields[0]) != 0) && (atoll(fields[1]) != 0) &&
(atoll(fields[2]) != 0)) {
submit("connections", "accepted", atoll(fields[0]));
} else if ((atoll(fields[0]) != 0) && (atoll(fields[1]) != 0) &&
(atoll(fields[2]) != 0)) {
submit("connections", "accepted", atoll(fields[0]));
+ /* TODO: The legacy metric "handled", which is the sum of "accepted" and
+ * "failed", is reported for backwards compatibility only. Remove in the
+ * next major version. */
submit("connections", "handled", atoll(fields[1]));
submit("connections", "handled", atoll(fields[1]));
+ submit("connections", "failed", (atoll(fields[0]) - atoll(fields[1])));
submit("nginx_requests", NULL, atoll(fields[2]));
}
} else if (fields_num == 6) {
submit("nginx_requests", NULL, atoll(fields[2]));
}
} else if (fields_num == 6) {
@@
-256,7
+258,7
@@
static int nginx_read(void) {
nginx_buffer_len = 0;
nginx_buffer_len = 0;
- return
(0)
;
+ return
0
;
} /* int nginx_read */
void module_register(void) {
} /* int nginx_read */
void module_register(void) {
@@
-264,7
+266,3
@@
void module_register(void) {
plugin_register_init("nginx", init);
plugin_register_read("nginx", nginx_read);
} /* void module_register */
plugin_register_init("nginx", init);
plugin_register_read("nginx", nginx_read);
} /* void module_register */
-
-/*
- * vim: set shiftwidth=2 softtabstop=2 tabstop=8 :
- */