Skip to content

testillano/metrics

Repository files navigation

C++ metrics wrapper library

License: MIT Documentation Ask Me Anything ! Maintenance Main project workflow

This library is based on @jupp0r prometheus-cpp library (https://github.com/jupp0r/prometheus-cpp). It offers a quick way to instantiate an object to ease metrics creation and management from every program module.

Project image

This image is already available at github container registry and docker hub for every repository tag, and also for master as latest:

$ docker pull ghcr.io/testillano/metrics:<tag>

You could also build it using the script ./build.sh located at project root:

$ ./build.sh --project-image

This image is built with ./Dockerfile.

Usage

To run compilation over this image, just run with docker. The entrypoint (check it at ./deps/build.sh) will fall back from cmake (looking for CMakeLists.txt file at project root, i.e. mounted on working directory /code to generate makefiles) to make, in order to build your source code. There are two available environment variables used by the builder script of this image: BUILD_TYPE (for cmake) and MAKE_PROCS (for make):

$ envs="-e MAKE_PROCS=$(grep processor /proc/cpuinfo -c) -e BUILD_TYPE=Release"
$ docker run --rm -it -u $(id -u):$(id -g) ${envs} -v ${PWD}:/code -w /code \
         ghcr.io/testillano/metrics:<tag>

Build project with docker

Builder image

This image is already available at github container registry and docker hub for every repository tag, and also for master as latest:

$ docker pull ghcr.io/testillano/metrics_builder:<tag>

You could also build it using the script ./build.sh located at project root:

$ ./build.sh --builder-image

This image is built with ./Dockerfile.build.

Usage

Builder image is used to build the project library. To run compilation over this image, again, just run with docker:

$ envs="-e MAKE_PROCS=$(grep processor /proc/cpuinfo -c) -e BUILD_TYPE=Release"
$ docker run --rm -it -u $(id -u):$(id -g) ${envs} -v ${PWD}:/code -w /code \
         ghcr.io/testillano/metrics_builder:<tag>

You could generate documentation passing extra arguments to the entry point behind:

$ docker run --rm -it -u $(id -u):$(id -g) ${envs} -v ${PWD}:/code -w /code \
         ghcr.io/testillano/metrics_builder::<tag>-build "" doc

You could also build the library using the script ./build.sh located at project root:

$ ./build.sh --project

Build project natively

This is a cmake-based building library, so you may install cmake:

$ sudo apt-get install cmake

And then generate the makefiles from project root directory:

$ cmake .

You could specify type of build, 'Debug' or 'Release', for example:

$ cmake -DCMAKE_BUILD_TYPE=Debug .
$ cmake -DCMAKE_BUILD_TYPE=Release .

You could also change the compilers used:

$ cmake -DCMAKE_CXX_COMPILER=/usr/bin/g++     -DCMAKE_C_COMPILER=/usr/bin/gcc

or

$ cmake -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang

Build

$ make

Clean

$ make clean

Documentation

$ make doc
$ cd docs/doxygen
$ tree -L 1
     .
     ├── Doxyfile
     ├── html
     ├── latex
     └── man

Install

$ sudo make install

Optionally you could specify another prefix for installation:

$ cmake -DMY_OWN_INSTALL_PREFIX=$HOME/mylibs/ert_metrics
$ make install

Uninstall

$ cat install_manifest.txt | sudo xargs rm

Integration

CMake

Embedded

Replication

To embed the library directly into an existing CMake project, place the entire source tree in a subdirectory and call add_subdirectory() in your CMakeLists.txt file:

add_subdirectory(ert_metrics)
...
add_library(foo ...)
...
target_link_libraries(foo PRIVATE ert_metrics::ert_metrics)
FetchContent

Since CMake v3.11, FetchContent can be used to automatically download the repository as a dependency at configure type.

Example:

include(FetchContent)

FetchContent_Declare(ert_metrics
  GIT_REPOSITORY https://github.com/testillano/metrics.git
  GIT_TAG vx.y.z)

FetchContent_GetProperties(ert_metrics)
if(NOT ert_json_POPULATED)
  FetchContent_Populate(ert_metrics)
  add_subdirectory(${ert_metrics_SOURCE_DIR} ${ert_metrics_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

target_link_libraries(foo PRIVATE ert_metrics::ert_metrics)

Contributing

Please, execute astyle formatting (using frankwolf image) before any pull request:

$ sources=$(find . -name "*.hpp" -o -name "*.cpp")
$ docker run -i --rm -v $PWD:/data frankwolf/astyle ${sources}