gaschler 2018-02-21 18:52:57 +01:00 committed by Wally B. Feed
parent 30114e364a
commit eabcab26ed
3 changed files with 25 additions and 1 deletions

View File

@ -217,7 +217,7 @@ if(${BUILD_GRPC})
endif() endif()
if(${BUILD_PROMETHEUS}) if(${BUILD_PROMETHEUS})
target_link_libraries(${PROJECT_NAME} PUBLIC prometheus-cpp) target_link_libraries(${PROJECT_NAME} PUBLIC prometheus-cpp)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_PROMETHEUS=1) target_compile_definitions(${PROJECT_NAME} PUBLIC USE_PROMETHEUS=1)
endif() endif()
# Add the binary directory first, so that port.h is included after it has # Add the binary directory first, so that port.h is included after it has

View File

@ -14,10 +14,15 @@
* limitations under the License. * limitations under the License.
*/ */
#include "cartographer/metrics/register.h"
#include "cartographer_grpc/map_builder_server.h" #include "cartographer_grpc/map_builder_server.h"
#include "cartographer_grpc/map_builder_server_options.h" #include "cartographer_grpc/map_builder_server_options.h"
#include "gflags/gflags.h" #include "gflags/gflags.h"
#include "glog/logging.h" #include "glog/logging.h"
#if USE_PROMETHEUS
#include "cartographer_grpc/metrics/prometheus/family_factory.h"
#include "prometheus/exposer.h"
#endif
DEFINE_string(configuration_directory, "", DEFINE_string(configuration_directory, "",
"First directory in which configuration files are searched, " "First directory in which configuration files are searched, "
@ -31,6 +36,14 @@ namespace cartographer_grpc {
void Run(const std::string& configuration_directory, void Run(const std::string& configuration_directory,
const std::string& configuration_basename) { const std::string& configuration_basename) {
#if USE_PROMETHEUS
metrics::prometheus::FamilyFactory registry;
cartographer::metrics::RegisterAllMetrics(&registry);
::prometheus::Exposer exposer("0.0.0.0:9100");
exposer.RegisterCollectable(registry.GetCollectable());
LOG(INFO) << "Exposing metrics at http://localhost:9100/metrics";
#endif
proto::MapBuilderServerOptions map_builder_server_options = proto::MapBuilderServerOptions map_builder_server_options =
LoadMapBuilderServerOptions(configuration_directory, LoadMapBuilderServerOptions(configuration_directory,
configuration_basename); configuration_basename);

View File

@ -131,6 +131,17 @@ TEST(MetricsTest, CollectHistogram) {
EXPECT_EQ(collected[0].metric(0).histogram().bucket(0).cumulative_count(), 1); EXPECT_EQ(collected[0].metric(0).histogram().bucket(0).cumulative_count(), 1);
} }
TEST(MetricsTest, RunExposerServer) {
FamilyFactory registry;
Algorithm::RegisterMetrics(&registry);
cartographer::metrics::RegisterAllMetrics(&registry);
::prometheus::Exposer exposer("0.0.0.0:9100");
exposer.RegisterCollectable(registry.GetCollectable());
Algorithm algorithm;
algorithm.Run();
}
} // namespace } // namespace
} // namespace prometheus } // namespace prometheus
} // namespace metrics } // namespace metrics