mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
PerfData: Server Timeouts for InfluxDB Writer
Exposes the TCP socket used to communicate with the InfluxDB server. When we are expecing a response we can now call poll() on the socket to wait for data to become available. If it doesn't in a user configurable timeout period we abort the request. fixes #4927 fixes #4941 Signed-off-by: Michael Friedrich <michael.friedrich@icinga.com>
This commit is contained in:
parent
1373a5e788
commit
041772fb28
@ -933,6 +933,7 @@ Configuration Attributes:
|
||||
enable_send_metadata | **Optional.** Whether to send check metadata e.g. states, execution time, latency etc.
|
||||
flush_interval | **Optional.** How long to buffer data points before transfering to InfluxDB. Defaults to `10s`.
|
||||
flush_threshold | **Optional.** How many data points to buffer before forcing a transfer to InfluxDB. Defaults to `1024`.
|
||||
socket_timeout | **Optional.** How long to wait for InfluxDB to respond. Defaults to `5s`.
|
||||
|
||||
### <a id="objecttype-influxdbwriter-instance-tags"></a> Instance Tagging
|
||||
|
||||
|
@ -78,9 +78,9 @@ void InfluxdbWriter::Start(bool runtimeCreated)
|
||||
Service::OnNewCheckResult.connect(boost::bind(&InfluxdbWriter::CheckResultHandler, this, _1, _2));
|
||||
}
|
||||
|
||||
Stream::Ptr InfluxdbWriter::Connect(void)
|
||||
Stream::Ptr InfluxdbWriter::Connect(TcpSocket::Ptr& socket)
|
||||
{
|
||||
TcpSocket::Ptr socket = new TcpSocket();
|
||||
socket = new TcpSocket();
|
||||
|
||||
Log(LogNotice, "InfluxdbWriter")
|
||||
<< "Reconnecting to InfluxDB on host '" << GetHost() << "' port '" << GetPort() << "'.";
|
||||
@ -345,7 +345,8 @@ void InfluxdbWriter::FlushTimeout(void)
|
||||
|
||||
void InfluxdbWriter::Flush(void)
|
||||
{
|
||||
Stream::Ptr stream = Connect();
|
||||
TcpSocket::Ptr socket;
|
||||
Stream::Ptr stream = Connect(socket);
|
||||
|
||||
// Unable to connect, play it safe and lose the data points
|
||||
// to avoid a memory leak
|
||||
@ -391,6 +392,13 @@ void InfluxdbWriter::Flush(void)
|
||||
HttpResponse resp(stream, req);
|
||||
StreamReadContext context;
|
||||
|
||||
struct timeval timeout = { GetSocketTimeout(), 0 };
|
||||
if (!socket->Poll(true, false, &timeout)) {
|
||||
Log(LogWarning, "InfluxdbWriter")
|
||||
<< "Response timeout of TCP socket from host '" << GetHost() << "' port '" << GetPort() << "'.";
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
resp.Parse(context, true);
|
||||
} catch (const std::exception&) {
|
||||
|
@ -65,7 +65,7 @@ private:
|
||||
static String EscapeKey(const String& str);
|
||||
static String EscapeField(const String& str);
|
||||
|
||||
Stream::Ptr Connect(void);
|
||||
Stream::Ptr Connect(TcpSocket::Ptr& socket);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -90,6 +90,9 @@ class InfluxdbWriter : ConfigObject
|
||||
[config] int flush_threshold {
|
||||
default {{{ return 1024; }}}
|
||||
};
|
||||
[config] int socket_timeout {
|
||||
default {{{ return 5; }}}
|
||||
};
|
||||
};
|
||||
|
||||
validator InfluxdbWriter {
|
||||
|
Loading…
x
Reference in New Issue
Block a user