summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6f618e6)
raw | patch | inline | side by side (parent: 6f618e6)
author | Paul Sadauskas <psadauskas@gmail.com> | |
Mon, 22 Jun 2009 20:10:17 +0000 (14:10 -0600) | ||
committer | Florian Forster <octo@leeloo.lan.home.verplant.org> | |
Fri, 21 Aug 2009 06:41:53 +0000 (08:41 +0200) |
src/http.c | patch | blob | history |
diff --git a/src/http.c b/src/http.c
index d891ab006603cc7457642df9097e03538c0336ce..995368c91114ed633b821b50503f370af14da478 100644 (file)
--- a/src/http.c
+++ b/src/http.c
CURL *curl;
char curl_errbuf[CURL_ERROR_SIZE];
+#define SEND_BUFFER_SIZE 4096
+static char send_buffer[SEND_BUFFER_SIZE];
+static char *send_buffer_ptr;
+static int send_buffer_fill;
+
static pthread_mutex_t send_lock = PTHREAD_MUTEX_INITIALIZER;
static int http_init(void) /* {{{ */
return (0);
} /* }}} int http_config */
+static void http_init_buffer (void) /* {{{ */
+{
+ memset (send_buffer, 0, sizeof (send_buffer));
+ send_buffer_ptr = send_buffer;
+ send_buffer_fill = 0;
+} /* }}} http_init_buffer */
+
+static void http_send_buffer (char *buffer) /* {{{ */
+{
+ printf("Sending: --------\n");
+ printf(buffer);
+ printf("---------------\n");
+
+ int status = 0;
+ curl_easy_setopt (curl, CURLOPT_POSTFIELDS, buffer);
+ status = curl_easy_perform (curl);
+ if (status != 0)
+ {
+ ERROR ("http plugin: curl_easy_perform failed with staus %i: %s",
+ status, curl_errbuf);
+ }
+} /* }}} http_send_buffer */
+
+static void http_flush_buffer (void) /* {{{ */
+{
+ DEBUG ("http plugin: flush_buffer: send_buffer_fill = %i",
+ send_buffer_fill);
+
+ http_send_buffer (send_buffer);
+ http_init_buffer ();
+} /* }}} http_flush_buffer */
+
static int http_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
user_data_t __attribute__((unused)) *user_data)
{
char value[512];
char timestamp[512];
- char csv_buffer[1024];
-
int status;
- int offset = 0;
int i;
if (0 != strcmp (ds->type, vl->type)) {
@@ -335,27 +369,26 @@ static int http_write (const data_set_t *ds, const value_list_t *vl, /* {{{ */
escape_string (metric_name, sizeof (metric_name));
- status = ssnprintf (csv_buffer + offset, sizeof (csv_buffer) - offset,
+ pthread_mutex_lock (&send_lock);
+
+ status = ssnprintf (send_buffer + send_buffer_fill, sizeof (send_buffer) - send_buffer_fill,
"\"%s\",%s,%s\n",
metric_name, timestamp, value);
- offset += status;
+ send_buffer_fill += status;
- } /* for */
+ printf(send_buffer);
+ printf("Fill: %i\n", send_buffer_fill);
+ printf("----\n");
- printf(csv_buffer);
+ if ((sizeof (send_buffer) - send_buffer_fill) < 128)
+ {
+ http_flush_buffer();
+ }
- pthread_mutex_lock (&send_lock);
+ pthread_mutex_unlock (&send_lock);
- curl_easy_setopt (curl, CURLOPT_POSTFIELDS, csv_buffer);
- status = curl_easy_perform (curl);
- if (status != 0)
- {
- ERROR ("curl plugin: curl_easy_perform failed with staus %i: %s",
- status, curl_errbuf);
- return (-1);
- }
+ } /* for */
- pthread_mutex_unlock (&send_lock);
return (0);