pax_global_header00006660000000000000000000000064144641137060014520gustar00rootroot0000000000000052 comment=1d6d67378a97d8680b5a8bfdddfe416a8815bdfd prometheus-cpp-1.0.2/000077500000000000000000000000001446411370600144735ustar00rootroot00000000000000prometheus-cpp-1.0.2/.bazelignore000066400000000000000000000000111446411370600167650ustar00rootroot000000000000003rdparty prometheus-cpp-1.0.2/.bazelrc000066400000000000000000000004151446411370600161160ustar00rootroot00000000000000build:asan --strip=never build:asan --copt -fsanitize=address build:asan --copt -DADDRESS_SANITIZER build:asan --copt -O0 build:asan --copt -fno-omit-frame-pointer build:asan --copt -g build:asan --linkopt -fsanitize=address build:asan --cc_output_directory_tag=asan prometheus-cpp-1.0.2/.clang-format000066400000000000000000000000251446411370600170430ustar00rootroot00000000000000BasedOnStyle: Google prometheus-cpp-1.0.2/.github/000077500000000000000000000000001446411370600160335ustar00rootroot00000000000000prometheus-cpp-1.0.2/.github/workflows/000077500000000000000000000000001446411370600200705ustar00rootroot00000000000000prometheus-cpp-1.0.2/.github/workflows/bazel-ci.yml000066400000000000000000000022431446411370600223020ustar00rootroot00000000000000name: Bazel CI on: [push, pull_request] jobs: build: name: Bazel on ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: matrix: os: [macos-latest, ubuntu-latest, windows-latest] steps: - name: Checkout source uses: actions/checkout@v3 - name: Generate German locale on Ubuntu if: runner.os == 'Linux' run: | sudo apt-get remove -y --purge man-db # avoid time-consuming trigger sudo apt-get update sudo apt-get install -y locales sudo locale-gen de_DE.UTF-8 # used by SerializerTest - name: Install telegraf on Ubuntu if: runner.os == 'Linux' run: | sudo apt-get install -y telegraf - name: Install telegraf on macOS if: runner.os == 'macOS' run: brew install telegraf - name: Build run: bazel build //... - name: Test run: bazel test --test_output=all //core/... //pull/... - name: Scraping Test if: runner.os != 'Windows' run: bazel test --test_output=all //pull/tests/integration:scrape-test - name: Benchmark run: bazel run -c opt //core/benchmarks prometheus-cpp-1.0.2/.github/workflows/cmake-ci.yml000066400000000000000000000164071446411370600222740ustar00rootroot00000000000000name: CMake CI on: [push, pull_request] jobs: build: name: CMake on ${{ matrix.os }} with ${{ matrix.dependencies }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [macOS-latest, ubuntu-20.04, windows-2019] dependencies: [submodule, vcpkg] steps: - name: Checkout source uses: actions/checkout@v3 with: submodules: ${{ matrix.dependencies == 'submodule' }} - name: Mount vcpkg cache if: matrix.dependencies == 'vcpkg' uses: actions/cache@v3 with: path: "~/.cache/vcpkg/archives" key: vcpkg-${{ matrix.os }} - name: Default to x64-windows vcpkg triplet if: matrix.dependencies == 'vcpkg' && runner.os == 'Windows' run: echo "VCPKG_DEFAULT_TRIPLET=x64-windows" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append - name: Install vcpkg dependencies if: matrix.dependencies == 'vcpkg' run: vcpkg install benchmark civetweb curl[core] gtest zlib - name: Generate German locale on Ubuntu if: runner.os == 'Linux' run: | sudo apt-get remove -y --purge man-db # avoid time-consuming trigger sudo apt-get update sudo apt-get install -y locales sudo locale-gen de_DE.UTF-8 # used by SerializerTest - name: Install ninja on Ubuntu if: runner.os == 'Linux' run: | sudo apt-get install -y ninja-build - name: Install ninja on macOS if: runner.os == 'macOS' run: brew install ninja - name: "Configure for Unix with internal dependencies" if: matrix.dependencies == 'submodule' && runner.os != 'Windows' run: cmake -DUSE_THIRDPARTY_LIBRARIES=ON -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install -DENABLE_WARNINGS_AS_ERRORS=ON -DENABLE_COMPRESSION=OFF -DENABLE_PUSH=OFF -DCMAKE_DEBUG_POSTFIX=_d -DCMAKE_CONFIGURATION_TYPES='Release;Debug' -G"Ninja Multi-Config" -S ${{ github.workspace }} -B ${{ github.workspace }}/_build - name: "Configure for Windows with internal dependencies" if: matrix.dependencies == 'submodule' && runner.os == 'Windows' run: cmake -DUSE_THIRDPARTY_LIBRARIES=ON -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install -DENABLE_WARNINGS_AS_ERRORS=ON -DENABLE_COMPRESSION=OFF -DENABLE_PUSH=OFF -DCMAKE_DEBUG_POSTFIX=_d -S ${{ github.workspace }} -B ${{ github.workspace }}/_build - name: "Configure for Unix with vcpkg dependencies" if: matrix.dependencies == 'vcpkg' && runner.os != 'Windows' run: cmake -DUSE_THIRDPARTY_LIBRARIES=OFF -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_DEBUG_POSTFIX=_d -DCMAKE_CONFIGURATION_TYPES='Release;Debug' -G"Ninja Multi-Config" -S ${{ github.workspace }} -B ${{ github.workspace }}/_build - name: "Configure for Windows with vcpkg dependencies" if: matrix.dependencies == 'vcpkg' && runner.os == 'Windows' run: cmake -DUSE_THIRDPARTY_LIBRARIES=OFF -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install "-DCMAKE_TOOLCHAIN_FILE=${Env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" -DCMAKE_DEBUG_POSTFIX=_d -S ${{ github.workspace }} -B ${{ github.workspace }}/_build - name: "Build Debug" run: cmake --build ${{ github.workspace }}/_build --config Debug - name: "Build Release" run: cmake --build ${{ github.workspace }}/_build --config Release - name: "Test Debug" run: ctest -C Debug -V -LE Benchmark working-directory: "${{ github.workspace }}/_build" - name: "Test Release" run: ctest -C Release -V -LE Benchmark working-directory: "${{ github.workspace }}/_build" - name: "Run Benchmark" run: ctest -C Release -V -L Benchmark working-directory: "${{ github.workspace }}/_build" - name: "Install Debug" run: cmake --install ${{ github.workspace }}/_build --config Debug - name: "Install Release" run: cmake --install ${{ github.workspace }}/_build --config Release - name: "Configure CMake import for Unix with internal dependencies" if: matrix.dependencies == 'submodule' && runner.os != 'Windows' run: cmake -Dprometheus-cpp_DIR=${{ github.workspace }}/_install/lib/cmake/prometheus-cpp -DCMAKE_CONFIGURATION_TYPES='Release;Debug' -G"Ninja Multi-Config" -S ${{ github.workspace }}/cmake/project-import-cmake -B ${{ github.workspace }}/_import_cmake - name: "Configure CMake import for Windows with internal dependencies" if: matrix.dependencies == 'submodule' && runner.os == 'Windows' run: cmake -Dprometheus-cpp_DIR=${{ github.workspace }}/_install/lib/cmake/prometheus-cpp -S ${{ github.workspace }}/cmake/project-import-cmake -B ${{ github.workspace }}/_import_cmake - name: "Configure CMake import for Unix with vcpkg dependencies" if: matrix.dependencies == 'vcpkg' && runner.os != 'Windows' run: cmake -Dprometheus-cpp_DIR=${{ github.workspace }}/_install/lib/cmake/prometheus-cpp "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" -DCMAKE_CONFIGURATION_TYPES='Release;Debug' -G"Ninja Multi-Config" -S ${{ github.workspace }}/cmake/project-import-cmake -B ${{ github.workspace }}/_import_cmake - name: "Configure CMake import for Windows with vcpkg dependencies" if: matrix.dependencies == 'vcpkg' && runner.os == 'Windows' run: cmake -Dprometheus-cpp_DIR=${{ github.workspace }}/_install/lib/cmake/prometheus-cpp "-DCMAKE_TOOLCHAIN_FILE=${Env:VCPKG_INSTALLATION_ROOT}\scripts\buildsystems\vcpkg.cmake" -S ${{ github.workspace }}/cmake/project-import-cmake -B ${{ github.workspace }}/_import_cmake - name: "Build CMake import Debug" run: cmake --build ${{ github.workspace }}/_import_cmake --config Debug - name: "Build CMake import Release" run: cmake --build ${{ github.workspace }}/_import_cmake --config Release - name: "Configure for Unix Shared Libs with internal dependencies" if: matrix.dependencies == 'submodule' && runner.os != 'Windows' run: cmake -DUSE_THIRDPARTY_LIBRARIES=ON -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=${{ github.workspace }}/_install_shared -DENABLE_WARNINGS_AS_ERRORS=ON -DENABLE_COMPRESSION=OFF -DENABLE_PUSH=OFF -DCMAKE_DEBUG_POSTFIX=_d -GNinja -S ${{ github.workspace }} -B ${{ github.workspace }}/_build_shared - name: "Build for Unix Shared Libs" if: matrix.dependencies == 'submodule' && runner.os != 'Windows' run: cmake --build ${{ github.workspace }}/_build_shared - name: "Install for Unix Shared Libs" if: matrix.dependencies == 'submodule' && runner.os != 'Windows' run: cmake --install ${{ github.workspace }}/_build_shared - name: "Configure pkg-config import for Unix" if: matrix.dependencies == 'submodule' && runner.os != 'Windows' run: cmake -DCMAKE_PREFIX_PATH=${{ github.workspace }}/_install_shared -GNinja -S ${{ github.workspace }}/cmake/project-import-pkgconfig -B ${{ github.workspace }}/_import_pkgconfig - name: "Build pkg-config import for Unix" if: matrix.dependencies == 'submodule' && runner.os != 'Windows' run: cmake --build ${{ github.workspace }}/_import_pkgconfig prometheus-cpp-1.0.2/.github/workflows/coverage.yml000066400000000000000000000036451446411370600224160ustar00rootroot00000000000000name: Coverage on: [push, pull_request] jobs: build: name: Code Coverage runs-on: ubuntu-20.04 steps: - name: Checkout source uses: actions/checkout@v3 - name: Mount vcpkg cache uses: actions/cache@v3 with: path: "~/.cache/vcpkg/archives" key: vcpkg-${{ runner.os }} - name: Install vcpkg dependencies run: vcpkg install benchmark civetweb curl[core] gtest zlib - name: Generate German locale on Ubuntu if: runner.os == 'Linux' run: | sudo apt-get remove -y --purge man-db # avoid time-consuming trigger sudo apt-get update sudo apt-get install -y locales sudo locale-gen de_DE.UTF-8 # used by SerializerTest - name: Install ninja on Ubuntu if: runner.os == 'Linux' run: | sudo apt-get install -y ninja-build - name: Install lcov if: runner.os == 'Linux' run: | sudo apt-get install -y lcov - name: "CMake Configure for Unix with vcpkg dependencies" env: CFLAGS: "--coverage" CXXFLAGS: "--coverage" LDFLAGS: "--coverage" run: cmake -DUSE_THIRDPARTY_LIBRARIES=OFF "-DCMAKE_TOOLCHAIN_FILE=${VCPKG_INSTALLATION_ROOT}/scripts/buildsystems/vcpkg.cmake" -GNinja -S ${{ github.workspace }} -B ${{ github.workspace }}/_build - name: Build run: cmake --build ${{ github.workspace }}/_build - name: Test run: ctest -V -LE Benchmark working-directory: "${{ github.workspace }}/_build" - name: Run lcov run: lcov --capture --directory "${{ github.workspace }}/_build" --output-file coverage.info --no-external --directory "${{ github.workspace }}" --exclude '*/tests/*' - name: Coveralls uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: coverage.info prometheus-cpp-1.0.2/.github/workflows/doxygen.yml000066400000000000000000000013211446411370600222650ustar00rootroot00000000000000name: Doxygen on: push: branches: - master jobs: build: name: Code Coverage runs-on: ubuntu-20.04 steps: - name: Checkout source uses: actions/checkout@v3 - name: Install doxygen run: | sudo apt-get remove -y --purge man-db # avoid time-consuming trigger sudo apt-get update sudo apt-get install -y doxygen graphviz - name: Generate doxygen run: doxygen working-directory: "${{ github.workspace }}/doc" - name: Deploy documentation uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} force_orphan: true publish_dir: ./doc/html prometheus-cpp-1.0.2/.github/workflows/linting.yml000066400000000000000000000041101446411370600222530ustar00rootroot00000000000000name: Linting on: [push, pull_request] jobs: iwyu: name: Include What You Use runs-on: ubuntu-latest container: image: debian:sid-slim steps: - name: Install dependencies run: | apt-get update apt-get install -y --no-install-recommends ca-certificates clang-14 cmake git iwyu libbenchmark-dev libcurl4-openssl-dev ninja-build zlib1g-dev - name: Checkout source uses: actions/checkout@v3 with: submodules: true - name: "CMake Configure" run: cmake -GNinja -DRUN_IWYU=ON -DCMAKE_C_COMPILER=clang-14 -DCMAKE_CXX_COMPILER=clang++-14 -S ${GITHUB_WORKSPACE} -B ${GITHUB_WORKSPACE}/_build - name: Build run: cmake --build ${GITHUB_WORKSPACE}/_build 2>&1 | tee ${GITHUB_WORKSPACE}/output.txt - name: Check build output run: if egrep -q 'should (add|remove) these lines' ${GITHUB_WORKSPACE}/output.txt; then exit 1; fi #- name: "CMake Configure" # run: cmake -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -S ${GITHUB_WORKSPACE} -B ${GITHUB_WORKSPACE}/_build #- name: "Run IWYU" # run: iwyu_tool -p ${GITHUB_WORKSPACE}/_build core push pull -- -Xiwyu --mapping_file=${GITHUB_WORKSPACE}/cmake/googletest.imp -Xiwyu --no_fwd_decls 2>&1 | tee ${{ github.workspace }}/output.txt format: name: Clang Format runs-on: ubuntu-20.04 steps: - name: Checkout source uses: actions/checkout@v3 # clang-format comes pre-installed # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md #- name: Install dependencies # run: | # sudo apt-get remove -y --purge man-db # avoid time-consuming trigger # sudo apt-get update # sudo apt-get install -y clang-format-12 - name: Run clang-format run: find . -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.cxx' -o -name '*.o' -o -name '*.h' -o -name '*.hpp' -o -name '*.hxx' \) -exec clang-format-12 -style=file -i {} \; - name: Check for changes run: git diff --exit-code prometheus-cpp-1.0.2/.github/workflows/release.yml000066400000000000000000000022031446411370600222300ustar00rootroot00000000000000on: release: types: [created] name: Handle Release jobs: build: name: Upload Release Asset runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v3 with: persist-credentials: false submodules: true - name: Create tarball including submodules shell: bash env: PREFIX: prometheus-cpp-with-submodules run: | git archive --prefix "${PREFIX}/" -o "${PREFIX}.tar" HEAD git submodule foreach --recursive "git archive --prefix=${PREFIX}/\$path/ --output=\$sha1.tar HEAD && tar --concatenate --file=$(pwd)/${PREFIX}.tar \$sha1.tar && rm \$sha1.tar" gzip "${PREFIX}.tar" # using the official actions/upload-release-asset action would be preferred but is blocked by # https://github.com/actions/upload-release-asset/pull/41 - name: Upload the artifacts uses: skx/github-action-publish-binaries@75ce5546020fc1848da842f40240f9fa03e7a3a8 # release-0.14 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: args: prometheus-cpp-with-submodules.tar.gz prometheus-cpp-1.0.2/.gitignore000066400000000000000000000000731446411370600164630ustar00rootroot00000000000000/bazel-* cmake-build-*/ _*/ .idea/ doc/html/ .vscode build prometheus-cpp-1.0.2/.gitmodules000066400000000000000000000003061446411370600166470ustar00rootroot00000000000000[submodule "googletest"] path = 3rdparty/googletest url = https://github.com/google/googletest.git [submodule "civetweb"] path = 3rdparty/civetweb url = https://github.com/civetweb/civetweb.git prometheus-cpp-1.0.2/3rdparty/000077500000000000000000000000001446411370600162435ustar00rootroot00000000000000prometheus-cpp-1.0.2/3rdparty/civetweb/000077500000000000000000000000001446411370600200535ustar00rootroot00000000000000prometheus-cpp-1.0.2/3rdparty/googletest/000077500000000000000000000000001446411370600204175ustar00rootroot00000000000000prometheus-cpp-1.0.2/BUILD.bazel000066400000000000000000000003341446411370600163510ustar00rootroot00000000000000package(default_visibility = ["//visibility:public"]) config_setting( name = "windows", values = {"cpu": "x64_windows"}, ) config_setting( name = "windows_msvc", values = {"cpu": "x64_windows_msvc"}, ) prometheus-cpp-1.0.2/CMakeLists.txt000066400000000000000000000136571446411370600172470ustar00rootroot00000000000000 cmake_minimum_required(VERSION 3.14 FATAL_ERROR) if(POLICY CMP0091) cmake_policy(SET CMP0091 NEW) # recognize CMAKE_MSVC_RUNTIME_LIBRARY endif() project(prometheus-cpp VERSION 1.0.2 DESCRIPTION "Prometheus Client Library for Modern C++" HOMEPAGE_URL "https://github.com/jupp0r/prometheus-cpp" ) include(GenerateExportHeader) include(GNUInstallDirs) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") option(BUILD_SHARED_LIBS "Build libraries as shared ones" OFF) option(ENABLE_PULL "Build prometheus-cpp pull library" ON) option(ENABLE_PUSH "Build prometheus-cpp push library" ON) option(ENABLE_COMPRESSION "Enable gzip compression" ON) option(ENABLE_TESTING "Build tests" ON) option(USE_THIRDPARTY_LIBRARIES "Use 3rdParty submodules" ON) option(THIRDPARTY_CIVETWEB_WITH_SSL "Enable SSL support for embedded civetweb source code") option(OVERRIDE_CXX_STANDARD_FLAGS "Force building with -std=c++11 even if the CXXLFAGS are configured differently" ON) option(GENERATE_PKGCONFIG "Generate and install pkg-config files" ${UNIX}) option(RUN_IWYU "Run include-what-you-use" OFF) if(OVERRIDE_CXX_STANDARD_FLAGS) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_EXTENSIONS Off) endif() # Set default directory permissions until # https://gitlab.kitware.com/cmake/cmake/issues/15163 # is fixed set(CMAKE_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) # Put DLLs and binaries into same directory set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) # Hide things by default for shared libraries if(BUILD_SHARED_LIBS) set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) endif() set(CMAKE_THREAD_PREFER_PTHREAD TRUE) find_package(Threads) # include-what-you-use if(RUN_IWYU) find_program(IWYU_EXECUTABLE NAMES include-what-you-use iwyu) if(NOT IWYU_EXECUTABLE) message(FATAL_ERROR "Include-what-you-use not found") endif() set(IWYU_ARGS "${IWYU_EXECUTABLE}" "-Xiwyu" "--no_fwd_decls" "-Xiwyu" "--mapping_file=${CMAKE_CURRENT_SOURCE_DIR}/cmake/googletest.imp" ) set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU_ARGS}) set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_ARGS}) endif() # check for required libatomic include(CheckAtomic) if(ENABLE_TESTING) if(USE_THIRDPARTY_LIBRARIES) find_package(googlemock-3rdparty CONFIG REQUIRED) else() find_package(GTest 1.8.1 CONFIG REQUIRED) endif() find_package(benchmark CONFIG) enable_testing() endif() # build flags for CI system if(ENABLE_WARNINGS_AS_ERRORS AND NOT MSVC) add_compile_options( $<$,CXX>,$>:-Werror> $<$,CXX>,$>:-Wall> $<$,CXX>,$>:-Wextra> $<$,CXX>,$>:-pedantic-errors> $<$,CXX>,$>:-Werror> $<$,CXX>,$>:-Wall> $<$,CXX>,$>:-pedantic-errors> ) endif() # pkgconfig if(GENERATE_PKGCONFIG) # see https://github.com/jupp0r/prometheus-cpp/issues/587 if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") set(PROMETHEUS_CPP_PKGCONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") else() set(PROMETHEUS_CPP_PKGCONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") endif() if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") set(PROMETHEUS_CPP_PKGCONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}") else() set(PROMETHEUS_CPP_PKGCONFIG_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") endif() endif() # prometheus-cpp add_subdirectory(core) if(ENABLE_PULL) add_subdirectory(pull) endif() if(ENABLE_PUSH) add_subdirectory(push) endif() # install include(CMakePackageConfigHelpers) install( EXPORT ${PROJECT_NAME}-targets NAMESPACE ${PROJECT_NAME}:: FILE ${PROJECT_NAME}-targets.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}-config.cmake.in" ${PROJECT_NAME}-config.cmake INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" NO_CHECK_REQUIRED_COMPONENTS_MACRO PATH_VARS CMAKE_INSTALL_INCLUDEDIR ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) # packaging if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) set(CPACK_PACKAGE_CONTACT "prometheus-cpp@@noreply.github.com") set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_DESCRIPTION}") set(CPACK_PACKAGE_RELOCATABLE OFF) set(CPACK_PACKAGE_VENDOR "The prometheus-cpp authors") if(CMAKE_VERSION VERSION_LESS "3.12") set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}") set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}") set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}") endif() set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON) set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) set(CPACK_RPM_PACKAGE_AUTOREQPROV ON) set(CPACK_RPM_FILE_NAME RPM-DEFAULT) include(CPack) endif() # summary include(FeatureSummary) add_feature_info("Pull" "${ENABLE_PULL}" "support for pulling metrics") add_feature_info("Push" "${ENABLE_PUSH}" "support for pushing metrics to a push-gateway") add_feature_info("Compression" "${ENABLE_COMPRESSION}" "support for zlib compression of metrics") add_feature_info("pkg-config" "${GENERATE_PKGCONFIG}" "generate pkg-config files") add_feature_info("IYWU" "${RUN_IWYU}" "include-what-you-use") feature_summary(WHAT ALL) prometheus-cpp-1.0.2/LICENSE000066400000000000000000000022601446411370600155000ustar00rootroot00000000000000MIT License Copyright (c) 2016-2021 Jupp Mueller Copyright (c) 2017-2022 Gregor Jasny And many contributors, see https://github.com/jupp0r/prometheus-cpp/graphs/contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. prometheus-cpp-1.0.2/README.md000066400000000000000000000375661446411370600157730ustar00rootroot00000000000000# Prometheus Client Library for Modern C++ [![CI Status](https://github.com/jupp0r/prometheus-cpp/workflows/Continuous%20Integration/badge.svg)](https://github.com/jupp0r/prometheus-cpp/actions?workflow=Continuous+Integration) [![Travis Status](https://travis-ci.org/jupp0r/prometheus-cpp.svg?branch=master)](https://travis-ci.org/jupp0r/prometheus-cpp) [![Coverage Status](https://coveralls.io/repos/github/jupp0r/prometheus-cpp/badge.svg?branch=master)](https://coveralls.io/github/jupp0r/prometheus-cpp?branch=master) [![Coverity Scan](https://scan.coverity.com/projects/10567/badge.svg)](https://scan.coverity.com/projects/jupp0r-prometheus-cpp) This library aims to enable [Metrics-Driven Development](https://sookocheff.com/post/mdd/mdd/) for C++ services. It implements the [Prometheus Data Model](https://prometheus.io/docs/concepts/data_model/), a powerful abstraction on which to collect and expose metrics. We offer the possibility for metrics to be collected by Prometheus, but other push/pull collections can be added as plugins. ## Usage See https://jupp0r.github.io/prometheus-cpp for more detailed interface documentation. ``` c++ #include #include #include #include #include #include #include #include #include int main() { using namespace prometheus; // create an http server running on port 8080 Exposer exposer{"127.0.0.1:8080"}; // create a metrics registry // @note it's the users responsibility to keep the object alive auto registry = std::make_shared(); // add a new counter family to the registry (families combine values with the // same name, but distinct label dimensions) // // @note please follow the metric-naming best-practices: // https://prometheus.io/docs/practices/naming/ auto& packet_counter = BuildCounter() .Name("observed_packets_total") .Help("Number of observed packets") .Register(*registry); // add and remember dimensional data, incrementing those is very cheap auto& tcp_rx_counter = packet_counter.Add({{"protocol", "tcp"}, {"direction", "rx"}}); auto& tcp_tx_counter = packet_counter.Add({{"protocol", "tcp"}, {"direction", "tx"}}); auto& udp_rx_counter = packet_counter.Add({{"protocol", "udp"}, {"direction", "rx"}}); auto& udp_tx_counter = packet_counter.Add({{"protocol", "udp"}, {"direction", "tx"}}); // add a counter whose dimensional data is not known at compile time // nevertheless dimensional values should only occur in low cardinality: // https://prometheus.io/docs/practices/naming/#labels auto& http_requests_counter = BuildCounter() .Name("http_requests_total") .Help("Number of HTTP requests") .Register(*registry); // ask the exposer to scrape the registry on incoming HTTP requests exposer.RegisterCollectable(registry); for (;;) { std::this_thread::sleep_for(std::chrono::seconds(1)); const auto random_value = std::rand(); if (random_value & 1) tcp_rx_counter.Increment(); if (random_value & 2) tcp_tx_counter.Increment(); if (random_value & 4) udp_rx_counter.Increment(); if (random_value & 8) udp_tx_counter.Increment(); const std::array methods = {"GET", "PUT", "POST", "HEAD"}; auto method = methods.at(random_value % methods.size()); // dynamically calling Family.Add() works but is slow and should be // avoided http_requests_counter.Add({{"method", method}}).Increment(); } return 0; } ``` ## Requirements Using `prometheus-cpp` requires a C++11 compliant compiler. It has been successfully tested with GNU GCC 7.4 on Ubuntu Bionic (18.04) and Visual Studio 2017 (but Visual Studio 2015 should work, too). ## Building There are two supported ways to build `prometheus-cpp` - [CMake](https://cmake.org) and [bazel](https://bazel.io). Both are tested in CI and should work on master and for all releases. In case these instructions don't work for you, looking at the [GitHub Workflows](.github/workflows) might help. ### via CMake For CMake builds don't forget to fetch the submodules first. Please note that [zlib](https://zlib.net/) and [libcurl](https://curl.se/) are not provided by the included submodules. In the example below their usage is disabled. Then build as usual. ``` shell # fetch third-party dependencies git submodule init git submodule update mkdir _build cd _build # run cmake cmake .. -DBUILD_SHARED_LIBS=ON -DENABLE_PUSH=OFF -DENABLE_COMPRESSION=OFF # build cmake --build . --parallel 4 # run tests ctest -V # install the libraries and headers cmake --install . ``` ### via Bazel Install [bazel](https://www.bazel.io). Bazel makes it easy to add this repo to your project as a dependency. Just add the following to your `WORKSPACE`: ```python load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file") http_archive( name = "com_github_jupp0r_prometheus_cpp", strip_prefix = "prometheus-cpp-master", urls = ["https://github.com/jupp0r/prometheus-cpp/archive/master.zip"], ) load("@com_github_jupp0r_prometheus_cpp//bazel:repositories.bzl", "prometheus_cpp_repositories") prometheus_cpp_repositories() ``` Then, you can reference this library in your own `BUILD` file, as demonstrated with the sample server included in this repository: ```python cc_binary( name = "sample_server", srcs = ["sample_server.cc"], deps = ["@com_github_jupp0r_prometheus_cpp//pull"], ) ``` When you call `prometheus_cpp_repositories()` in your `WORKSPACE` file, you load the following dependencies, if they do not exist yet, into your project: * `civetweb` for [Civetweb](https://github.com/civetweb/civetweb) * `com_google_googletest` for [Google Test](https://github.com/google/googletest) * `com_github_google_benchmark` for [Google Benchmark](https://github.com/google/benchmark) * `com_github_curl` for [curl](https://curl.haxx.se/) * `net_zlib_zlib` for [zlib](http://www.zlib.net/) The list of dependencies is also available from file [repositories.bzl](bazel/repositories.bzl). ## Packaging By configuring CPack you can generate an installer like a Debian package (.deb) or RPM (.rpm) for the static or dynamic libraries so they can be easily installed on other systems. Please refer to the [CPack](https://cmake.org/cmake/help/latest/module/CPack.html) documentation for all available generators and their configuration options. To generate a Debian package you could follow these steps: ``` shell # fetch third-party dependencies git submodule update --init # run cmake cmake -B_build -DCPACK_GENERATOR=DEB -DBUILD_SHARED_LIBS=ON # or OFF for static libraries # build and package cmake --build _build --target package --parallel $(nproc) ``` This will place an appropriately named .deb in the `_build` folder. To build a RPM package set the `CPACK_GENERATOR` variable to `RPM`. ## Consuming the installed project ### CMake Consuming prometheus-cpp via CMake is the preferred way because all the dependencies between the three prometheus-cpp libraries are handled correctly. The `cmake/project-import` directory contains an example project and minimal [CMakeLists.txt](cmake/project-import-cmake/CMakeLists.txt). ### vcpkg The [vcpkg](https://github.com/microsoft/vcpkg) package manager contains a prometheus-cpp port which has been tested on Linux, macOS, and Windows. ### Conan [Conan](https://conan.io/) package manager contains prometheus-cpp package as well in [ConanCenter](https://conan.io/center/prometheus-cpp) repository ### Plain Makefiles When manually linking prometheus-cpp the library order matters. The needed libraries depend on the individual use case but the following should work for the pull metrics approach: ``` -lprometheus-cpp-pull -lprometheus-cpp-core -lz ``` For the push-workflow please try: ``` -lprometheus-cpp-push -lprometheus-cpp-core -lcurl -lz ``` ## Contributing Please adhere to the [Google C++ Style Guide](https://google.github.io/styleguide/cppguide.html). Make sure to clang-format your patches before opening a PR. Also make sure to adhere to [these commit message guidelines](https://chris.beams.io/posts/git-commit/). You can check out this repo and build the library using ``` bash bazel build //... # build everything bazel build //core //pull # build just the libraries ``` Run the unit tests using ``` bazel test //... ``` There is also an integration test that uses [telegraf](https://github.com/influxdata/telegraf) to scrape a sample server. With telegraf installed, it can be run using ``` bazel test //pull/tests/integration:scrape-test ``` ## Benchmarks There's a benchmark suite you can run: ``` bazel run -c opt //core/benchmarks INFO: Analysed target //core/benchmarks:benchmarks (0 packages loaded, 0 targets configured). INFO: Found 1 target... Target //core/benchmarks:benchmarks up-to-date: bazel-bin/core/benchmarks/benchmarks INFO: Elapsed time: 0.356s, Critical Path: 0.01s, Remote (0.00% of the time): [queue: 0.00%, setup: 0.00%, process: 0.00%] INFO: 0 processes. INFO: Build completed successfully, 1 total action INFO: Build completed successfully, 1 total action 2018-11-30 15:13:14 Run on (4 X 2200 MHz CPU s) CPU Caches: L1 Data 32K (x2) L1 Instruction 32K (x2) L2 Unified 262K (x2) L3 Unified 4194K (x1) ----------------------------------------------------------------------------------- Benchmark Time CPU Iterations ----------------------------------------------------------------------------------- BM_Counter_Increment 13 ns 12 ns 55616469 BM_Counter_Collect 7 ns 7 ns 99823170 BM_Gauge_Increment 12 ns 12 ns 51511873 BM_Gauge_Decrement 12 ns 12 ns 56831098 BM_Gauge_SetToCurrentTime 184 ns 183 ns 3928964 BM_Gauge_Collect 6 ns 6 ns 117223478 BM_Histogram_Observe/0 134 ns 124 ns 5665310 BM_Histogram_Observe/1 122 ns 120 ns 5937185 BM_Histogram_Observe/8 137 ns 135 ns 4652863 BM_Histogram_Observe/64 143 ns 143 ns 4835957 BM_Histogram_Observe/512 259 ns 257 ns 2334750 BM_Histogram_Observe/4096 1545 ns 1393 ns 620754 BM_Histogram_Collect/0 103 ns 102 ns 5654829 BM_Histogram_Collect/1 100 ns 100 ns 7015153 BM_Histogram_Collect/8 608 ns 601 ns 1149652 BM_Histogram_Collect/64 1438 ns 1427 ns 515236 BM_Histogram_Collect/512 5178 ns 5159 ns 114619 BM_Histogram_Collect/4096 33527 ns 33280 ns 20785 BM_Registry_CreateFamily 320 ns 316 ns 2021567 BM_Registry_CreateCounter/0 128 ns 128 ns 5487140 BM_Registry_CreateCounter/1 2066 ns 2058 ns 386002 BM_Registry_CreateCounter/8 7672 ns 7634 ns 91328 BM_Registry_CreateCounter/64 63270 ns 62761 ns 10780 BM_Registry_CreateCounter/512 560714 ns 558328 ns 1176 BM_Registry_CreateCounter/4096 18672798 ns 18383000 ns 35 BM_Summary_Observe/0/iterations:262144 9351 ns 9305 ns 262144 BM_Summary_Observe/1/iterations:262144 9242 ns 9169 ns 262144 BM_Summary_Observe/8/iterations:262144 14344 ns 14195 ns 262144 BM_Summary_Observe/64/iterations:262144 19176 ns 18950 ns 262144 BM_Summary_Collect/0/0 31 ns 30 ns 24873766 BM_Summary_Collect/1/0 166 ns 166 ns 4266706 BM_Summary_Collect/8/0 1040 ns 1036 ns 660527 BM_Summary_Collect/64/0 4529 ns 4489 ns 155600 BM_Summary_Collect/0/1 28 ns 28 ns 24866697 BM_Summary_Collect/1/1 190 ns 188 ns 3930354 BM_Summary_Collect/8/1 1372 ns 1355 ns 535779 BM_Summary_Collect/64/1 9901 ns 9822 ns 64632 BM_Summary_Collect/0/8 29 ns 29 ns 24922651 BM_Summary_Collect/1/8 217 ns 215 ns 3278381 BM_Summary_Collect/8/8 2275 ns 2256 ns 282503 BM_Summary_Collect/64/8 56790 ns 55804 ns 13878 BM_Summary_Collect/0/64 32 ns 31 ns 22548350 BM_Summary_Collect/1/64 395 ns 389 ns 1817073 BM_Summary_Collect/8/64 10187 ns 10064 ns 71928 BM_Summary_Collect/64/64 374835 ns 373560 ns 1812 BM_Summary_Collect/0/512 28 ns 28 ns 25234228 BM_Summary_Collect/1/512 1710 ns 1639 ns 802285 BM_Summary_Collect/8/512 50355 ns 49335 ns 15975 BM_Summary_Collect/64/512 2520972 ns 2493417 ns 295 BM_Summary_Collect/0/4096 31 ns 31 ns 24059034 BM_Summary_Collect/1/4096 2719 ns 2698 ns 286186 BM_Summary_Collect/8/4096 121689 ns 119995 ns 5647 BM_Summary_Collect/64/4096 5660131 ns 5587634 ns 134 BM_Summary_Collect/0/32768 29 ns 29 ns 22217567 BM_Summary_Collect/1/32768 4344 ns 4294 ns 138135 BM_Summary_Collect/8/32768 331563 ns 326403 ns 2017 BM_Summary_Collect/64/32768 16363553 ns 16038182 ns 44 BM_Summary_Collect/0/262144 27 ns 27 ns 23923036 BM_Summary_Collect/1/262144 10457 ns 10332 ns 67690 BM_Summary_Collect/8/262144 930434 ns 869234 ns 792 BM_Summary_Collect/64/262144 39217069 ns 39054846 ns 13 BM_Summary_Observe_Common/iterations:262144 5587 ns 5557 ns 262144 BM_Summary_Collect_Common/0 676 ns 673 ns 1054630 BM_Summary_Collect_Common/1 709 ns 705 ns 990659 BM_Summary_Collect_Common/8 1030 ns 1025 ns 685649 BM_Summary_Collect_Common/64 2066 ns 2055 ns 339969 BM_Summary_Collect_Common/512 5754 ns 5248 ns 156895 BM_Summary_Collect_Common/4096 23894 ns 23292 ns 31096 BM_Summary_Collect_Common/32768 49831 ns 49292 ns 13492 BM_Summary_Collect_Common/262144 128723 ns 126987 ns 5579 ``` ## Project Status Stable and used in production. Parts of the library are instrumented by itself (bytes scraped, number of scrapes, scrape request latencies). There is a working [example](pull/tests/integration/sample_server.cc) that's scraped by telegraf as part of integration tests. ## FAQ ### What scrape formats do you support Only the [Prometheus Text Exposition Format](https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md#text-format-details). Support for the protobuf format was removed because it's been removed from Prometheus 2.0. ## License MIT prometheus-cpp-1.0.2/WORKSPACE000066400000000000000000000002251446411370600157530ustar00rootroot00000000000000workspace(name = "com_github_jupp0r_prometheus_cpp") load("//bazel:repositories.bzl", "prometheus_cpp_repositories") prometheus_cpp_repositories() prometheus-cpp-1.0.2/bazel/000077500000000000000000000000001446411370600155705ustar00rootroot00000000000000prometheus-cpp-1.0.2/bazel/BUILD.bazel000066400000000000000000000001621446411370600174450ustar00rootroot00000000000000exports_files( glob([ "*.BUILD", "*.tpl", ]), visibility = ["//visibility:public"], ) prometheus-cpp-1.0.2/bazel/civetweb.BUILD000066400000000000000000000030521446411370600201610ustar00rootroot00000000000000licenses(["notice"]) # MIT license config_setting( name = "osx", constraint_values = [ "@platforms//os:osx", ], ) config_setting( name = "windows", constraint_values = [ "@platforms//os:windows", ], ) cc_library( name = "libcivetweb", srcs = [ "src/civetweb.c", "src/response.inl", ], hdrs = [ "include/civetweb.h", ], copts = [ "-DUSE_IPV6", "-DNDEBUG", "-DNO_CGI", "-DNO_CACHING", "-DNO_SSL", "-DNO_FILES", "-UDEBUG", ], includes = [ "include", ], linkopts = select({ ":windows": [], "//conditions:default": ["-lpthread"], }) + select({ ":osx": [], ":windows": [], "//conditions:default": ["-lrt"], }), textual_hdrs = [ "src/md5.inl", "src/handle_form.inl", ], visibility = ["//visibility:public"], ) cc_library( name = "civetweb", srcs = [ "src/CivetServer.cpp", ], hdrs = [ "include/CivetServer.h", ], copts = [ "-DUSE_IPV6", "-DNDEBUG", "-DNO_CGI", "-DNO_CACHING", "-DNO_SSL", "-DNO_FILES", ], includes = [ "include", ], linkopts = select({ ":windows": [], "//conditions:default": ["-lpthread"], }) + select({ ":osx": [], ":windows": [], "//conditions:default": ["-lrt"], }), visibility = ["//visibility:public"], deps = [ ":libcivetweb", ], ) prometheus-cpp-1.0.2/bazel/curl.BUILD000066400000000000000000000035371446411370600173260ustar00rootroot00000000000000# Copyright 2017, OpenCensus Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # copied from: https://github.com/census-instrumentation/opencensus-cpp/blob/master/WORKSPACE licenses(["notice"]) # MIT/X derivative license load("@com_github_jupp0r_prometheus_cpp//bazel:curl.bzl", "CURL_COPTS") package(features = ["no_copts_tokenization"]) config_setting( name = "windows", constraint_values = [ "@platforms//os:windows", ], visibility = ["//visibility:private"], ) config_setting( name = "osx", constraint_values = [ "@platforms//os:osx", ], visibility = ["//visibility:private"], ) cc_library( name = "curl", srcs = glob([ "lib/**/*.c", ]), hdrs = glob([ "include/curl/*.h", "lib/**/*.h", ]), copts = CURL_COPTS + [ '-DOS="os"', ], defines = ["CURL_STATICLIB"], includes = [ "include/", "lib/", ], linkopts = select({ "//:windows": [ "-DEFAULTLIB:ws2_32.lib", "-DEFAULTLIB:advapi32.lib", "-DEFAULTLIB:crypt32.lib", "-DEFAULTLIB:Normaliz.lib", ], "//:osx": [ "-framework SystemConfiguration", "-lpthread", ], "//conditions:default": [ "-lpthread", ], }), visibility = ["//visibility:public"], ) prometheus-cpp-1.0.2/bazel/curl.bzl000066400000000000000000000130431446411370600172470ustar00rootroot00000000000000# Copyright 2018, OpenCensus Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # Compiler options for building libcurl. # copied from: https://github.com/census-instrumentation/opencensus-cpp/blob/master/opencensus/curl.bzl BASE_CURL_COPTS = [ # Disable everything else except HTTP protocol. "-DHTTP_ONLY=1", "-DENABLE_IPV6=1", "-DGETHOSTNAME_TYPE_ARG2=size_t", "-DGETSERVBYPORT_R_ARGS=6", "-DGETSERVBYPORT_R_BUFSIZE=4096", "-DHAVE_ALARM=1", "-DHAVE_ALLOCA_H=1", "-DHAVE_ARPA_INET_H=1", "-DHAVE_ARPA_TFTP_H=1", "-DHAVE_ASSERT_H=1", "-DHAVE_BASENAME=1", "-DHAVE_BOOL_T=1", "-DHAVE_CLOCK_GETTIME_MONOTONIC=1", "-DHAVE_CONNECT=1", "-DHAVE_DLFCN_H=1", "-DHAVE_ENGINE_LOAD_BUILTIN_ENGINES=1", "-DHAVE_ERRNO_H=1", "-DHAVE_FCNTL=1", "-DHAVE_FCNTL_H=1", "-DHAVE_FCNTL_O_NONBLOCK=1", "-DHAVE_FDOPEN=1", "-DHAVE_FREEADDRINFO=1", "-DHAVE_FREEIFADDRS=1", "-DHAVE_FSETXATTR=1", "-DHAVE_FSETXATTR_5=1", "-DHAVE_FTRUNCATE=1", "-DHAVE_GAI_STRERROR=1", "-DHAVE_GETADDRINFO=1", "-DHAVE_GETADDRINFO_THREADSAFE=1", "-DHAVE_GETEUID=1", "-DHAVE_GETHOSTBYADDR=1", "-DHAVE_GETHOSTBYADDR_R=1", "-DHAVE_GETHOSTBYADDR_R_8=1", "-DHAVE_GETHOSTBYNAME=1", "-DHAVE_GETHOSTBYNAME_R=1", "-DHAVE_GETHOSTBYNAME_R_6=1", "-DHAVE_GETHOSTNAME=1", "-DHAVE_GETIFADDRS=1", "-DHAVE_GETPPID=1", "-DHAVE_GETPWUID=1", "-DHAVE_GETPWUID_R=1", "-DHAVE_GETRLIMIT=1", "-DHAVE_GETSERVBYPORT_R=1", "-DHAVE_GETTIMEOFDAY=1", "-DHAVE_GMTIME_R=1", "-DHAVE_IFADDRS_H=1", "-DHAVE_IF_NAMETOINDEX=1", "-DHAVE_INET_NTOP=1", "-DHAVE_INET_PTON=1", "-DHAVE_INTTYPES_H=1", "-DHAVE_IOCTL=1", "-DHAVE_IOCTL_FIONBIO=1", "-DHAVE_IOCTL_SIOCGIFADDR=1", "-DHAVE_LIBGEN_H=1", "-DHAVE_LL=1", "-DHAVE_LOCALE_H=1", "-DHAVE_LOCALTIME_R=1", "-DHAVE_LONGLONG=1", "-DHAVE_MALLOC_H=1", "-DHAVE_MEMORY_H=1", "-DHAVE_NETDB_H=1", "-DHAVE_NETINET_IN_H=1", "-DHAVE_NETINET_TCP_H=1", "-DHAVE_NET_IF_H=1", "-DHAVE_PIPE=1", "-DHAVE_POLL=1", "-DHAVE_POLL_FINE=1", "-DHAVE_POLL_H=1", "-DHAVE_POSIX_STRERROR_R=1", "-DHAVE_PTHREAD_H=1", "-DHAVE_PWD_H=1", "-DHAVE_RECV=1", "-DHAVE_SA_FAMILY_T=1", "-DHAVE_SELECT=1", "-DHAVE_SEND=1", "-DHAVE_SETJMP_H=1", "-DHAVE_SETLOCALE=1", "-DHAVE_SETRLIMIT=1", "-DHAVE_SETSOCKOPT=1", "-DHAVE_SGTTY_H=1", "-DHAVE_SIGACTION=1", "-DHAVE_SIGINTERRUPT=1", "-DHAVE_SIGNAL=1", "-DHAVE_SIGNAL_H=1", "-DHAVE_SIGSETJMP=1", "-DHAVE_SIG_ATOMIC_T=1", "-DHAVE_SOCKADDR_IN6_SIN6_SCOPE_ID=1", "-DHAVE_SOCKET=1", "-DHAVE_SOCKETPAIR=1", "-DHAVE_STDBOOL_H=1", "-DHAVE_STDINT_H=1", "-DHAVE_STDIO_H=1", "-DHAVE_STDLIB_H=1", "-DHAVE_STRCASECMP=1", "-DHAVE_STRDUP=1", "-DHAVE_STRERROR_R=1", "-DHAVE_STRINGS_H=1", "-DHAVE_STRING_H=1", "-DHAVE_STRNCASECMP=1", "-DHAVE_STRSTR=1", "-DHAVE_STRTOK_R=1", "-DHAVE_STRTOLL=1", "-DHAVE_STRUCT_SOCKADDR_STORAGE=1", "-DHAVE_STRUCT_TIMEVAL=1", "-DHAVE_SYS_IOCTL_H=1", "-DHAVE_SYS_PARAM_H=1", "-DHAVE_SYS_POLL_H=1", "-DHAVE_SYS_RESOURCE_H=1", "-DHAVE_SYS_SELECT_H=1", "-DHAVE_SYS_SOCKET_H=1", "-DHAVE_SYS_STAT_H=1", "-DHAVE_SYS_TIME_H=1", "-DHAVE_SYS_TYPES_H=1", "-DHAVE_SYS_UIO_H=1", "-DHAVE_SYS_UN_H=1", "-DHAVE_SYS_WAIT_H=1", "-DHAVE_SYS_XATTR_H=1", "-DHAVE_TERMIOS_H=1", "-DHAVE_TERMIO_H=1", "-DHAVE_TIME_H=1", "-DHAVE_UNISTD_H=1", "-DHAVE_UTIME=1", "-DHAVE_UTIMES=1", "-DHAVE_UTIME_H=1", "-DHAVE_VARIADIC_MACROS_C99=1", "-DHAVE_VARIADIC_MACROS_GCC=1", "-DHAVE_WRITABLE_ARGV=1", "-DHAVE_WRITEV=1", "-DRECV_TYPE_ARG1=int", "-DRECV_TYPE_ARG2=void*", "-DRECV_TYPE_ARG3=size_t", "-DRECV_TYPE_ARG4=int", "-DRECV_TYPE_RETV=ssize_t", "-DSELECT_QUAL_ARG5=", "-DSELECT_TYPE_ARG1=int", "-DSELECT_TYPE_ARG234=fd_set*", "-DSELECT_TYPE_RETV=int", "-DSEND_QUAL_ARG2=const", "-DSEND_TYPE_ARG1=int", "-DSEND_TYPE_ARG2=void*", "-DSEND_TYPE_ARG3=size_t", "-DSEND_TYPE_ARG4=int", "-DSEND_TYPE_RETV=ssize_t", "-DSIZEOF_CURL_OFF_T=8", "-DSIZEOF_INT=4", "-DSIZEOF_LONG=8", "-DSIZEOF_OFF_T=8", "-DSIZEOF_SHORT=2", "-DSIZEOF_SIZE_T=8", "-DSIZEOF_TIME_T=8", "-DSTDC_HEADERS=1", "-DSTRERROR_R_TYPE_ARG3=size_t", "-DTIME_WITH_SYS_TIME=1", "-DUSE_THREADS_POSIX=1", "-DUSE_UNIX_SOCKETS=1", # Extra defines needed by curl "-DBUILDING_LIBCURL", "-DCURL_HIDDEN_SYMBOLS", ] LINUX_CURL_COPTS = [ "-DHAVE_LINUX_TCP_H=1", "-DHAVE_MSG_NOSIGNAL=1", ] CURL_COPTS = select({ "//:windows": [ # Disable everything else except HTTP protocol. "/DHTTP_ONLY=1", "/DCURL_STATICLIB", "/DWIN32", "/DBUILDING_LIBCURL", "/DUSE_WIN32_IDN", "/DWANT_IDN_PROTOTYPES", "/DUSE_IPV6", "/DUSE_WINDOWS_SSPI", "/DUSE_SCHANNEL", ], "//:osx": BASE_CURL_COPTS, "//conditions:default": BASE_CURL_COPTS + LINUX_CURL_COPTS, }) prometheus-cpp-1.0.2/bazel/dummy_export.h.tpl000066400000000000000000000001071446411370600212710ustar00rootroot00000000000000#pragma once #define {BASE_NAME}_EXPORT #define {BASE_NAME}_NO_EXPORT prometheus-cpp-1.0.2/bazel/export_header.bzl000066400000000000000000000012541446411370600211340ustar00rootroot00000000000000def _generate_dummy_export_header_impl(ctx): ctx.actions.expand_template( template = ctx.file._template, output = ctx.outputs.header_file, substitutions = { "{BASE_NAME}": ctx.attr.basename, }, ) generate_dummy_export_header = rule( attrs = { "basename": attr.string(mandatory = True), "header": attr.string(mandatory = True), "_template": attr.label( allow_single_file = True, default = Label("@com_github_jupp0r_prometheus_cpp//bazel:dummy_export.h.tpl"), ), }, implementation = _generate_dummy_export_header_impl, outputs = {"header_file": "%{header}"}, ) prometheus-cpp-1.0.2/bazel/repositories.bzl000066400000000000000000000041421446411370600210310ustar00rootroot00000000000000load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") def prometheus_cpp_repositories(): maybe( http_archive, name = "civetweb", strip_prefix = "civetweb-1.15", sha256 = "90a533422944ab327a4fbb9969f0845d0dba05354f9cacce3a5005fa59f593b9", urls = [ "https://github.com/civetweb/civetweb/archive/v1.15.tar.gz", ], build_file = "@com_github_jupp0r_prometheus_cpp//bazel:civetweb.BUILD", ) maybe( http_archive, name = "com_google_googletest", sha256 = "b4870bf121ff7795ba20d20bcdd8627b8e088f2d1dab299a031c1034eddc93d5", strip_prefix = "googletest-release-1.11.0", urls = [ "https://github.com/google/googletest/archive/release-1.11.0.tar.gz", ], ) maybe( http_archive, name = "com_github_curl", sha256 = "93fb2cd4b880656b4e8589c912a9fd092750166d555166370247f09d18f5d0c0", strip_prefix = "curl-7.83.1", urls = [ "https://github.com/curl/curl/releases/download/curl-7_83_1/curl-7.83.1.tar.gz", "https://curl.haxx.se/download/curl-7.83.1.tar.gz", ], build_file = "@com_github_jupp0r_prometheus_cpp//bazel:curl.BUILD", ) maybe( http_archive, name = "com_github_google_benchmark", sha256 = "6132883bc8c9b0df5375b16ab520fac1a85dc9e4cf5be59480448ece74b278d4", strip_prefix = "benchmark-1.6.1", urls = [ "https://github.com/google/benchmark/archive/v1.6.1.tar.gz", ], ) maybe( http_archive, name = "net_zlib_zlib", sha256 = "91844808532e5ce316b3c010929493c0244f3d37593afd6de04f71821d5136d9", strip_prefix = "zlib-1.2.12", urls = [ "https://mirror.bazel.build/zlib.net/zlib-1.2.12.tar.gz", "https://zlib.net/zlib-1.2.12.tar.gz", "https://storage.googleapis.com/bazel-mirror/zlib.net/zlib-1.2.12.tar.gz", ], build_file = "@com_github_jupp0r_prometheus_cpp//bazel:zlib.BUILD", ) prometheus-cpp-1.0.2/bazel/zlib.BUILD000066400000000000000000000011231446411370600173060ustar00rootroot00000000000000# copied from: https://github.com/bazelbuild/bazel/blob/master/third_party/zlib/BUILD licenses(["notice"]) # BSD/MIT-like license (for zlib) cc_library( name = "z", srcs = glob(["*.c"]), hdrs = glob(["*.h"]), # Use -Dverbose=-1 to turn off zlib's trace logging. (bazelbuild/bazel#3280) copts = [ "-w", "-Dverbose=-1", ], includes = ["."], local_defines = select({ "@bazel_tools//src/conditions:windows": [], "//conditions:default": [ "Z_HAVE_UNISTD_H", ], }), visibility = ["//visibility:public"], ) prometheus-cpp-1.0.2/cmake/000077500000000000000000000000001446411370600155535ustar00rootroot00000000000000prometheus-cpp-1.0.2/cmake/CheckAtomic.cmake000066400000000000000000000024171446411370600207330ustar00rootroot00000000000000# Inspired by CheckAtomic.cmake from LLVM project: # https://github.com/llvm/llvm-project/blob/master/llvm/cmake/modules/CheckAtomic.cmake # # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception include(CheckCXXSourceCompiles) include(CheckLibraryExists) function(check_working_cxx_atomics varname) check_cxx_source_compiles(" #include #include std::atomic x(0); int main() { std::uint64_t i = x.load(std::memory_order_relaxed); return static_cast(i); } " ${varname}) endfunction() if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU") # First check if atomics work without the library. check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB) # If not, check if the library exists, and atomics work with it. if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB) check_library_exists(atomic __atomic_load_8 "" HAVE_CXX_LIBATOMIC) if(HAVE_CXX_LIBATOMIC) list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic") check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB) if(NOT HAVE_CXX_ATOMICS_WITH_LIB) message(FATAL_ERROR "Host compiler must support 64-bit std::atomic!") endif() else() message(FATAL_ERROR "Host compiler appears to require libatomic for 64-bit operations, but cannot find it.") endif() endif() endif() prometheus-cpp-1.0.2/cmake/FindTelegraf.cmake000066400000000000000000000003571446411370600211140ustar00rootroot00000000000000find_program(Telegraf_EXECUTABLE NAMES telegraf) mark_as_advanced(Telegraf_EXECUTABLE) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Telegraf FOUND_VAR Telegraf_FOUND REQUIRED_VARS Telegraf_EXECUTABLE ) prometheus-cpp-1.0.2/cmake/civetweb-3rdparty-config.cmake000066400000000000000000000035311446411370600234000ustar00rootroot00000000000000get_filename_component(_IMPORT_PREFIX "${PROJECT_SOURCE_DIR}/3rdparty/civetweb/" ABSOLUTE) macro(set_and_check _var _file) set(${_var} "${_file}") if(NOT EXISTS "${_file}") message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") endif() endmacro() set_and_check(CIVETWEB_INCLUDE_DIR ${_IMPORT_PREFIX}/include) set(CIVETWEB_INCLUDE_DIRS "${CIVETWEB_INCLUDE_DIR}") add_library(civetweb OBJECT ${_IMPORT_PREFIX}/include/CivetServer.h ${_IMPORT_PREFIX}/include/civetweb.h ${_IMPORT_PREFIX}/src/CivetServer.cpp ${_IMPORT_PREFIX}/src/civetweb.c ${_IMPORT_PREFIX}/src/handle_form.inl ${_IMPORT_PREFIX}/src/md5.inl ) set_property(TARGET civetweb PROPERTY PUBLIC_HEADER ${_IMPORT_PREFIX}/include/CivetServer.h ${_IMPORT_PREFIX}/include/civetweb.h ) target_compile_definitions(civetweb PRIVATE CIVETWEB_API= USE_IPV6 NDEBUG NO_CGI NO_CACHING NO_FILES SOCKET_TIMEOUT_QUANTUM=200 ) target_compile_options(civetweb PRIVATE $<$:-w> $<$:-w> ) target_include_directories(civetweb PRIVATE ${CIVETWEB_INCLUDE_DIRS} ) if(THIRDPARTY_CIVETWEB_WITH_SSL) include(CMakeFindDependencyMacro) find_dependency(OpenSSL) if(OPENSSL_VERSION VERSION_GREATER_EQUAL 1.1) target_compile_definitions(civetweb PRIVATE OPENSSL_API_1_1) endif() target_compile_definitions(civetweb PRIVATE NO_SSL_DL) target_link_libraries(civetweb PUBLIC OpenSSL::SSL) else() target_compile_definitions(civetweb PRIVATE NO_SSL) endif() if(BUILD_SHARED_LIBS) set_target_properties(civetweb PROPERTIES POSITION_INDEPENDENT_CODE ON C_VISIBILITY_PRESET hidden CXX_VISIBILITY_PRESET hidden VISIBILITY_INLINES_HIDDEN ON ) endif() set_target_properties(civetweb PROPERTIES C_INCLUDE_WHAT_YOU_USE "" CXX_INCLUDE_WHAT_YOU_USE "" ) prometheus-cpp-1.0.2/cmake/googlemock-3rdparty-config.cmake000066400000000000000000000013671446411370600237230ustar00rootroot00000000000000get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../3rdparty/googletest/" ABSOLUTE) find_package(Threads QUIET) add_library(gmock_main STATIC EXCLUDE_FROM_ALL ${_IMPORT_PREFIX}/googletest/src/gtest-all.cc ${_IMPORT_PREFIX}/googlemock/src/gmock-all.cc ${_IMPORT_PREFIX}/googlemock/src/gmock_main.cc ) target_include_directories(gmock_main SYSTEM PUBLIC ${_IMPORT_PREFIX}/googletest/include ${_IMPORT_PREFIX}/googlemock/include PRIVATE ${_IMPORT_PREFIX}/googletest ${_IMPORT_PREFIX}/googlemock ) target_link_libraries(gmock_main PRIVATE Threads::Threads ) add_library(GTest::gmock_main ALIAS gmock_main) set_target_properties(gmock_main PROPERTIES C_INCLUDE_WHAT_YOU_USE "" CXX_INCLUDE_WHAT_YOU_USE "" ) prometheus-cpp-1.0.2/cmake/googletest.imp000066400000000000000000000004401446411370600204340ustar00rootroot00000000000000[ { include: [ "@", private, "", public ] }, { include: [ "@", private, "", public ] }, { include: [ "@", private, "", public ]}, { include: [ "@", private, "", public ]} ] prometheus-cpp-1.0.2/cmake/project-import-cmake/000077500000000000000000000000001446411370600216075ustar00rootroot00000000000000prometheus-cpp-1.0.2/cmake/project-import-cmake/CMakeLists.txt000066400000000000000000000007601446411370600243520ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.12 FATAL_ERROR) project(prometheus-cpp-import) set(CMAKE_CXX_STANDARD 11) find_package(prometheus-cpp CONFIG REQUIRED) if(PROMETHEUS_CPP_ENABLE_PUSH) add_executable(sample-client sample_client.cc) target_link_libraries(sample-client PRIVATE prometheus-cpp::push $<$:Ws2_32>) endif() if(PROMETHEUS_CPP_ENABLE_PULL) add_executable(sample-server sample_server.cc) target_link_libraries(sample-server PRIVATE prometheus-cpp::pull) endif() prometheus-cpp-1.0.2/cmake/project-import-cmake/sample_client.cc000077700000000000000000000000001446411370600351502../../push/tests/integration/sample_client.ccustar00rootroot00000000000000prometheus-cpp-1.0.2/cmake/project-import-cmake/sample_server.cc000077700000000000000000000000001446411370600352252../../pull/tests/integration/sample_server.ccustar00rootroot00000000000000prometheus-cpp-1.0.2/cmake/project-import-pkgconfig/000077500000000000000000000000001446411370600224765ustar00rootroot00000000000000prometheus-cpp-1.0.2/cmake/project-import-pkgconfig/CMakeLists.txt000066400000000000000000000013211446411370600252330ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.12 FATAL_ERROR) project(prometheus-cpp-import) set(CMAKE_CXX_STANDARD 11) find_package(PkgConfig REQUIRED) pkg_check_modules(PROMETHEUS_CPP_CORE REQUIRED prometheus-cpp-core) pkg_check_modules(PROMETHEUS_CPP_PUSH IMPORTED_TARGET prometheus-cpp-push) pkg_check_modules(PROMETHEUS_CPP_PULL IMPORTED_TARGET prometheus-cpp-pull) if(PROMETHEUS_CPP_PUSH_FOUND) add_executable(sample-client sample_client.cc) target_link_libraries(sample-client PRIVATE PkgConfig::PROMETHEUS_CPP_PUSH $<$:Ws2_32>) endif() if(PROMETHEUS_CPP_PULL_FOUND) add_executable(sample-server sample_server.cc) target_link_libraries(sample-server PRIVATE PkgConfig::PROMETHEUS_CPP_PULL) endif() prometheus-cpp-1.0.2/cmake/project-import-pkgconfig/sample_client.cc000077700000000000000000000000001446411370600360372../../push/tests/integration/sample_client.ccustar00rootroot00000000000000prometheus-cpp-1.0.2/cmake/project-import-pkgconfig/sample_server.cc000077700000000000000000000000001446411370600361142../../pull/tests/integration/sample_server.ccustar00rootroot00000000000000prometheus-cpp-1.0.2/cmake/prometheus-cpp-config.cmake.in000066400000000000000000000017401446411370600234020ustar00rootroot00000000000000@PACKAGE_INIT@ include(CMakeFindDependencyMacro) set_and_check(prometheus-cpp_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") set(PROMETHEUS_CPP_ENABLE_PULL @ENABLE_PULL@) set(PROMETHEUS_CPP_ENABLE_PUSH @ENABLE_PUSH@) set(PROMETHEUS_CPP_USE_COMPRESSION @ENABLE_COMPRESSION@) set(PROMETHEUS_CPP_USE_THIRDPARTY_LIBRARIES @USE_THIRDPARTY_LIBRARIES@) set(PROMETHEUS_CPP_THIRDPARTY_CIVETWEB_WITH_SSL @THIRDPARTY_CIVETWEB_WITH_SSL@) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) find_dependency(Threads) unset(CMAKE_THREAD_PREFER_PTHREAD) if(PROMETHEUS_CPP_ENABLE_PULL) if(PROMETHEUS_CPP_USE_THIRDPARTY_LIBRARIES) if(PROMETHEUS_CPP_THIRDPARTY_CIVETWEB_WITH_SSL) find_dependency(OpenSSL) endif() else() find_dependency(civetweb) endif() endif() if(PROMETHEUS_CPP_ENABLE_PULL AND PROMETHEUS_CPP_USE_COMPRESSION) find_dependency(ZLIB) endif() if(PROMETHEUS_CPP_ENABLE_PUSH) find_dependency(CURL) endif() include("${CMAKE_CURRENT_LIST_DIR}/prometheus-cpp-targets.cmake") prometheus-cpp-1.0.2/cmake/prometheus-cpp-core.pc.in000066400000000000000000000006531446411370600224110ustar00rootroot00000000000000prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} includedir=@PROMETHEUS_CPP_PKGCONFIG_INCLUDEDIR@ libdir=@PROMETHEUS_CPP_PKGCONFIG_LIBDIR@ Name: @PROJECT_NAME@-core Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_HOMEPAGE_URL@ Version: @PROJECT_VERSION@ Requires: Requires.private: @PKGCONFIG_REQUIRES@ Cflags: -I${includedir} Libs: -L${libdir} -l@PROJECT_NAME@-core Libs.private: @CMAKE_THREAD_LIBS_INIT@ @PKGCONFIG_LIBS@prometheus-cpp-1.0.2/cmake/prometheus-cpp-pull.pc.in000066400000000000000000000007001446411370600224260ustar00rootroot00000000000000prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} includedir=@PROMETHEUS_CPP_PKGCONFIG_INCLUDEDIR@ libdir=@PROMETHEUS_CPP_PKGCONFIG_LIBDIR@ Name: @PROJECT_NAME@-pull Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_HOMEPAGE_URL@ Version: @PROJECT_VERSION@ Requires: @PROJECT_NAME@-core Requires.private: @PKGCONFIG_REQUIRES@ Cflags: -I${includedir} Libs: -L${libdir} -l@PROJECT_NAME@-pull Libs.private: @CMAKE_THREAD_LIBS_INIT@ @PKGCONFIG_LIBS@ prometheus-cpp-1.0.2/cmake/prometheus-cpp-push.pc.in000066400000000000000000000007001446411370600224310ustar00rootroot00000000000000prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} includedir=@PROMETHEUS_CPP_PKGCONFIG_INCLUDEDIR@ libdir=@PROMETHEUS_CPP_PKGCONFIG_LIBDIR@ Name: @PROJECT_NAME@-push Description: @PROJECT_DESCRIPTION@ URL: @PROJECT_HOMEPAGE_URL@ Version: @PROJECT_VERSION@ Requires: @PROJECT_NAME@-core Requires.private: @PKGCONFIG_REQUIRES@ Cflags: -I${includedir} Libs: -L${libdir} -l@PROJECT_NAME@-push Libs.private: @CMAKE_THREAD_LIBS_INIT@ @PKGCONFIG_LIBS@ prometheus-cpp-1.0.2/core/000077500000000000000000000000001446411370600154235ustar00rootroot00000000000000prometheus-cpp-1.0.2/core/BUILD.bazel000066400000000000000000000007371446411370600173100ustar00rootroot00000000000000load("//bazel:export_header.bzl", "generate_dummy_export_header") generate_dummy_export_header( name = "export_header", basename = "PROMETHEUS_CPP_CORE", header = "include/prometheus/detail/core_export.h", ) cc_library( name = "core", srcs = glob([ "src/**/*.cc", "src/**/*.h", ]), hdrs = glob( ["include/**/*.h"], ) + [":export_header"], strip_include_prefix = "include", visibility = ["//visibility:public"], ) prometheus-cpp-1.0.2/core/CMakeLists.txt000066400000000000000000000041561446411370600201710ustar00rootroot00000000000000 add_library(core src/check_names.cc src/counter.cc src/detail/builder.cc src/detail/ckms_quantiles.cc src/detail/time_window_quantiles.cc src/detail/utils.cc src/family.cc src/gauge.cc src/histogram.cc src/registry.cc src/serializer.cc src/summary.cc src/text_serializer.cc ) add_library(${PROJECT_NAME}::core ALIAS core) target_link_libraries(core PRIVATE Threads::Threads $<$,$>>:rt> ) if(HAVE_CXX_LIBATOMIC) # the exported library config must use libatomic unconditionally # (the HAVE_CXX_LIBATOMIC variable should not leak into the target config) target_link_libraries(core PUBLIC atomic) endif() target_include_directories(core PUBLIC $ $ ) set_target_properties(core PROPERTIES OUTPUT_NAME ${PROJECT_NAME}-core DEFINE_SYMBOL PROMETHEUS_CPP_CORE_EXPORTS VERSION "${PROJECT_VERSION}" SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" ) generate_export_header(core BASE_NAME ${PROJECT_NAME}-core EXPORT_FILE_NAME include/prometheus/detail/core_export.h ) install( TARGETS core EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) install( DIRECTORY include/ ${CMAKE_CURRENT_BINARY_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) if(GENERATE_PKGCONFIG) set(PKGCONFIG_LIBS) set(PKGCONFIG_REQUIRES) if(HAVE_CXX_LIBATOMIC) string(APPEND PKGCONFIG_LIBS " -latomic") endif() configure_file( ${PROJECT_SOURCE_DIR}/cmake/prometheus-cpp-core.pc.in ${CMAKE_CURRENT_BINARY_DIR}/prometheus-cpp-core.pc @ONLY ) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/prometheus-cpp-core.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig ) unset(PKGCONFIG_LIBS) unset(PKGCONFIG_REQUIRES) endif() if(ENABLE_TESTING) add_subdirectory(tests) endif() if(benchmark_FOUND) add_subdirectory(benchmarks) endif() prometheus-cpp-1.0.2/core/benchmarks/000077500000000000000000000000001446411370600175405ustar00rootroot00000000000000prometheus-cpp-1.0.2/core/benchmarks/BUILD.bazel000066400000000000000000000003201446411370600214110ustar00rootroot00000000000000cc_binary( name = "benchmarks", srcs = glob([ "*.cc", "*.h", ]), linkstatic = True, deps = [ "//core", "@com_github_google_benchmark//:benchmark", ], ) prometheus-cpp-1.0.2/core/benchmarks/CMakeLists.txt000066400000000000000000000006171446411370600223040ustar00rootroot00000000000000 add_executable(benchmarks main.cc benchmark_helpers.cc benchmark_helpers.h counter_bench.cc gauge_bench.cc histogram_bench.cc registry_bench.cc summary_bench.cc ) target_link_libraries(benchmarks PRIVATE ${PROJECT_NAME}::core benchmark::benchmark ) add_test( NAME benchmarks COMMAND benchmarks ) set_property( TEST benchmarks APPEND PROPERTY LABELS Benchmark ) prometheus-cpp-1.0.2/core/benchmarks/benchmark_helpers.cc000066400000000000000000000014511446411370600235240ustar00rootroot00000000000000#include "benchmark_helpers.h" #include #include #include std::string GenerateRandomString(std::size_t length) { auto randchar = []() -> char { const char charset[] = "abcdefghijklmnopqrstuvwxyz"; const std::size_t max_index = (sizeof(charset) - 1); return charset[rand() % max_index]; }; std::string str(length, 0); std::generate_n(str.begin(), length, randchar); return str; } prometheus::Labels GenerateRandomLabels(std::size_t number_of_pairs) { const auto label_character_count = 10; auto label_pairs = prometheus::Labels{}; for (std::size_t i = 0; i < number_of_pairs; i++) { label_pairs.insert({GenerateRandomString(label_character_count), GenerateRandomString(label_character_count)}); } return label_pairs; } prometheus-cpp-1.0.2/core/benchmarks/benchmark_helpers.h000066400000000000000000000003211446411370600233610ustar00rootroot00000000000000#pragma once #include #include #include "prometheus/labels.h" std::string GenerateRandomString(std::size_t length); prometheus::Labels GenerateRandomLabels(std::size_t number_of_labels); prometheus-cpp-1.0.2/core/benchmarks/counter_bench.cc000066400000000000000000000017131446411370600226670ustar00rootroot00000000000000#include #include "prometheus/counter.h" #include "prometheus/family.h" #include "prometheus/registry.h" static void BM_Counter_Increment(benchmark::State& state) { using prometheus::BuildCounter; using prometheus::Counter; using prometheus::Registry; Registry registry; auto& counter_family = BuildCounter().Name("benchmark_counter").Help("").Register(registry); auto& counter = counter_family.Add({}); while (state.KeepRunning()) counter.Increment(); } BENCHMARK(BM_Counter_Increment); static void BM_Counter_Collect(benchmark::State& state) { using prometheus::BuildCounter; using prometheus::Counter; using prometheus::Registry; Registry registry; auto& counter_family = BuildCounter().Name("benchmark_counter").Help("").Register(registry); auto& counter = counter_family.Add({}); while (state.KeepRunning()) { benchmark::DoNotOptimize(counter.Collect()); }; } BENCHMARK(BM_Counter_Collect); prometheus-cpp-1.0.2/core/benchmarks/gauge_bench.cc000066400000000000000000000032721446411370600223020ustar00rootroot00000000000000#include #include "prometheus/family.h" #include "prometheus/gauge.h" #include "prometheus/registry.h" static void BM_Gauge_Increment(benchmark::State& state) { using prometheus::BuildGauge; using prometheus::Gauge; using prometheus::Registry; Registry registry; auto& gauge_family = BuildGauge().Name("benchmark_gauge").Help("").Register(registry); auto& gauge = gauge_family.Add({}); while (state.KeepRunning()) gauge.Increment(2); } BENCHMARK(BM_Gauge_Increment); static void BM_Gauge_Decrement(benchmark::State& state) { using prometheus::BuildGauge; using prometheus::Gauge; using prometheus::Registry; Registry registry; auto& gauge_family = BuildGauge().Name("benchmark_gauge").Help("").Register(registry); auto& gauge = gauge_family.Add({}); while (state.KeepRunning()) gauge.Decrement(2); } BENCHMARK(BM_Gauge_Decrement); static void BM_Gauge_SetToCurrentTime(benchmark::State& state) { using prometheus::BuildGauge; using prometheus::Gauge; using prometheus::Registry; Registry registry; auto& gauge_family = BuildGauge().Name("benchmark_gauge").Help("").Register(registry); auto& gauge = gauge_family.Add({}); while (state.KeepRunning()) gauge.SetToCurrentTime(); } BENCHMARK(BM_Gauge_SetToCurrentTime); static void BM_Gauge_Collect(benchmark::State& state) { using prometheus::BuildGauge; using prometheus::Gauge; using prometheus::Registry; Registry registry; auto& gauge_family = BuildGauge().Name("benchmark_gauge").Help("").Register(registry); auto& gauge = gauge_family.Add({}); while (state.KeepRunning()) { benchmark::DoNotOptimize(gauge.Collect()); }; } BENCHMARK(BM_Gauge_Collect); prometheus-cpp-1.0.2/core/benchmarks/histogram_bench.cc000066400000000000000000000043441446411370600232100ustar00rootroot00000000000000#include #include #include #include #include #include "prometheus/family.h" #include "prometheus/histogram.h" #include "prometheus/registry.h" using prometheus::Histogram; static Histogram::BucketBoundaries CreateLinearBuckets(std::int64_t start, std::int64_t end, std::int64_t step) { auto bucket_boundaries = Histogram::BucketBoundaries{}; for (auto i = start; i < end; i += step) { bucket_boundaries.push_back(i); } return bucket_boundaries; } static void BM_Histogram_Observe(benchmark::State& state) { using prometheus::BuildHistogram; using prometheus::Histogram; using prometheus::Registry; const auto number_of_buckets = state.range(0); Registry registry; auto& histogram_family = BuildHistogram().Name("benchmark_histogram").Help("").Register(registry); auto bucket_boundaries = CreateLinearBuckets(0, number_of_buckets - 1, 1); auto& histogram = histogram_family.Add({}, bucket_boundaries); std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> d(0, number_of_buckets); while (state.KeepRunning()) { auto observation = d(gen); auto start = std::chrono::high_resolution_clock::now(); histogram.Observe(observation); auto end = std::chrono::high_resolution_clock::now(); auto elapsed_seconds = std::chrono::duration_cast>(end - start); state.SetIterationTime(elapsed_seconds.count()); } } BENCHMARK(BM_Histogram_Observe)->Range(0, 4096); static void BM_Histogram_Collect(benchmark::State& state) { using prometheus::BuildHistogram; using prometheus::Histogram; using prometheus::Registry; const auto number_of_buckets = state.range(0); Registry registry; auto& histogram_family = BuildHistogram().Name("benchmark_histogram").Help("").Register(registry); auto bucket_boundaries = CreateLinearBuckets(0, number_of_buckets - 1, 1); auto& histogram = histogram_family.Add({}, bucket_boundaries); while (state.KeepRunning()) { benchmark::DoNotOptimize(histogram.Collect()); } } BENCHMARK(BM_Histogram_Collect)->Range(0, 4096); prometheus-cpp-1.0.2/core/benchmarks/main.cc000066400000000000000000000000641446411370600207730ustar00rootroot00000000000000#include BENCHMARK_MAIN(); prometheus-cpp-1.0.2/core/benchmarks/registry_bench.cc000066400000000000000000000025601446411370600230610ustar00rootroot00000000000000#include #include #include "benchmark_helpers.h" #include "prometheus/counter.h" #include "prometheus/family.h" #include "prometheus/registry.h" static void BM_Registry_CreateFamily(benchmark::State& state) { using prometheus::BuildCounter; using prometheus::Counter; using prometheus::Registry; Registry registry; while (state.KeepRunning()) BuildCounter().Name("benchmark_counter").Help("").Register(registry); } BENCHMARK(BM_Registry_CreateFamily); static void BM_Registry_CreateCounter(benchmark::State& state) { using prometheus::BuildCounter; using prometheus::Counter; using prometheus::Registry; Registry registry; auto& counter_family = BuildCounter() .Labels(GenerateRandomLabels(10)) .Name("benchmark_counter") .Help("") .Register(registry); while (state.KeepRunning()) { auto labels = GenerateRandomLabels(state.range(0)); auto start = std::chrono::high_resolution_clock::now(); counter_family.Add(labels); auto end = std::chrono::high_resolution_clock::now(); auto elapsed_seconds = std::chrono::duration_cast>(end - start); state.SetIterationTime(elapsed_seconds.count()); } } BENCHMARK(BM_Registry_CreateCounter)->Range(0, 4096); prometheus-cpp-1.0.2/core/benchmarks/summary_bench.cc000066400000000000000000000102571446411370600227100ustar00rootroot00000000000000#include #include #include #include #include #include #include "prometheus/family.h" #include "prometheus/registry.h" #include "prometheus/summary.h" using prometheus::Summary; static const auto ITERATIONS = 262144; static Summary::Quantiles CreateLinearQuantiles(int count) { static auto generator = [](double x) { static auto exp = [](double x) { static const double A = 2; return 1 - std::exp(-A * x); }; return exp(x) / exp(1); }; auto quantiles = Summary::Quantiles{}; for (auto i = 0; i < count; ++i) { quantiles.emplace_back(generator(double(i) / count), 0.01); } return quantiles; } static void BM_Summary_Observe(benchmark::State& state) { using prometheus::BuildSummary; using prometheus::Registry; using prometheus::Summary; const auto number_of_quantiles = state.range(0); Registry registry; auto& summary_family = BuildSummary().Name("benchmark_summary").Help("").Register(registry); auto quantiles = CreateLinearQuantiles(number_of_quantiles); auto& summary = summary_family.Add({}, quantiles); std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> d(0, 100); while (state.KeepRunning()) { auto observation = d(gen); auto start = std::chrono::high_resolution_clock::now(); summary.Observe(observation); auto end = std::chrono::high_resolution_clock::now(); auto elapsed_seconds = std::chrono::duration_cast>(end - start); state.SetIterationTime(elapsed_seconds.count()); } } BENCHMARK(BM_Summary_Observe)->Range(0, 64)->Iterations(ITERATIONS); static void BM_Summary_Collect(benchmark::State& state) { using prometheus::BuildSummary; using prometheus::Registry; using prometheus::Summary; const auto number_of_quantiles = state.range(0); const auto number_of_entries = state.range(1); Registry registry; auto& summary_family = BuildSummary().Name("benchmark_summary").Help("").Register(registry); auto quantiles = CreateLinearQuantiles(number_of_quantiles); auto& summary = summary_family.Add({}, quantiles); std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> d(0, 100); for (auto i = 1; i <= number_of_entries; ++i) summary.Observe(d(gen)); while (state.KeepRunning()) { benchmark::DoNotOptimize(summary.Collect()); } } BENCHMARK(BM_Summary_Collect)->RangePair(0, 64, 0, ITERATIONS); static void BM_Summary_Observe_Common(benchmark::State& state) { using prometheus::BuildSummary; using prometheus::Registry; using prometheus::Summary; Registry registry; auto& summary_family = BuildSummary().Name("benchmark_summary").Help("").Register(registry); auto& summary = summary_family.Add( {}, Summary::Quantiles{ {0.5, 0.05}, {0.9, 0.01}, {0.95, 0.005}, {0.99, 0.001}}); std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> d(0, 100); while (state.KeepRunning()) { auto observation = d(gen); auto start = std::chrono::high_resolution_clock::now(); summary.Observe(observation); auto end = std::chrono::high_resolution_clock::now(); auto elapsed_seconds = std::chrono::duration_cast>(end - start); state.SetIterationTime(elapsed_seconds.count()); } } BENCHMARK(BM_Summary_Observe_Common)->Iterations(ITERATIONS); static void BM_Summary_Collect_Common(benchmark::State& state) { using prometheus::BuildSummary; using prometheus::Registry; using prometheus::Summary; const auto number_of_entries = state.range(0); Registry registry; auto& summary_family = BuildSummary().Name("benchmark_summary").Help("").Register(registry); auto& summary = summary_family.Add( {}, Summary::Quantiles{ {0.5, 0.05}, {0.9, 0.01}, {0.95, 0.005}, {0.99, 0.001}}); std::random_device rd; std::mt19937 gen(rd()); std::uniform_real_distribution<> d(0, 100); for (auto i = 1; i <= number_of_entries; ++i) summary.Observe(d(gen)); while (state.KeepRunning()) { benchmark::DoNotOptimize(summary.Collect()); } } BENCHMARK(BM_Summary_Collect_Common)->Range(0, ITERATIONS); prometheus-cpp-1.0.2/core/include/000077500000000000000000000000001446411370600170465ustar00rootroot00000000000000prometheus-cpp-1.0.2/core/include/prometheus/000077500000000000000000000000001446411370600212415ustar00rootroot00000000000000prometheus-cpp-1.0.2/core/include/prometheus/check_names.h000066400000000000000000000004231446411370600236510ustar00rootroot00000000000000#pragma once #include #include "prometheus/detail/core_export.h" namespace prometheus { PROMETHEUS_CPP_CORE_EXPORT bool CheckMetricName(const std::string& name); PROMETHEUS_CPP_CORE_EXPORT bool CheckLabelName(const std::string& name); } // namespace prometheus prometheus-cpp-1.0.2/core/include/prometheus/client_metric.h000066400000000000000000000025231446411370600242350ustar00rootroot00000000000000#pragma once #include #include #include #include #include "prometheus/detail/core_export.h" namespace prometheus { struct PROMETHEUS_CPP_CORE_EXPORT ClientMetric { // Label struct Label { std::string name; std::string value; bool operator<(const Label& rhs) const { return std::tie(name, value) < std::tie(rhs.name, rhs.value); } bool operator==(const Label& rhs) const { return std::tie(name, value) == std::tie(rhs.name, rhs.value); } }; std::vector