Prometheus module for monolith.
This wraps the native prometheus-cpp client and exposes it to Python as a native module (PYD).
This library supports the Counter, Gauge, Histogram, and Summary metric types. See the prometheus docs for a detailed explanation of each type.
See .\test\test.py for detailed examples
import prometheus_module
# Create a metric registry. All metrics belong to a registry.
registry = prometheus_module.MetricRegistry()
# Serve the metrics on the specified port so Prometheus can pull them
registry.Serve('8080')
# At this point, localhost:8080 is live, but without any metric data.
# Create a Counter metric. name is required. labels are optional.
counter = registry.MakeCounter('MyCounter', labels=['my_label', 'another_label'])
# At this point, MyCounter should be visible on localhost:8080 with value 0
# Increment the counter
counter.Increment() # value is 1
counter.Increment() # value is 2
counter.Increment(10) # value is 12
# At this point, MyCounter should be visible on localhost:8080 with value 12Counters are for values that can only increase. Generally, they are used to record the number of times a given event happens like an error count or number of times a function is called.
# Name is required.
# labels are optional.
counter = registry.MakeCounter('MyCounter', labels=['my_label', 'another_label'])
# Increments by one by default
counter.Increment()
# Optionally, can increment by any positive non-zero value
counter.Increment(10)
# Does not support 'incrementing' by zero. This will increment by one instead as it is the same as calling Increment() without a value.
#invalid: counter.Increment(0)
# Does not support negative values. This will have no effect.
#invalid: counter.Increment(-1)Gauges are for values that can increase, decrease, or be set to an arbitrary value. Generally, they are used to record observations of a variable like queue size, memory utilization, or number of processes.
# Name is required
# labels are optional
gauge = registry.MakeGauge('MyGauge', labels=['my_label', 'another_label'])
# Can increment like a Counter
gauge.Increment() # Increments by one by default
gauge.Increment(10) # Can increment by an arbitrary value
#invalid: gauge.Increment(0) # This will increment by one instead as it is the same as calling Increment() without a value.
#invalid: gauge.Increment(-1) # Cannot increment by negative values. Use Decrement instead.
# Can decrement
gauge.Decrement() # Decrements by one by default
gauge.Decrement(10) # Can decrement by an arbitrary value
#invalid: gauge.Decrement(0) # This will decrement by one instead as it is the same as calling Decrement() without a value.
#invalid: gauge.Decrement(-1) # Cannot decrement by negative values. Use Increment instead.
# Can be set to an arbitrary value
gauge.Set(999)Histograms are used to record samples of a value and count them in buckets. Generally, these are used to record things like request sizes or durations. The bucket sizes are configurable.
# Name is required
# labels are optional
# boundaries specify the buckets. A bucket represents all values less than or equal to its boundary
histogram = registry.MakeHistogram('MyHistogram', labels=['my_label'], boundaries=[10,100,1000])
# Observe() records a sample, incrementing all buckets greater than or equal to the sample value.
# Given the boundaries [10,100,1000],
histogram.Observe(1) # Increments all buckets
histogram.Observe(11) # Increments the second and third buckets
histogram.Observe(101) # Increments the third bucket
histogram.Observe(1001) # Increments the (automatically-provided) infinity bucketSee the prometheus docs for a proper explanation of summaries.
Summaries are similar to Histograms, but they sort samples into φ-quantiles (basically percentiles) rather than buckets, and are used to represent a sliding window of time (as opposed to histograms which store their samples permanently). Generally, these are used for the same types of data as histograms (request sizes and durations), but provide a different view due to their sliding window property, and are calculated on the client side (whereas histograms can be used to calculate quantiles on the server side).
# Name is required
# labels are optional
# quantiles specify the percentile and error values of the quantile "buckets". The following example will calculate the 10th, 50th, and 90th percentile observations (first parameter of each tuple) with a 5% error tolerance (second parameter of each tuple).
# The sliding window size is currently fixed at 5 minutes.
summary = registry.MakeSummary('MySummary', labels=['my_label'], quantiles=[(0.1, 0.05), (0.5, 0.05), (0.9, 0.05)])
# Observe() records a sample value at the current time.
summary.Observe(1)See the prometheus docs for a proper explanation of labels.
Labels allow you to group related metrics that differ along one or more dimensions. Rather than programmatically generating metric names, you can instead use labels to differentiate them. A common example is for http response codes. Rather than making an http_response_200_total metric and an http_response_404 metric, you would instead make a single http_response_total metric with response_code as a label to differentiate the 200 and 404 response measurements. Each distinct set of label values represents a standalone time-series.
http_response_total = registry.MakeCounter('http_response_total', labels=['response_code'])
# Record a 200 result
http_response_total.WithLabelValues({'response_code':'200'}).Increment()
# Record a 404 result
http_response_total.WithLabelValues({'response_code':'404'}).Increment()
# For better performance, you can save a reference to the metric for a given set of labels
http_response_total_200 = http_response_total.WithLabelValues({'response_code':'200'})
http_response_total_200.Increment()
# Metrics are stored and can be looked up at will. If given the same label values, WithLabelValues() will return the
# same metric object
assert(http_response_total_200 is http_response_total.WithLabelValues({'response_code':'200'}))
# Which allows you to refer to the metric either way. If http_response_total_200 has a value of zero, then:
http_response_total_200.Increment()
http_response_total.WithLabelValues({'response_code':'200'}).Increment()
# Will result in http_response_total_200 having a value of 2
# If the metric returned by MakeCounter() is used directly, it uses empty strings for its label values
assert(http_response_total is http_response_total.WithLabelValues({'response_code':''}))Configuration is managed via cmake presets. For a list of available presets run:
cmake --list-presetsTo configure your project, run the following from the project root:
cmake --preset [preset_name] -S .To build your configured project, run:
cmake build [BUILD_DIRECTORY]To install your project, run:
cmake install [BUILD_DIRECTORY]When installing into the monolith, ensure the INSTALL_TO_MONOLITH option is set to ON. This installs a package which
is compliant with the package layout expected from the monolith.
© 2026 CCP Games
This software is provided by CCP Games and does not include or distribute any third-party libraries or frameworks.
This software is a Native Prometheus client for the monolith .
Trademark Notice: CCP Games is a trademark of CCP ehf.
This project is licensed under the MIT License. Nothing in the MIT License grants any rights to CCP Games' trademarks or game content.