Module: check_mk
Branch: master
Commit: 46a560ff31e220a251bae78f775384e5203f88b8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=46a560ff31e220…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Apr 2 12:37:09 2013 +0200
* windows_agent: Now buffers output before writing it to the socket
Results in less tcp packages per call
---
ChangeLog | 2 ++
agents/windows/check_mk_agent.cc | 35 ++++++++++++++++++++++++++++-------
agents/windows/check_mk_agent.exe | Bin 111104 -> 111104 bytes
agents/windows/install_agent.exe | Bin 130870 -> 130952 bytes
4 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d8d5d1c..531df24 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -55,6 +55,8 @@
* agent_vsphere: New VMWare ESX monitoring that uses pySphere and the VMWare
API in order to get data very efficiently. Read (upcoming) documentation
for details.
+ * windows_agent: Now buffers output before writing it to the socket
+ Results in less tcp packages per call
Notifications:
* notify.py: unique spoolfiles name no longer created with uuid
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index 2aea327..9fddea0 100755
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -156,6 +156,7 @@ bool verbose_mode = false;
bool g_crash_debug = false;
bool do_tcp = false;
bool should_terminate = false;
+bool force_tcp_output = false; // if true, send socket data immediately
char g_hostname[256];
// sections enabled (configurable in check_mk.ini)
@@ -3076,13 +3077,21 @@ void listen_tcp_loop()
void output(SOCKET &out, const char *format, ...)
{
- static char outbuffer[4096];
-
+ static char outbuffer[16384];
+ static int len = 0;
va_list ap;
va_start(ap, format);
- int len = vsnprintf(outbuffer, sizeof(outbuffer), format, ap);
+ int written_len = vsnprintf(outbuffer + len, sizeof(outbuffer) - len, format, ap);
+ len += written_len;
+
+ // We do not send out the data immediately
+ // This would lead to many small tcp packages
+ bool write_to_socket = false;
+ if (force_tcp_output || len > 1300)
+ write_to_socket = true;
+
if (do_tcp) {
- while (!should_terminate) {
+ while (write_to_socket && !should_terminate) {
int result = send(out, outbuffer, len, 0);
if (result == SOCKET_ERROR) {
debug("send() failed");
@@ -3105,9 +3114,14 @@ void output(SOCKET &out, const char *format, ...)
}
}
else if (result == 0)
- debug("send() returned 0");
- else if (result != len)
- debug("send() sent too few bytes");
+ debug("send() returned 0");
+ else if (result != len) {
+ debug("send() sent too few bytes");
+ len -= result;
+ }
+ else
+ len = 0;
+
break;
}
}
@@ -3202,6 +3216,13 @@ void output_data(SOCKET &out)
section_mrpe(out);
if (enabled_sections & SECTION_SYSTEMTIME)
section_systemtime(out);
+
+ // Send remaining data in out buffer
+ if (do_tcp) {
+ force_tcp_output = true;
+ output(out, "");
+ force_tcp_output = false;
+ }
}
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index e1fbb05..abb7633 100755
Binary files a/agents/windows/check_mk_agent.exe and b/agents/windows/check_mk_agent.exe
differ
diff --git a/agents/windows/install_agent.exe b/agents/windows/install_agent.exe
index 9b001ac..401e933 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ