livestatus: add connections and extcmds to status table

refs #4372
This commit is contained in:
Michael Friedrich 2013-07-19 15:42:00 +02:00
parent c2f43775b8
commit 669e3764bd
5 changed files with 51 additions and 19 deletions

View File

@ -18,6 +18,7 @@
******************************************************************************/ ******************************************************************************/
#include "livestatus/component.h" #include "livestatus/component.h"
#include "base/objectlock.h"
#include "base/dynamictype.h" #include "base/dynamictype.h"
#include "base/logger_fwd.h" #include "base/logger_fwd.h"
#include "base/tcpsocket.h" #include "base/tcpsocket.h"
@ -31,6 +32,10 @@ using namespace livestatus;
REGISTER_TYPE(LivestatusComponent); REGISTER_TYPE(LivestatusComponent);
static int l_ClientsConnected = 0;
static int l_Connections = 0;
static boost::mutex l_ComponentMutex;
LivestatusComponent::LivestatusComponent(const Dictionary::Ptr& serializedUpdate) LivestatusComponent::LivestatusComponent(const Dictionary::Ptr& serializedUpdate)
: DynamicObject(serializedUpdate) : DynamicObject(serializedUpdate)
{ {
@ -65,8 +70,6 @@ void LivestatusComponent::Start(void)
return; return;
#endif #endif
} }
m_ClientsConnected = 0;
} }
String LivestatusComponent::GetSocketType(void) const String LivestatusComponent::GetSocketType(void) const
@ -105,9 +108,18 @@ String LivestatusComponent::GetPort(void) const
return service; 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::ServerThreadProc(const Socket::Ptr& server)
@ -126,7 +138,11 @@ void LivestatusComponent::ServerThreadProc(const Socket::Ptr& server)
void LivestatusComponent::ClientThreadProc(const Socket::Ptr& client) 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); Stream::Ptr stream = boost::make_shared<NetworkStream>(client);
@ -148,5 +164,8 @@ void LivestatusComponent::ClientThreadProc(const Socket::Ptr& client)
break; break;
} }
m_ClientsConnected--; {
boost::mutex::scoped_lock lock(l_ComponentMutex);
l_ClientsConnected--;
}
} }

View File

@ -45,7 +45,8 @@ public:
String GetAddress(void) const; String GetAddress(void) const;
String GetPort(void) const; String GetPort(void) const;
int GetClientsConnected(void) const; static int GetClientsConnected(void);
static int GetConnections(void);
private: private:
Attribute<String> m_SocketType; Attribute<String> m_SocketType;
@ -53,8 +54,6 @@ private:
Attribute<String> m_Address; Attribute<String> m_Address;
Attribute<String> m_Port; Attribute<String> m_Port;
int m_ClientsConnected;
void ServerThreadProc(const Socket::Ptr& server); void ServerThreadProc(const Socket::Ptr& server);
void ClientThreadProc(const Socket::Ptr& client); void ClientThreadProc(const Socket::Ptr& client);
}; };

View File

@ -44,6 +44,9 @@
using namespace icinga; using namespace icinga;
using namespace livestatus; using namespace livestatus;
static int l_ExternalCommands = 0;
static boost::mutex l_QueryMutex;
Query::Query(const std::vector<String>& lines) Query::Query(const std::vector<String>& lines)
: m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1) : m_KeepAlive(false), m_OutputFormat("csv"), m_ColumnHeaders(true), m_Limit(-1)
{ {
@ -221,6 +224,13 @@ Query::Query(const std::vector<String>& lines)
m_Aggregators.swap(aggregators); 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) Filter::Ptr Query::ParseFilter(const String& params)
{ {
std::vector<String> tokens; std::vector<String> tokens;
@ -382,6 +392,12 @@ void Query::ExecuteGetHelper(const Stream::Ptr& stream)
void Query::ExecuteCommandHelper(const Stream::Ptr& stream) void Query::ExecuteCommandHelper(const Stream::Ptr& stream)
{ {
{
boost::mutex::scoped_lock lock(l_QueryMutex);
l_ExternalCommands++;
}
Log(LogInformation, "livestatus", "Executing command: " + m_Command); Log(LogInformation, "livestatus", "Executing command: " + m_Command);
ExternalCommandProcessor::Execute(m_Command); ExternalCommandProcessor::Execute(m_Command);
SendResponse(stream, LivestatusErrorOK, ""); SendResponse(stream, LivestatusErrorOK, "");

View File

@ -51,6 +51,8 @@ public:
bool Execute(const Stream::Ptr& stream); bool Execute(const Stream::Ptr& stream);
static int GetExternalCommands(void);
private: private:
String m_Verb; String m_Verb;

View File

@ -18,6 +18,7 @@
******************************************************************************/ ******************************************************************************/
#include "livestatus/statustable.h" #include "livestatus/statustable.h"
#include "livestatus/component.h"
#include "icinga/icingaapplication.h" #include "icinga/icingaapplication.h"
#include "icinga/cib.h" #include "icinga/cib.h"
#include "base/dynamictype.h" #include "base/dynamictype.h"
@ -134,14 +135,12 @@ Value StatusTable::RequestsRateAccessor(const Value& row)
Value StatusTable::ConnectionsAccessor(const Value& row) Value StatusTable::ConnectionsAccessor(const Value& row)
{ {
/* TODO */ return LivestatusComponent::GetConnections();
return Empty;
} }
Value StatusTable::ConnectionsRateAccessor(const Value& row) Value StatusTable::ConnectionsRateAccessor(const Value& row)
{ {
/* TODO */ return (LivestatusComponent::GetConnections() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime()));
return Empty;
} }
Value StatusTable::ServiceChecksAccessor(const Value& row) Value StatusTable::ServiceChecksAccessor(const Value& row)
@ -194,14 +193,12 @@ Value StatusTable::LogMessagesRateAccessor(const Value& row)
Value StatusTable::ExternalCommandsAccessor(const Value& row) Value StatusTable::ExternalCommandsAccessor(const Value& row)
{ {
/* TODO */ return Query::GetExternalCommands();
return Empty;
} }
Value StatusTable::ExternalCommandsRateAccessor(const Value& row) Value StatusTable::ExternalCommandsRateAccessor(const Value& row)
{ {
/* TODO */ return (Query::GetExternalCommands() / (Utility::GetTime() - IcingaApplication::GetInstance()->GetStartTime()));
return Empty;
} }
Value StatusTable::LivechecksAccessor(const Value& row) Value StatusTable::LivechecksAccessor(const Value& row)
@ -380,8 +377,7 @@ Value StatusTable::LivestatusVersionAccessor(const Value& row)
Value StatusTable::LivestatusActiveConnectionsAccessor(const Value& row) Value StatusTable::LivestatusActiveConnectionsAccessor(const Value& row)
{ {
/* TODO */ return LivestatusComponent::GetClientsConnected();
return Empty;
} }
Value StatusTable::LivestatusQueuedConnectionsAccessor(const Value& row) Value StatusTable::LivestatusQueuedConnectionsAccessor(const Value& row)