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

View File

@ -45,7 +45,8 @@ public:
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;
@ -53,8 +54,6 @@ private:
Attribute<String> m_Address;
Attribute<String> m_Port;
int m_ClientsConnected;
void ServerThreadProc(const Socket::Ptr& server);
void ClientThreadProc(const Socket::Ptr& client);
};

View File

@ -44,6 +44,9 @@
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)
{
@ -221,6 +224,13 @@ Query::Query(const std::vector<String>& lines)
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;
@ -382,6 +392,12 @@ void Query::ExecuteGetHelper(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);
ExternalCommandProcessor::Execute(m_Command);
SendResponse(stream, LivestatusErrorOK, "");

View File

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

View File

@ -18,6 +18,7 @@
******************************************************************************/
#include "livestatus/statustable.h"
#include "livestatus/component.h"
#include "icinga/icingaapplication.h"
#include "icinga/cib.h"
#include "base/dynamictype.h"
@ -134,14 +135,12 @@ Value StatusTable::RequestsRateAccessor(const Value& row)
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)
@ -194,14 +193,12 @@ Value StatusTable::LogMessagesRateAccessor(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)
@ -380,8 +377,7 @@ Value StatusTable::LivestatusVersionAccessor(const Value& row)
Value StatusTable::LivestatusActiveConnectionsAccessor(const Value& row)
{
/* TODO */
return Empty;
return LivestatusComponent::GetClientsConnected();
}
Value StatusTable::LivestatusQueuedConnectionsAccessor(const Value& row)