Coder Social home page Coder Social logo

prometheus-client-c's Introduction

prometheus-client-c

Build Status

This project provides shared libraries for instrumenting software via Prometheus

  • libprom - Provides the core API. Resources such as counters, gauges, histograms, and collector registries can be found here. This library has no dependencies on third-party libraries; however, it does rely on pthreads native to POSIX systems.
  • libpromhttp - Provides a simple web handler to expose Prometheus metrics for scraping. This library has a dependency on libmicrohttpd.

Documentation can be found at the documentation site and an example can be found under example/. Check under the releases tab for tarballs and debian installers

Versioning

This project generally follows semantic versioning. For each version you can find a corresponding release under the releases type. Do not expect the master branch to maintain alignment with the latest release. It may contain changes not yet released.

Development

The only development dependencies required to get started are Docker, Make and Bash. Navigate to the root fo this project directory and execute make. This process will build the development container, build libprom and libpromhttp, run the unit tests and execute the smoke tests.

The stages of the development workflow are automated via auto which can be found in the root of this project directory. Execute bash auto -h for information regarding the different subcommands. Information for each subcommand can be obtained by executing bash auto CMD -h.

Contributing

Thank you for your interest in contributing to prometheus-client-c! There two primary ways to get involved with this project: documentation and code modifications. In either case, the process is identical.

General Rules for Contribution

  • Open An Issue: Before opening a PR or starting any work, open an issue. In the issue, describe the problem you want to fix and how you would like to fix it. The level of detail should match the relative size of the proposed change. This will allow us to work together to determine the best path forward towards a sound solution.

  • Open a Pull Request: After you have gotten confirmation on your proposed change it's time to get to work! Create a fork and make all of your updates in said fork. For each commit, you must prefix the commit with the associated issue. For example: #12 - Fixing typo in documentation. Before opening a pull request, review the commit log for your fork. If any of your commit messages are extraneous, squash said commits using git rebase. Once you're happy with your changes and your commit log, open a pull request against the master branch.

  • Engage in the Code Review: After submitting your pull request, there may be some requests for changes. If you have any questions or concerns, please do not hesitate to make them known. The code review process is a bidirectional communication process so please do not be shy. Speak up!

Coding Rules for Contribution

  • Please follow the general coding style already present in the project.
    • clang-format your code by executing bash auto format before submitting a PR.
    • Every struct must have a constructor function and destructor function.
    • Every method must pass a pointer to the target struct as the first argument.
    • Every function that is not a constructor or destructor and does not return a value must return an int to signify success with 0 and failure with non-zero.
    • Every function name must begin with the library name. For example, all functions within prom must begin with prom_ and all functions within promhttp must begin with promhttp_.
    • All variables must be underscore delimited (i.e. snake-case).
    • All macros must be captilalized.
    • Every pointer reference must be assigned a NULL value after it is destroyed either by prom_free or its corresponding destructor function.
  • All new functions must introduce a corresponding suite of unit tests.
  • If you add functionality to an existing function, be sure to add a corresponding unit test to verify correctness.

Misc

  • Language level: C11
  • Operating Systems:
    • Ubuntu 20.04
    • Ubuntu 18.04
    • Ubuntu 16.04
    • Debian Buster
    • Debian Stretch
    • Debian Jessie

prometheus-client-c's People

Contributors

andrewwa0 avatar cfsmp3 avatar jecklabs avatar juergenhoetzel avatar lyda avatar michaelxniu avatar miroswan avatar pavelmash avatar prksu avatar qmx avatar taotetek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prometheus-client-c's Issues

prom_*_new functions don't validate metrics names conform to specs

The specs for metrics name define the names must be [a-zA-Z_:][a-zA-Z0-9_:]*

but prom_histogram_new and friends don't validate, or any least the accept - (hyphen) which then results in this error from prometheus:

invalid metric type "gauges gauge"

(that happened with a call like this):

 prom_gauge_new("interleaver-gauges", "All internal interleaver gauges", 2,
                       (const char *[]){"instance_id", "metric"});

Smoke tests don't scrape metrics as they're updating

The smoke tests seem to work by updating a metric a bunch and then scraping. Might it be an idea to run prom2jason or something else to scrape the metrics a few dozen times between // Start each thread and // Join each thread?

Build error: cannot find package

Operating System: Linux x86_64 GNU/Linux
make .

+ tar xzf - -C /usr/local
+ mkdir -p /gopath/{src,bin}
+ printf export GOPATH=/gopath\nexport PATH=$PATH:/usr/local/go/bin:/gopath/bin\n
+ printf #!/usr/bin/env bash\nsource /root/.bash_profile\nexec /bin/bash $@\n
+ chmod +x /entrypoint
+ GOPATH=/gopath /usr/local/go/bin/go get github.com/prometheus/prom2json
+ GOPATH=/gopath /usr/local/go/bin/go install github.com/prometheus/prom2json/cmd/prom2json
+ GOPATH=/gopath /usr/local/go/bin/go get github.com/git-chglog/git-chglog
+ GOPATH=/gopath /usr/local/go/bin/go install github.com/git-chglog/git-chglog/cmd/git-chglog
gopath/src/github.com/git-chglog/git-chglog/cmd/git-chglog/questioner.go:10:2: cannot find package "github.com/AlecAivazis/survey/v2" in any of:
        /usr/local/go/src/github.com/AlecAivazis/survey/v2 (from $GOROOT)
        /gopath/src/github.com/AlecAivazis/survey/v2 (from $GOPATH)
gopath/src/github.com/git-chglog/git-chglog/cmd/git-chglog/cli.go:9:2: cannot find package "github.com/fatih/color" in any of:
        /usr/local/go/src/github.com/fatih/color (from $GOROOT)
        /gopath/src/github.com/fatih/color (from $GOPATH)
gopath/src/github.com/git-chglog/git-chglog/cmd/git-chglog/config.go:8:2: cannot find package "github.com/imdario/mergo" in any of:
        /usr/local/go/src/github.com/imdario/mergo (from $GOROOT)
        /gopath/src/github.com/imdario/mergo (from $GOPATH)
gopath/src/github.com/git-chglog/git-chglog/cmd/git-chglog/logger.go:10:2: cannot find package "github.com/kyokomi/emoji/v2" in any of:
        /usr/local/go/src/github.com/kyokomi/emoji/v2 (from $GOROOT)
        /gopath/src/github.com/kyokomi/emoji/v2 (from $GOPATH)
gopath/src/github.com/git-chglog/git-chglog/cmd/git-chglog/main.go:9:2: cannot find package "github.com/mattn/go-colorable" in any of:
        /usr/local/go/src/github.com/mattn/go-colorable (from $GOROOT)
        /gopath/src/github.com/mattn/go-colorable (from $GOPATH)
gopath/src/github.com/git-chglog/git-chglog/cmd/git-chglog/main.go:11:2: cannot find package "github.com/urfave/cli/v2" in any of:
        /usr/local/go/src/github.com/urfave/cli/v2 (from $GOROOT)
        /gopath/src/github.com/urfave/cli/v2 (from $GOPATH)
gopath/src/github.com/git-chglog/git-chglog/cmd/git-chglog/config_loader.go:6:2: cannot find package "gopkg.in/yaml.v2" in any of:
        /usr/local/go/src/gopkg.in/yaml.v2 (from $GOROOT)
        /gopath/src/gopkg.in/yaml.v2 (from $GOPATH)

Fix dev environment

An update to the Dockerfile removed GOPATH from the environment and consequently removed the prom2json binary from the PATH. Since we're only building (within CI) on changes to C files, it was missed.

We'll need to update the Dockerfile to fix this issue. We also need to update the default make target to only exclude changes to .md files to capture more of what we care about.

Version API

Would it be possible to add an API that returns the version of the library.

How can we build debug versions?

I tried doing AUTO_DEBUG=1 make and I didn't get .o's or .so's with debug info. How can I get builds with the -g flag set on the C compiler?

Precision loss in float rendering

We happened to be looking at this code as part of OpenMetrics, and noticed that there appears to be precision loss in how floating points are rendered by this client library:

sprintf(buffer, "%f", sample->r_value);

The default precision for %f is 6, which is not sufficient for a 64bit floating point which can have 17 significant digits. I believe this should be changed to %.17f.

macos not build (error: incompatible pointer types passing '_Atomic(double) *' to parameter of type 'double)

/Users/fengwei/prometheus-client-c/prom/src/prom_metric_sample.c:69:54: error: incompatible pointer types passing
'_Atomic(double) *' to parameter of type 'double *' [-Werror,-Wincompatible-pointer-types]
if (atomic_compare_exchange_weak(&self->r_value, &old, new)) {
^~~~
/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include/stdatomic.h:143:108: note: expanded from macro
'atomic_compare_exchange_weak'
#define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, des...
^~~~~~~~
/Users/fengwei/prometheus-client-c/prom/src/prom_metric_sample.c:84:54: error: incompatible pointer types passing
'_Atomic(double) *' to parameter of type 'double *' [-Werror,-Wincompatible-pointer-types]
if (atomic_compare_exchange_weak(&self->r_value, &old, new)) {
^~~~
/Library/Developer/CommandLineTools/usr/lib/clang/11.0.0/include/stdatomic.h:143:108: note: expanded from macro
'atomic_compare_exchange_weak'
#define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, des...

--------------------clang version--------------------------------
Apple clang version 11.0.0 (clang-1100.0.33.8)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

---------------os--------------
Darwin Kernel Version 19.6.0: Mon Aug 31 22:12:52 PDT 2020; root:xnu-6153.141.2~1/RELEASE_X86_64 x86_64

Is this library unmaintained?

@pavelmash @miroswan

There are multiple pull requests and issues, but the most recent commit to the repository was 4 years ago.

If this library is no longer maintained, can you please signal that this is the case by using the github archive functionality?

make fails on ubuntu

log is right after docker container is created and updated

..........
Setting up libcairo2:amd64 (1.15.10-2ubuntu0.1) ...
Setting up curl (7.58.0-2ubuntu3.22) ...
Setting up build-essential (12.4ubuntu1) ...
Setting up libpangoft2-1.0-0:amd64 (1.40.14-1ubuntu0.1) ...
Setting up pkg-config (0.29.1-0ubuntu2) ...
Setting up libpangocairo-1.0-0:amd64 (1.40.14-1ubuntu0.1) ...
Setting up libgvc6 (2.40.1-2) ...
Setting up graphviz (2.40.1-2) ...
Processing triggers for libc-bin (2.27-3ubuntu1.6) ...
Processing triggers for mime-support (3.60ubuntu1) ...

  • rm -f /usr/bin/gcc
  • ln -s /usr/bin/gcc-10 /usr/bin/gcc
  • curl -sL https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5-Linux-x86_64.tar.gz
  • tar xzf - -C /opt
  • cp /opt/cmake-3.14.5-Linux-x86_64/bin/ccmake /opt/cmake-3.14.5-Linux-x86_64/bin/cmake /opt/cmake-3.14.5-Linux-x86_64/bin/cmake-gui /opt/cmake-3.14.5-Linux-x86_64/bin/cpack /opt/cmake-3.14.5-Linux-x86_64/bin/ctest /usr/local/bin/
  • cp -R /opt/cmake-3.14.5-Linux-x86_64/share/cmake-3.14 /usr/local/share/
  • curl -sL https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz
  • tar xzf - -C /usr/local
  • mkdir -p /gopath/{src,bin}
  • printf export GOPATH=/gopath\nexport PATH=$PATH:/usr/local/go/bin:/gopath/bin\n
  • printf #!/usr/bin/env bash\nsource /root/.bash_profile\nexec /bin/bash $@\n
  • chmod +x /entrypoint
  • GOPATH=/gopath /usr/local/go/bin/go get github.com/prometheus/prom2json

github.com/prometheus/common/expfmt

gopath/src/github.com/prometheus/common/expfmt/decode.go:89:34: cannot use v (type *io_prometheus_client.MetricFamily) as type protoreflect.ProtoMessage in argument to pbutil.ReadDelimited:
*io_prometheus_client.MetricFamily does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
gopath/src/github.com/prometheus/common/expfmt/encode.go:120:36: cannot use v (type io_prometheus_client.MetricFamily) as type protoreflect.ProtoMessage in argument to pbutil.WriteDelimited:
io_prometheus_client.MetricFamily does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
gopath/src/github.com/prometheus/common/expfmt/text_create.go:46:27: undefined: io.Discard
The command '/bin/sh -c set -x && apt-get update && apt-get install -y apt-utils software-properties-common clang-format && add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get update -y && apt-get install -y curl tar build-essential git pkg-config gdb valgrind gcc-10 libmicrohttpd-dev doxygen graphviz && rm -f /usr/bin/gcc && ln -s /usr/bin/gcc-10 /usr/bin/gcc && curl -sL https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5-Linux-x86_64.tar.gz | tar xzf - -C /opt && cp /opt/cmake-3.14.5-Linux-x86_64/bin/
/usr/local/bin/ && cp -R /opt/cmake-3.14.5-Linux-x86_64/share/cmake-3.14 /usr/local/share/ && curl -sL https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz 2> /dev/null | tar xzf - -C /usr/local && mkdir -p /gopath/{src,bin} && printf 'export GOPATH=/gopath\nexport PATH=$PATH:/usr/local/go/bin:/gopath/bin\n' > /root/.bash_profile && printf '#!/usr/bin/env bash\nsource /root/.bash_profile\nexec /bin/bash $@\n' > /entrypoint && chmod +x /entrypoint && GOPATH=/gopath /usr/local/go/bin/go get github.com/prometheus/prom2json && GOPATH=/gopath /usr/local/go/bin/go install github.com/prometheus/prom2json/cmd/prom2json && GOPATH=/gopath /usr/local/go/bin/go get github.com/git-chglog/git-chglog && GOPATH=/gopath /usr/local/go/bin/go install github.com/git-chglog/git-chglog/cmd/git-chglog && rm -rf /var/lib/apt/lists/
' returned a non-zero code: 2
make[1]: *** [Makefile:2: docker] Error 2
make[1]: Leaving directory '/home/user/GitHub_Releases/prometheus-client-c/docker'
ERROR: Docker Build Failure
make: *** [Makefile:26: clean] Error 2

Support build in local machine (not in docker container)

i want to build this project on my mac (not in a container).

when i run ./auto build i got an error CPack package description file: "/code/README.md" could not be found.

this is full output

$ ./auto build

########################################################################
> Executing build
########################################################################


########################################################################
> prom: CMake Build Stage
########################################################################

-- The C compiler identification is GNU 9.2.0
-- Checking whether C compiler has -isysroot
-- Checking whether C compiler has -isysroot - yes
-- Checking whether C compiler supports OSX deployment target flag
-- Checking whether C compiler supports OSX deployment target flag - yes
-- Check for working C compiler: /usr/local/bin/gcc-9
-- Check for working C compiler: /usr/local/bin/gcc-9 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
CMake Error at /usr/local/Cellar/cmake/3.15.5/share/cmake/Modules/CPack.cmake:523 (message):
  CPack package description file: "/code/README.md" could not be found.
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.15.5/share/cmake/Modules/CPack.cmake:527 (cpack_check_file_exists)
  CMakeLists.txt:136 (include)


-- Configuring incomplete, errors occurred!
See also "/Users/prksu/Developer/c/prometheus-client-c/prom/build/CMakeFiles/CMakeOutput.log".
ERROR: prom: CMake Failure

this error can be solved with change /code/README.md to ${CMAKE_CURRENT_SOURCE_DIR}/../README.md) and i can build this project both in local machine and in container.

i have see README that one of the dependencies needed is a docker. my question, is there a plan to support build this project on the local machine? maybe it would be great.

Failed build against newer libmicrohttpd versions

When trying to compile against newer libmicrohttpd versions it fails with the following errror:

[ 95%] Building C object promhttp/CMakeFiles/promhttp.dir/src/promhttp.c.o
cd /<<PKGBUILDDIR>>/obj-x86_64-linux-gnu/promhttp && /usr/bin/cc -Dpromhttp_EXPORTS -I/<<PKGBUILDDIR>>/promhttp/include -I/<<PKGBUILDDIR>>/
promhttp/../prom/include -I/<<PKGBUILDDIR>>/promhttp/src -I/<<PKGBUILDDIR>>/prom/include -g -O2 -ffile-prefix-map=/<<PKGBUILDDIR>>=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -Werror -Wuninitialized -Wall -Wno-unused-label -
std=gnu11 -std=gnu11 -MD -MT promhttp/CMakeFiles/promhttp.dir/src/promhttp.c.o -MF CMakeFiles/promhttp.dir/src/promhttp.c.o.d -o CMakeFiles
/promhttp.dir/src/promhttp.c.o -c /<<PKGBUILDDIR>>/promhttp/src/promhttp.c
/<<PKGBUILDDIR>>/promhttp/src/promhttp.c: In function ‘promhttp_start_daemon’:
/<<PKGBUILDDIR>>/promhttp/src/promhttp.c:64:54: error: passing argument 5 of ‘MHD_start_daemon’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   64 |   return MHD_start_daemon(flags, port, apc, apc_cls, &promhttp_handler, NULL, MHD_OPTION_END);
      |                                                      ^~~~~~~~~~~~~~~~~
      |                                                      |
      |                                                      int (*)(void *, struct MHD_Connection *, const char *, const char *, const char *, const char *, size_t *, void **) {aka int (*)(void *, struct MHD_Connection *, const char *, const char *, const char *, const char *, long unsigned int *, void **)}
In file included from /<<PKGBUILDDIR>>/promhttp/src/promhttp.c:19:
/usr/include/microhttpd.h:2480:45: note: expected ‘MHD_AccessHandlerCallback’ {aka ‘enum MHD_Result (*)(void *, struct MHD_Connection *, co
nst char *, const char *, const char *, const char *, long unsigned int *, void **)’} but argument is of type ‘int (*)(void *, struct MHD_C
onnection *, const char *, const char *, const char *, const char *, size_t *, void **)’ {aka ‘int (*)(void *, struct MHD_Connection *, con
st char *, const char *, const char *, const char *, long unsigned int *, void **)’}
 2480 |                   MHD_AccessHandlerCallback dh, void *dh_cls,
      |                   ~~~~~~~~~~~~~~~~~~~~~~~~~~^~
cc1: all warnings being treated as errors
make[3]: *** [promhttp/CMakeFiles/promhttp.dir/build.make:79: promhttp/CMakeFiles/promhttp.dir/src/promhttp.c.o] Error 1
make[3]: Leaving directory '/<<PKGBUILDDIR>>/obj-x86_64-linux-gnu'
make[2]: *** [CMakeFiles/Makefile2:145: promhttp/CMakeFiles/promhttp.dir/all] Error 2

Breaking change was introduced in libmicrohttpd back in April last year:

Introduce enum MHD_Result for #MHD_YES/#MHD_NO to avoid using 'int' so much.
Note that this change WILL cause compiler warnings until (most) MHD callbacks
in application code change their return type from 'int' to 'enum MHD_Result'.
That said, avoiding possible confusions of different enums is going to make
the code more robust in the future. For conditional compilation, test
for "MHD_VERSION >= 0x00097002". -CG

Performance bottleneck on prom_map_get_index_internal

I used the Prometheus C client in a high performance network server application. Each server request increments a few prometheus counters (request count, bytes transferred, etc) and observes a few prometheus histograms (latency, request size, etc).

When I ran the cpu profiling from gperftools, I discovered that 24% of all cpu was spent inside the prom_map_get_index_internal function. See the attached screenshot for more details.

I've switched to another library, but wanted to let you know of my findings.
Screen Shot 2021-08-27 at 10 40 29 am

Build static library

It would be useful to introduce a new option in the CMake project to be able to build a static version of the library (prom and/or promhttp).

I will look into it see what I can do and If this works I will open a PR to propose my work (If manage to success)

How to use a Summary-type metric?

Hello, I need to use the summary-type metric, but I can only find the histogram-type in the source code.How do I use the summary metric?

Build fails under Arch Linux (undefined: io.Discard)

I got the following error when trying to build the library:

$ make
...
Step 1/4 : FROM ubuntu:18.04
...
Processing triggers for mime-support (3.60ubuntu1) ...
+ rm -f /usr/bin/gcc
+ ln -s /usr/bin/gcc-10 /usr/bin/gcc
+ curl -sL https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5-Linux-x86_64.tar.gz
+ tar xzf - -C /opt
+ cp /opt/cmake-3.14.5-Linux-x86_64/bin/ccmake /opt/cmake-3.14.5-Linux-x86_64/bin/cmake /opt/cmake-3.14.5-Linux-x86_64/bin/cmake-gui /opt/cmake-3.14.5-Linux-x86_64/bin/cpack /opt/cmake-3.14.5-Linux-x86_64/bin/ctest /usr/local/bin/
+ cp -R /opt/cmake-3.14.5-Linux-x86_64/share/cmake-3.14 /usr/local/share/
+ curl -sL https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz
+ tar xzf - -C /usr/local
+ mkdir -p /gopath/{src,bin}
+ printf export GOPATH=/gopath\nexport PATH=$PATH:/usr/local/go/bin:/gopath/bin\n
+ printf #!/usr/bin/env bash\nsource /root/.bash_profile\nexec /bin/bash $@\n
+ chmod +x /entrypoint
+ GOPATH=/gopath /usr/local/go/bin/go get github.com/prometheus/prom2json
# github.com/prometheus/common/expfmt
gopath/src/github.com/prometheus/common/expfmt/decode.go:89:34: cannot use v (type *io_prometheus_client.MetricFamily) as type protoreflect.ProtoMessage in argument to pbutil.ReadDelimited:
	*io_prometheus_client.MetricFamily does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
gopath/src/github.com/prometheus/common/expfmt/encode.go:120:36: cannot use v (type *io_prometheus_client.MetricFamily) as type protoreflect.ProtoMessage in argument to pbutil.WriteDelimited:
	*io_prometheus_client.MetricFamily does not implement protoreflect.ProtoMessage (missing ProtoReflect method)
gopath/src/github.com/prometheus/common/expfmt/text_create.go:46:27: undefined: io.Discard
The command '/bin/sh -c set -x &&     apt-get update &&     apt-get install -y apt-utils software-properties-common clang-format &&     add-apt-repository ppa:ubuntu-toolchain-r/test &&     apt-get update -y &&     apt-get install -y curl tar build-essential git pkg-config gdb valgrind gcc-10 libmicrohttpd-dev doxygen graphviz &&     rm -f /usr/bin/gcc &&     ln -s /usr/bin/gcc-10 /usr/bin/gcc &&     curl -sL https://github.com/Kitware/CMake/releases/download/v3.14.5/cmake-3.14.5-Linux-x86_64.tar.gz | tar xzf - -C /opt &&     cp /opt/cmake-3.14.5-Linux-x86_64/bin/* /usr/local/bin/ &&     cp -R /opt/cmake-3.14.5-Linux-x86_64/share/cmake-3.14 /usr/local/share/ &&     curl -sL https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz 2> /dev/null | tar xzf - -C /usr/local &&     mkdir -p /gopath/{src,bin} &&     printf 'export GOPATH=/gopath\nexport PATH=$PATH:/usr/local/go/bin:/gopath/bin\n' > /root/.bash_profile &&     printf '#!/usr/bin/env bash\nsource /root/.bash_profile\nexec /bin/bash $@\n' > /entrypoint &&     chmod +x /entrypoint &&     GOPATH=/gopath /usr/local/go/bin/go get github.com/prometheus/prom2json &&     GOPATH=/gopath /usr/local/go/bin/go install github.com/prometheus/prom2json/cmd/prom2json &&     GOPATH=/gopath /usr/local/go/bin/go get github.com/git-chglog/git-chglog &&     GOPATH=/gopath /usr/local/go/bin/go install github.com/git-chglog/git-chglog/cmd/git-chglog &&     rm -rf /var/lib/apt/lists/*' returned a non-zero code: 2
make[1]: *** [Makefile:2: docker] Error 2
make[1]: Leaving directory '/home/mutex/dist/src/odyssey/include/prometheus-client-c/docker'
ERROR: Docker Build Failure
make: *** [Makefile:26: clean] Error 2

I'm building from master branch, commit hash = c57034d. Myabe go version iw wrong or am I missed something?

process_cpu_seconds_total do not includes utime and stime

Current implementation of process_cpu_seconds_total gauge uses cutime + cstime so for processes without child's returns 0 Below is an output for example app metric

# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.
# TYPE process_cpu_seconds_total gauge
process_cpu_seconds_total 0.000000

Can it be calculated as utime + stime + cutime + cstime to produce a valid result?

The function "prom_map_delete" cause “core dump”

An abnormal program termination occurred when I called the "prom_map_delete" function.
I found that in the following code, the parameter was passed incorrectly.

if ((*self->compare_fn)(node->item, item) == PROM_EQUAL) {

I changed to the following code, and the problem was solved.
r = prom_linked_list_remove(list, current_node);

change "prom_map.cpp 372" to :
r = prom_linked_list_remove(list, current_node->item);

Is it possible to open new API to clear data?

After run prometheus client for a long time, the memory keep eating up.
It would be better if I could simply call a api to flush all the collected data.
Is it possible or any better solution to prevent out of memory trouble?

Broken build due to outdated go version

Hi,

Building with make led me to the error below:

gopath/src/github.com/golang-jwt/jwt/ecdsa.go:135:4: r.FillBytes undefined (type *big.Int has no field or method FillBytes)
gopath/src/github.com/golang-jwt/jwt/ecdsa.go:136:4: s.FillBytes undefined (type *big.Int has no field or method FillBytes)

This can be fixed by upgrading Go to the latest stable release (go1.16.7 at the time of writing) in docker.sh.

Thanks :)

edit: some more changes are needed after upgrading; need to add @latest after prom2json and git-chlo

GOPATH=/gopath /usr/local/go/bin/go install github.com/prometheus/prom2json/cmd/prom2json@latest && \
GOPATH=/gopath /usr/local/go/bin/go get github.com/git-chglog/git-chglog && \
GOPATH=/gopath /usr/local/go/bin/go install github.com/git-chglog/git-chglog/cmd/git-chglog@latest && \
rm -rf /var/lib/apt/lists/*

Please update your lib to make it GCC 10 compatilbe

See gcc 10 -fno-common update:

I use your lib in coturn and experience error with version gcc 10.
If I add extern before these vars works fine..
https://github.com/misi/prometheus-client-c

/usr/bin/ld: /tmp/cc8Yt5mw.o:/usr/include/prom_collector_registry.h:37: multiple definition of `PROM_COLLECTOR_REGISTRY_DEFAULT'; /tmp/ccL9shFy.o:/usr/include/prom_collector_registry.h:37: first defined here
/usr/bin/ld: /tmp/cc8Yt5mw.o:/usr/include/prom_histogram_buckets.h:44: multiple definition of `prom_histogram_default_buckets'; /tmp/ccL9shFy.o:/usr/include/prom_histogram_buckets.h:44: first defined here
/usr/bin/ld: /tmp/cc26uJhy.o:/usr/include/prom_collector_registry.h:37: multiple definition of `PROM_COLLECTOR_REGISTRY_DEFAULT'; /tmp/ccL9shFy.o:/usr/include/prom_collector_registry.h:37: first defined here
/usr/bin/ld: /tmp/cc26uJhy.o:/usr/include/prom_histogram_buckets.h:44: multiple definition of `prom_histogram_default_buckets'; /tmp/ccL9shFy.o:/usr/include/prom_histogram_buckets.h:44: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:136: bin/turnserver] Error 1

Please update your lib to work properly with gcc-10

Many thanks for your help and cooperation in advance!

Error with promhttp_start_daemon()

Dear Team,

I have built this project in my Debian (without Docker).
I cannot send information from this client.

Test with this code :

#include <prom.h>
#include <promhttp.h>
#include <prom_counter.h>
#include <sys/types.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <microhttpd.h>

static void *promtest_counter_handler(void *data);
static int promtest_parse_counter_output(const char *output, char **value);

prom_counter_t *bar_counter;
prom_gauge_t *bar_gauge;

int bar(int v, const char *label) {
  int r = 0;
  r = prom_counter_inc(bar_counter, NULL);
  if (r) return r;
  return prom_gauge_add(bar_gauge, v, (const char *[]) { label });
}

void bar_init(void) {
  bar_counter = prom_collector_registry_must_register_metric(prom_counter_new("bar_counter", "counter for bar", 0, NULL
));
  bar_gauge = prom_collector_registry_must_register_metric(prom_gauge_new("bar_gauge", "gauge for bar", 1, (const char
*[]) { "label" }));
}

int main(void) {
  // Initialize the default collector registry
  prom_collector_registry_default_init();

  bar_init();
  bar(1, "toto");
  bar(1, "tata");
  bar(1, "tata");
  bar(1, "tata");
  bar(1, "tata");

  promhttp_set_active_collector_registry(NULL);


  const char *buf = prom_collector_registry_bridge(PROM_COLLECTOR_REGISTRY_DEFAULT);
  printf("--\n%s\n", buf);
  exit(1);


  // Start the HTTP server
  struct MHD_Daemon* promtest_daemon = promhttp_start_daemon(MHD_USE_DEBUG|MHD_USE_SELECT_INTERNALLY, 8000, NULL, NULL);

  sleep(100);

  printf("\nshutting down...\n");


  prom_collector_registry_destroy(PROM_COLLECTOR_REGISTRY_DEFAULT);
  PROM_COLLECTOR_REGISTRY_DEFAULT = NULL;
  
  // Stop the HTTP server
  MHD_stop_daemon(promtest_daemon);

  return 0;
}

Here is the error in gbd:

Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
__GI___pthread_rwlock_unlock (rwlock=0x55555577e4e0) at pthread_rwlock_unlock.c:38
38	pthread_rwlock_unlock.c: No such file or directory.
(gdb) 
(gdb) 
(gdb) 
(gdb) backtrace 
#0  __GI___pthread_rwlock_unlock (rwlock=0x55555577e4e0) at pthread_rwlock_unlock.c:38
#1  0x00007ffff7bd0722 in prom_map_destroy () from /usr/local/lib/libprom.so
#2  0x00007ffff7bced95 in prom_collector_process_collect () from /usr/local/lib/libprom.so
#3  0x00007ffff7bd224d in prom_metric_formatter_load_metrics () from /usr/local/lib/libprom.so
#4  0x00007ffff7bcf3c3 in prom_collector_registry_bridge () from /usr/local/lib/libprom.so
#5  0x0000555555554ca1 in main () at test.c:52```


Is there a way not to expose process_* metrics?

As the title says, is there a way not to expose process_* metrics?

I've given a quick look at the code and prom_collector_registry_t->disable_process_metrics seems the knob I'm looking for, but it seems it's never used. Besides, it seems that collecting and exposing process metrics is enabled by default:

int prom_collector_registry_default_init(void) {
if (PROM_COLLECTOR_REGISTRY_DEFAULT != NULL) return 0;
PROM_COLLECTOR_REGISTRY_DEFAULT = prom_collector_registry_new("default");
if (PROM_COLLECTOR_REGISTRY_DEFAULT) {
return prom_collector_registry_enable_process_metrics(PROM_COLLECTOR_REGISTRY_DEFAULT);
}
return 1;
}

I guess that one could always edit and recompile the library but I was looking for something out of the box.

Crash observed during counter update

Hi,

I have a infinite loop in main thread with a sleep timer of 5 sec. It updates Prometheus counters every time. I am seeing segmentation fault when thread tries to aquire write lock in prom_counter_add () function.

Below is stack trace.

(gdb) bt
#0 0x00007f35c20f91b6 in pthread_rwlock_wrlock () from /lib64/libpthread.so.0
#1 0x00007f35c25154e8 in prom_metric_sample_from_labels () from /lib64/libprom.so
#2 0x00007f35c2513431 in prom_counter_add () from /lib64/libprom.so
#3 0x00000000004300aa in ran_update_cplane_perf_counters ()
#4 0x000000000040a761 in ran_adaptor_loop ()
#5 0x00000000004069df in main ()

Please suggest.

Illegal Exception errors under test for older flavors of Linux

pthread_rwlock_unlock had undefined behavior when called when the lock is not locked. It appears that older version of Linux will throw an Exception: Illegal error when this occurs. The solution may be to remove these calls from destructor functions.

Failing to compile client

Hi Guys,

I am failing to compile with the following error, my version of libmicrohttpd is 0.9.75.

I have tried a fresh compile of both on a clean machine and still running into the same issue, any having a similar experience?

[ 50%] Building C object CMakeFiles/promhttp.dir/src/promhttp.c.o
/home/jamieb/prometheus-client-c/promhttp/src/promhttp.c: In function ‘promhttp_start_daemon’:
/home/jamieb/prometheus-client-c/promhttp/src/promhttp.c:64:54: error: passing argument 5 of ‘MHD_start_daemon’ from incompatible pointer type [-Werror=incompatible-pointer-types]
   64 |   return MHD_start_daemon(flags, port, apc, apc_cls, &promhttp_handler, NULL, MHD_OPTION_END);
      |                                                      ^~~~~~~~~~~~~~~~~
      |                                                      |
      |                                                      int (*)(void *, struct MHD_Connection *, const char *, const char *, const char *, const char *, size_t *, void **) {aka int (*)(void *, struct MHD_Connection *, const char *, const char *, const char *, const char *, long unsigned int *, void **)}
In file included from /home/jamieb/prometheus-client-c/promhttp/src/promhttp.c:19:
/usr/local/include/microhttpd.h:2813:1: note: expected ‘MHD_AccessHandlerCallback’ {aka ‘enum MHD_Result (*)(void *, struct MHD_Connection *, const char *, const char *, const char *, const char *, long unsigned int *, void **)’} but argument is of type ‘int (*)(void *, struct MHD_Connection *, const char *, const char *, const char *, const char *, size_t *, void **)’ {aka ‘int (*)(void *, struct MHD_Connection *, const char *, const char *, const char *, const char *, long unsigned int *, void **)’}
 2813 | MHD_start_daemon (unsigned int flags,
      | ^~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [CMakeFiles/promhttp.dir/build.make:63: CMakeFiles/promhttp.dir/src/promhttp.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/promhttp.dir/all] Error 2
make: *** [Makefile:152: all] Error 2
ERROR: promhttp Make Failure

API to clear data(second request)

Previously, at this issue was a request for clearing data API. I repeat this request. Since, we are parsing the exported metrics from CoTurn, and we are doing this in an interval, there is a need to clear existing metrics to clear metrics history.

Or, is there another way?

Windows build

We want to use the library on Windows and I found that if the code below is conditionally excluded for WIN32 the library will build and work on Windows. Would it be possible to add this change or something similar to the code.

diff --git a/prom/src/prom_collector.c b/prom/src/prom_collector.c
index dce3bb4..f3bd8cf 100644
--- a/prom/src/prom_collector.c
+++ b/prom/src/prom_collector.c
@@ -15,7 +15,9 @@
  */

 #include <stdio.h>
+#ifndef WIN32
 #include <unistd.h>
+#endif

 // Public
 #include "prom_alloc.h"
@@ -119,6 +121,7 @@ int prom_collector_add_metric(prom_collector_t *self, prom_metric_t *metric) {
 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // Process Collector

+#ifndef WIN32
 prom_map_t *prom_collector_process_collect(prom_collector_t *self);

 prom_collector_t *prom_collector_process_new(const char *limits_path, const char *stat_path) {
@@ -275,3 +278,4 @@ prom_map_t *prom_collector_process_collect(prom_collector_t *self) {

   return self->metrics;
 }
+#endif
diff --git a/prom/src/prom_collector_registry.c b/prom/src/prom_collector_registry.c
index 4c2bc2d..a99573f 100644
--- a/prom/src/prom_collector_registry.c
+++ b/prom/src/prom_collector_registry.c
@@ -61,6 +61,7 @@ prom_collector_registry_t *prom_collector_registry_new(const char *name) {
   return self;
 }

+#ifndef WIN32
 int prom_collector_registry_enable_process_metrics(prom_collector_registry_t *self) {
   PROM_ASSERT(self != NULL);
   if (self == NULL) return 1;
@@ -87,14 +88,17 @@ int prom_collector_registry_enable_custom_process_metrics(prom_collector_registr
   }
   return 1;
 }
+#endif

 int prom_collector_registry_default_init(void) {
   if (PROM_COLLECTOR_REGISTRY_DEFAULT != NULL) return 0;

   PROM_COLLECTOR_REGISTRY_DEFAULT = prom_collector_registry_new("default");
+#ifndef WIN32
   if (PROM_COLLECTOR_REGISTRY_DEFAULT) {
     return prom_collector_registry_enable_process_metrics(PROM_COLLECTOR_REGISTRY_DEFAULT);
   }
+#endif
   return 1;
 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.