Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Pryakhin <[email protected]>
  • Loading branch information
waldgange committed Oct 20, 2023
1 parent d493346 commit 250746a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
13 changes: 9 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,15 @@ else()
endif()

if (installBMQPLUGINS)
set(BMQ_TARGET_MWC_NEEDED YES)
set(BMQ_TARGET_BMQ_NEEDED YES)
set(BMQ_TARGET_MQB_NEEDED YES)
set(BMQ_TARGET_PLUGINS_NEEDED YES)
set(BMQ_TARGET_BMQBRKR_NEEDED YES)
set(BMQ_TARGET_BMQBRKRCFG_NEEDED YES)
set(BMQ_TARGET_BMQTOOL_NEEDED YES)
set(BMQ_TARGET_MWC_NEEDED YES)
set(BMQ_TARGET_BMQ_NEEDED YES)
set(BMQ_TARGET_MQB_NEEDED YES)
set(BMQ_TARGET_E_BMQBRKR_NEEDED YES)
set(BMQ_TARGET_TUTORIAL_NEEDED YES)
set(BMQ_TARGET_PLUGINS_NEEDED YES)
endif()
endif()

Expand Down
8 changes: 4 additions & 4 deletions docker/plugins/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
global:
scrape_interval: 5s
evaluation_interval: 5s
scrape_interval: 10s
evaluation_interval: 10s

scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']

- job_name: 'gateway'
scrape_interval: 1s
scrape_interval: 10s
static_configs:
- targets: ['host.docker.internal:9091']
labels:
group: 'pushgateway'

- job_name: 'bmq'
scrape_interval: 1s
scrape_interval: 10s
static_configs:
- targets: ['host.docker.internal:8080']
labels:
Expand Down
51 changes: 30 additions & 21 deletions src/plugins/plugins_prometheusstatconsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,30 @@ class Tagger {
prometheus::Labels& getLabels() { return labels; }
};

} // close unnamed namespace

bsl::unique_ptr<PrometheusStatExporter>
makeExporter(const bsl::string& mode,
const bsl::string& host,
const bsl::size_t port,
std::shared_ptr<prometheus::Registry>& registry);

} // close unnamed namespace

// ----------------------------
// class PrometheusStatConsumer
// ----------------------------

void PrometheusStatConsumer::stopImpl()
{
if (!d_isStarted || !d_prometheusStatExporter_p) {
return; // RETURN
}
d_prometheusStatExporter_p->stop();
d_isStarted = false;
}

PrometheusStatConsumer::~PrometheusStatConsumer()
{
stop();
stopImpl();
}

PrometheusStatConsumer::PrometheusStatConsumer(
Expand Down Expand Up @@ -162,17 +171,6 @@ int PrometheusStatConsumer::start(
return -1; // RETURN
}

if (!d_prometheusStatExporter_p) {
d_prometheusStatExporter_p = makeExporter(d_consumerConfig_p->mode(),
d_consumerConfig_p->host(),
d_consumerConfig_p->port(),
d_prometheusRegistry_p);
}
if (!d_prometheusStatExporter_p) {
return -2; // RETURN
}
d_prometheusStatExporter_p->start();

const mqbcfg::AppConfig& brkrCfg = mqbcfg::BrokerConfig::get();
d_publishInterval = d_consumerConfig_p->publishInterval();
d_snapshotInterval = brkrCfg.stats().snapshotInterval();
Expand All @@ -185,18 +183,25 @@ int PrometheusStatConsumer::start(

d_snapshotId = static_cast<int>(d_publishInterval.seconds() /
d_snapshotInterval.seconds());
d_isStarted = true;

if (!d_prometheusStatExporter_p) {
d_prometheusStatExporter_p = makeExporter(d_consumerConfig_p->mode(),
d_consumerConfig_p->host(),
d_consumerConfig_p->port(),
d_prometheusRegistry_p);
}
if (!d_prometheusStatExporter_p) {
return -2; // RETURN
}
d_prometheusStatExporter_p->start();

d_isStarted = true;
return 0;
}

void PrometheusStatConsumer::stop()
{
if (!d_isStarted) {
return; // RETURN
}

d_prometheusStatExporter_p->stop();
d_isStarted = false;
stopImpl();
}

void PrometheusStatConsumer::onSnapshot()
Expand Down Expand Up @@ -884,6 +889,8 @@ class PrometheusPushStatExporter : public PrometheusStatExporter {
void stop() override { stopImpl(); }
};

namespace {

bsl::unique_ptr<PrometheusStatExporter>
makeExporter(const bsl::string& mode,
const bsl::string& host,
Expand All @@ -908,6 +915,8 @@ makeExporter(const bsl::string& mode,
return result;
}

} // close unnamed namespace

} // close package namespace
} // close enterprise namespace

Expand Down
3 changes: 3 additions & 0 deletions src/plugins/plugins_prometheusstatconsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ class PrometheusStatConsumer : public mqbplug::StatConsumer {
const prometheus::Labels& labels,
const bsls::Types::Int64 value);

/// Stop plugin
void stopImpl();

public:
// NOT IMPLEMENTED

Expand Down

0 comments on commit 250746a

Please sign in to comment.