Table of Contents
Prometheus is a platform for real-time systems and event monitoring and alerting. The Prometheus project is free, open-source, and available on GitHub. Originally developed at SoundCloud, Prometheus became a project of the Cloud Native Computing Foundation in 2016, alongside other popular frameworks such as Kubernetes. The core of the project is the Prometheus server, which acts as the system’s “brain” by collecting various metrics and storing them in a time-series database.
But once the data is inside the Prometheus database, how can you query this data efficiently to get answers to important business questions? That's where Prometheus functions come in. Below, we'll discuss what Prometheus functions are and the various use cases of Prometheus functions.
If you're interested in trying it out for yourself, sign up for our Hosted Prometheus free trial. You can also sign up for a demo and we can talk about the best Prometheus monitoring solutions for you.
What are Prometheus Functions?
Before we discuss Prometheus functions too deeply, we first need to discuss some basic concepts and terminology.
PromQL is a custom query language for the Prometheus project that is used to filter and search through Prometheus' time series data. When querying in PromQL, every metric has four components:
- The metric name
- Labels, i.e. key-value pairs to distinguish metrics with the same name
- The metric value, a 64-bit floating point number
- A timestamp with millisecond-level precision
The Prometheus expression language has three different data types:
- A scalar, which represents a floating point value.
- An instant vector, which is a set of time series data with a single scalar for each time series.
- A range vector, which is a set of time series data with a range of data points over time for each time series.
In addition, there are four different metric types in the Prometheus client libraries:
- Counter: Useful for increasing values; the counter resets to zero on restart.
- Gauge: Useful for counts that go up and down, or for rising and falling values.
- Histogram: Useful for sampling observations (such as response sizes), counting them in buckets for configuration and providing a sum of the observed values.
- Summary: Similar to a histogram, this metric type records a total count of observations and a sum of observed values. It processes the information while computing configurable quantities for a sliding window of time.
A Prometheus query using the PromQL query language can return either an instant vector or a range vector, depending on the metric type and the result you are asking for. Now that we've got all that out of the way, let's return to the original question: what are Prometheus functions?
Simply put, Prometheus functions are functions in the PromQL language that can be used to query a Prometheus database. In the next section, we'll go over a few of the most common use cases of Prometheus functions.
If you're interested in using Prometheus, but the setup and management of it would be too resource-consuming, book a demo and talk to us about how Hosted Prometheus can fit into your monitoring environment. You can also get right onto a free trial, and check it out now.
What are the Use Cases of Prometheus Functions?
There are as many Prometheus function use cases as there are functions—and even more. Below, we'll demonstrate just a few uses of Prometheus functions.
Aggregation operators calculate mathematical values over a time range. You can use Prometheus functions such as the ones below to aggregate over a given range vector:
- avg_over_time() for the average (mean) value
- max_over_time() for the maximum value
- count_over_time() for the total count of all values
Counting HTTP requests
As another example, you can use the increase() Prometheus function to count the number of HTTP requests over the past 5 minutes, e.g.:
Given a range vector and a scalar t, the predict_linear() Prometheus function uses simple linear regression to predict the value of the time series t seconds in the future.
The label_replace() Prometheus function searches through time series to find one that matches the given regex (regular expression), and then
Given a histogram, the histogram_quantile() Prometheus function. The highest bucket in the histogram must have an upper bound of +Inf (positive infinity).
Given a range vector, the delta() Prometheus function calculates the difference between two quantities. For example, to calculate the difference in CPU temperature between now and 2 hours ago:
To enhance your use of Prometheus functions, you can also integrate Prometheus with Grafana, a web application for data analytics and visualization. MetricFire's hosted Grafana service makes it easy for any Prometheus user to enjoy high-quality, informative data visualizations.
How MetricFire Can Help
MetricFire is a cloud infrastructure and application monitoring platform that makes it simple to understand your data at a glance. We offer a hosted Prometheus service that handles issues such as scaling, data storage, and support and maintenance—so that you can spend more time on the metrics and less time on the technical details.
To learn more, check out the Prometheus posts on our blog, or book a demo for a chat about your business needs and objectives. Want to get started with Prometheus right away? The MetricFire free trial is an excellent way to explore what you can do with hosted Prometheus, including using Prometheus functions.