2019-11-02 14:00:06 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2018-06-08 11:38:36 +02:00
|
|
|
|
2019-10-29 18:36:16 +01:00
|
|
|
#include "icingadb/icingadb.hpp"
|
2021-09-10 17:47:44 +02:00
|
|
|
#include "base/application.hpp"
|
2018-06-08 11:38:36 +02:00
|
|
|
#include "base/json.hpp"
|
|
|
|
#include "base/logger.hpp"
|
|
|
|
#include "base/serializer.hpp"
|
|
|
|
#include "base/statsfunction.hpp"
|
|
|
|
#include "base/convert.hpp"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2019-10-29 17:32:29 +01:00
|
|
|
Dictionary::Ptr IcingaDB::GetStats()
|
2018-06-08 11:38:36 +02:00
|
|
|
{
|
2018-06-08 12:47:45 +02:00
|
|
|
Dictionary::Ptr stats = new Dictionary();
|
|
|
|
|
2018-06-08 11:38:36 +02:00
|
|
|
//TODO: Figure out if more stats can be useful here.
|
2018-09-18 15:47:44 +02:00
|
|
|
Namespace::Ptr statsFunctions = ScriptGlobal::Get("StatsFunctions", &Empty);
|
2018-06-08 11:38:36 +02:00
|
|
|
|
|
|
|
if (!statsFunctions)
|
|
|
|
Dictionary::Ptr();
|
|
|
|
|
2018-06-08 12:47:45 +02:00
|
|
|
ObjectLock olock(statsFunctions);
|
|
|
|
|
2018-09-18 15:47:44 +02:00
|
|
|
for (auto& kv : statsFunctions)
|
2018-06-08 12:47:45 +02:00
|
|
|
{
|
2023-01-03 12:02:51 +01:00
|
|
|
Function::Ptr func = kv.second.Val;
|
2018-06-08 11:38:36 +02:00
|
|
|
|
2018-06-08 12:47:45 +02:00
|
|
|
if (!func)
|
|
|
|
BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid status function name."));
|
2018-06-08 11:38:36 +02:00
|
|
|
|
2018-06-08 12:47:45 +02:00
|
|
|
Dictionary::Ptr status = new Dictionary();
|
|
|
|
Array::Ptr perfdata = new Array();
|
|
|
|
func->Invoke({ status, perfdata });
|
2018-06-08 11:38:36 +02:00
|
|
|
|
2018-06-08 12:47:45 +02:00
|
|
|
stats->Set(kv.first, new Dictionary({
|
|
|
|
{ "status", status },
|
|
|
|
{ "perfdata", Serialize(perfdata, FAState) }
|
|
|
|
}));
|
|
|
|
}
|
2018-06-08 11:38:36 +02:00
|
|
|
|
2021-09-10 17:47:44 +02:00
|
|
|
typedef Dictionary::Ptr DP;
|
|
|
|
DP app = DP(DP(DP(stats->Get("IcingaApplication"))->Get("status"))->Get("icingaapplication"))->Get("app");
|
2019-12-02 14:46:10 +01:00
|
|
|
|
2021-09-10 17:47:44 +02:00
|
|
|
app->Set("program_start", TimestampToMilliseconds(Application::GetStartTime()));
|
2019-12-02 14:46:10 +01:00
|
|
|
|
2021-09-10 17:47:44 +02:00
|
|
|
auto localEndpoint (Endpoint::GetLocalEndpoint());
|
|
|
|
if (localEndpoint) {
|
|
|
|
app->Set("endpoint_id", GetObjectIdentifier(localEndpoint));
|
2019-12-02 14:46:10 +01:00
|
|
|
}
|
|
|
|
|
2018-06-08 12:47:45 +02:00
|
|
|
return stats;
|
2018-06-08 11:38:36 +02:00
|
|
|
}
|