******************************************************************************/
#include "livestatus/component.h"
+#include "base/objectlock.h"
#include "base/dynamictype.h"
#include "base/logger_fwd.h"
#include "base/tcpsocket.h"
REGISTER_TYPE(LivestatusComponent);
+static int l_ClientsConnected = 0;
+static int l_Connections = 0;
+static boost::mutex l_ComponentMutex;
+
LivestatusComponent::LivestatusComponent(const Dictionary::Ptr& serializedUpdate)
: DynamicObject(serializedUpdate)
{
return;
#endif
}
-
- m_ClientsConnected = 0;
}
String LivestatusComponent::GetSocketType(void) const
return service;
}
-int LivestatusComponent::GetClientsConnected(void) const
+int LivestatusComponent::GetClientsConnected(void)
{
- return m_ClientsConnected;
+ boost::mutex::scoped_lock lock(l_ComponentMutex);
+
+ return l_ClientsConnected;
+}
+
+int LivestatusComponent::GetConnections(void)
+{
+ boost::mutex::scoped_lock lock(l_ComponentMutex);
+
+ return l_Connections;
}
void LivestatusComponent::ServerThreadProc(const Socket::Ptr& server)
void LivestatusComponent::ClientThreadProc(const Socket::Ptr& client)
{
- m_ClientsConnected++;
+ {
+ boost::mutex::scoped_lock lock(l_ComponentMutex);
+ l_ClientsConnected++;
+ l_Connections++;
+ }
Stream::Ptr stream = boost::make_shared<NetworkStream>(client);
break;
}
- m_ClientsConnected--;
+ {
+ boost::mutex::scoped_lock lock(l_ComponentMutex);
+ l_ClientsConnected--;
+ }
}
String GetAddress(void) const;
String GetPort(void) const;
- int GetClientsConnected(void) const;
+ static int GetClientsConnected(void);
+ static int GetConnections(void);
private:
Attribute<String> m_SocketType;
Attribute<String> m_Address;
Attribute<String> m_Port;
- int m_ClientsConnected;
-
void ServerThreadProc(const Socket::Ptr& server);
void ClientThreadProc(const Socket::Ptr& client);
};
using namespace icinga;
using namespace livestatus;
+static int l_ExternalCommands = 0;
+static boost::mutex l_QueryMutex;
+
Query::Query(const std::vector<String>& lines)
: m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1)
{
m_Aggregators.swap(aggregators);
}
+int Query::GetExternalCommands(void)
+{
+ boost::mutex::scoped_lock lock(l_QueryMutex);
+
+ return l_ExternalCommands;
+}
+
Filter::Ptr Query::ParseFilter(const String& params)
{
std::vector<String> tokens;
void Query::ExecuteCommandHelper(const Stream::Ptr& stream)
{
+ {
+ boost::mutex::scoped_lock lock(l_QueryMutex);
+
+ l_ExternalCommands++;
+ }
+
Log(LogInformation, "livestatus", "Executing command: " + m_Command);
ExternalCommandProcessor::Execute(m_Command);
SendResponse(stream, LivestatusErrorOK, "");
bool Execute(const Stream::Ptr& stream);
+ static int GetExternalCommands(void);
+
private:
String m_Verb;
******************************************************************************/
#include "livestatus/statustable.h"
+#include "livestatus/component.h"
#include "icinga/icingaapplication.h"
#include "icinga/cib.h"
#include "base/dynamictype.h"
Value StatusTable::ConnectionsAccessor(const Value& row)
{
- /* TODO */
- return Empty;
+ return LivestatusComponent::GetConnections();
}
Value StatusTable::ConnectionsRateAccessor(const Value& row)
{
- /* TODO */
- return Empty;
+ return (LivestatusComponent::GetConnections() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime()));
}
Value StatusTable::ServiceChecksAccessor(const Value& row)
Value StatusTable::ExternalCommandsAccessor(const Value& row)
{
- /* TODO */
- return Empty;
+ return Query::GetExternalCommands();
}
Value StatusTable::ExternalCommandsRateAccessor(const Value& row)
{
- /* TODO */
- return Empty;
+ return (Query::GetExternalCommands() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime()));
}
Value StatusTable::LivechecksAccessor(const Value& row)
Value StatusTable::LivestatusActiveConnectionsAccessor(const Value& row)
{
- /* TODO */
- return Empty;
+ return LivestatusComponent::GetClientsConnected();
}
Value StatusTable::LivestatusQueuedConnectionsAccessor(const Value& row)