Is it possible to use prometheus in such a scenario

36 views
Skip to first unread message

Robert Flocks

unread,
Feb 22, 2022, 2:56:58 PM2/22/22
to Prometheus Users
Good afternoon, 
is it possible to use prometheus for such a scenario:
One database, one request but with different parameters?
Example:
select value from perfmon where hostname = 'some hostname'
There are many such hostnames, I would like to have one configuration file for all hosts. Is it possible?
Hostnames are specified in grafana variables.

Brian Candler

unread,
Feb 23, 2022, 1:19:33 AM2/23/22
to Prometheus Users
Prometheus is not a SQL database: it's a time series database and has its own query language, PromQL.

Each timeseries is uniquely identified by a metric name (which describes the type of thing you're measuring) and a set of labels (which taken together identify one particular instance of that thing).  A common label is "instance" which normally identifies the host the metric came from. Here are a few simple PromQL queries:

node_filesystem_avail_bytes

node_filesystem_avail_bytes{instance="server1"}

node_filesystem_avail_bytes{instance="server1",mountpoint="/"}

The first query returns a vector with available space on all filesystems.
The second query returns a vector with available space on all filesystems on one particular host (which still may be multiple results)
The third instance constrains the query more specifically to a single filesystem.

There is lots of documentation online, both official and various blogs, which can tell you more.

Robert Flocks

unread,
Feb 23, 2022, 1:57:54 AM2/23/22
to Prometheus Users
Thanks for the answer, I meant that I already have a SQL database with the required data. And now, when using some kind of sql exporter, is it possible to configure the config for each metric once, but so that when querying with a different hostname, the sql query changes?

Maybe it looks like this:
query:  select value from perfmon where hostname = %variable% 

Maybe I do not understand how this should work, I just started looking for a solution

среда, 23 февраля 2022 г. в 09:19:33 UTC+3, Brian Candler:

Brian Candler

unread,
Feb 23, 2022, 4:43:31 AM2/23/22
to Prometheus Users
What do you mean by "querying with a different hostname"?

Some Prometheus exporters accept URL query parameters to control what they do, e.g.
http://localhost:9115/probe?module=http&target=foo
That's a perfectly valid thing to do.  The prometheus server can specify these query parameters using "params" setting in the scrape job, or __param_XXX labels.

Hence if you're going to write your own exporter that performs SQL queries, it's perfectly fine to adjust the SQL query using values from the query parameters.

What you *don't* want to do is to return different data depending on which host is making the query (i.e. where the scrape is coming from)
Reply all
Reply to author
Forward
0 new messages