-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add libprometheus-cpp as a submodule. Use it to publish information about the number of connected peers in the DHT. To experiment with it, run prometheus (e.g., `prometheus --config.file prometheus/infinit-prometheus.yml`) and monitor `infinit_overlay_peers` while, for instance running `tests/overlay` or `tests/prometheus`.
- Loading branch information
Showing
14 changed files
with
309 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,6 @@ TAGS | |
__pycache__ | ||
*node_modules* | ||
/_build/*/.drake | ||
|
||
# when running Prometheus from here. | ||
/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# my global config | ||
global: | ||
scrape_interval: 15s # Default is every 1 minute. | ||
evaluation_interval: 15s # Default is every 1 minute. | ||
# scrape_timeout is set to the global default (10s). | ||
|
||
scrape_configs: | ||
- job_name: 'infinit' | ||
static_configs: | ||
- targets: ['localhost:8080'] |
Submodule prometheus-cpp
added at
b07ba6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include <infinit/model/prometheus.hh> | ||
|
||
#include <boost/exception/diagnostic_information.hpp> | ||
|
||
#include <elle/log.hh> | ||
#include <elle/os/environ.hh> | ||
|
||
#include <prometheus/exposer.h> | ||
#include <prometheus/registry.h> | ||
|
||
ELLE_LOG_COMPONENT("infinit.prometheus"); | ||
|
||
namespace | ||
{ | ||
auto prometheus_endpoint | ||
= elle::os::getenv("INFINIT_PROMETHEUS_ENDPOINT", "127.0.0.1:8080"); | ||
} | ||
|
||
namespace infinit | ||
{ | ||
namespace prometheus | ||
{ | ||
void prometheus_endpoint(std::string e) | ||
{ | ||
::prometheus_endpoint = std::move(e); | ||
} | ||
|
||
std::string const& prometheus_endpoint() | ||
{ | ||
return ::prometheus_endpoint; | ||
} | ||
|
||
/// An HTTP server to answer Prometheus's requests. | ||
/// | ||
/// Maybe nullptr if set up failed. | ||
::prometheus::Exposer* | ||
exposer() | ||
{ | ||
static auto res = []() -> std::unique_ptr<::prometheus::Exposer> { | ||
auto const addr = prometheus_endpoint(); | ||
if (addr != "no" || addr != "0") | ||
try | ||
{ | ||
ELLE_LOG("exposer: create: %s", addr); | ||
auto res = std::make_unique<::prometheus::Exposer>(addr); | ||
ELLE_LOG("exposer: creation succeeded"); | ||
return res; | ||
} | ||
catch (std::exception const& e) | ||
{ | ||
ELLE_LOG("exposer: creation failed," | ||
" metrics will not be exposed: %s", e); | ||
} | ||
catch (...) | ||
{ | ||
ELLE_LOG("exposer: creation failed with unknown" | ||
" exception type: %s", | ||
boost::current_exception_diagnostic_information()); | ||
} | ||
return {}; | ||
}(); | ||
return res.get(); | ||
} | ||
|
||
|
||
/// Where to register the measurements to expose to Prometheus. | ||
std::shared_ptr<::prometheus::Registry> | ||
registry() | ||
{ | ||
// Build and ask the exposer to scrape the registry on incoming | ||
// scrapes. | ||
static auto res = []() -> std::shared_ptr<::prometheus::Registry> | ||
{ | ||
if (auto e = exposer()) | ||
{ | ||
auto res = std::make_shared<::prometheus::Registry>(); | ||
e->RegisterCollectable(res); | ||
return res; | ||
} | ||
else | ||
return nullptr; | ||
}(); | ||
return res; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
#include <prometheus/registry.h> | ||
|
||
namespace prometheus | ||
{ | ||
class Exposer; | ||
} | ||
|
||
namespace infinit | ||
{ | ||
namespace prometheus | ||
{ | ||
/// Set the Prometheus publishing address. | ||
void prometheus_endpoint(std::string e); | ||
|
||
/// Get the Prometheus publishing address. | ||
std::string const& prometheus_endpoint(); | ||
|
||
/// An HTTP server to answer Prometheus's requests. | ||
/// | ||
/// Maybe nullptr if set up failed. | ||
::prometheus::Exposer* | ||
exposer(); | ||
|
||
/// Where to register the measurements to expose to Prometheus. | ||
/// | ||
/// Maybe nullptr if set up failed. | ||
std::shared_ptr<::prometheus::Registry> | ||
registry(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.