From 3ce3305e4ee4d7e34334dc96b7eb0c66af95dcd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Mat=C4=9Bjka?= Date: Sun, 15 Dec 2024 13:28:24 +0100 Subject: [PATCH] message-queue/cpp/src: wip postgres metrics refs #6 --- message-queue/cpp/src/instance.cpp | 4 +++- message-queue/cpp/src/instance.hpp | 2 ++ message-queue/cpp/src/postgres.cpp | 5 +++++ message-queue/cpp/src/postgres.hpp | 24 ++++++++++++++++++++++++ message-queue/cpp/src/runtime.hpp | 1 + 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 message-queue/cpp/src/postgres.cpp create mode 100644 message-queue/cpp/src/postgres.hpp diff --git a/message-queue/cpp/src/instance.cpp b/message-queue/cpp/src/instance.cpp index ce591d4..070d1b4 100644 --- a/message-queue/cpp/src/instance.cpp +++ b/message-queue/cpp/src/instance.cpp @@ -1,6 +1,8 @@ #include "./instance.hpp" -Instance::Instance() : prometheus(Prometheus(config)) {} +Instance::Instance() +: prometheus(Prometheus(config)), pg(Postgres(config)) +{} prometheus::Labels mk_labels(const Instance& app, const WorkerResult& wr, const SampleDesc& sdesc) { Labels labels = app.runtime.Map(); diff --git a/message-queue/cpp/src/instance.hpp b/message-queue/cpp/src/instance.hpp index 59acc38..1ff2672 100644 --- a/message-queue/cpp/src/instance.hpp +++ b/message-queue/cpp/src/instance.hpp @@ -4,6 +4,7 @@ #include #include "./config.hpp" +#include "./postgres.hpp" #include "./primitives.hpp" #include "./prometheus.hpp" #include "./runtime.hpp" @@ -15,6 +16,7 @@ class Instance { Config config; Runtime runtime; Prometheus prometheus; + Postgres pg; Instance(); }; diff --git a/message-queue/cpp/src/postgres.cpp b/message-queue/cpp/src/postgres.cpp new file mode 100644 index 0000000..05ba6ab --- /dev/null +++ b/message-queue/cpp/src/postgres.cpp @@ -0,0 +1,5 @@ +#include "postgres.hpp" + +Postgres::Postgres(Config &c) +: conn(connection("postgres://mq@localhost/mq")) { +} diff --git a/message-queue/cpp/src/postgres.hpp b/message-queue/cpp/src/postgres.hpp new file mode 100644 index 0000000..0220280 --- /dev/null +++ b/message-queue/cpp/src/postgres.hpp @@ -0,0 +1,24 @@ +#ifndef POSTGRES_CPP +#define POSTGRES_CPP + +#include + +#include + +#include "config.hpp" +#include "runtime.hpp" +#include "primitives.hpp" + +using namespace std; +using namespace pqxx; + +class Postgres { + connection conn; + optional runtime_id = nullopt; + +public: + Postgres(Config&); + void Push(Runtime&, SampleDesc&, Results&); +}; + +#endif diff --git a/message-queue/cpp/src/runtime.hpp b/message-queue/cpp/src/runtime.hpp index efa44af..e0d1f1c 100644 --- a/message-queue/cpp/src/runtime.hpp +++ b/message-queue/cpp/src/runtime.hpp @@ -45,4 +45,5 @@ class Runtime { return ss.str(); } }; + #endif