I am new to Grafana Monitoring and not quite familiar with PromQL query. I wanted to try to retrieve a table has pod names and time created from Kubernetes cluster. How do I need to retrieve the info using PromQL?
For instance, in the table will have
Pod Name nginx-xxxxxxxx-xxxxxx and creation time HH:MM:SS or any suitable format.
You can use metric kube_pod_created which returns the time in unix timestamp. Multiply the value by 1000 and select date format.
kube_pod_created{pod="nginx-xxx"} * 1000
More you can find here https://github.com/grafana/grafana/issues/6297.
Related
I want to remove time range selector from grafana dashboard to not query for specific selected time range. I am using influxdb and I want to load all data without selecting specific time range and query with some where clausess. Is it possible?
In the dahboard setting enable Hide time picker and all InfluxDB queries write in the raw mode without time conditon ($timeFilter macro).
I have a varchar column in redshift table where the time is stored in 24 hours format, e.g, 17:00, I want to query the table and convert the format to 12 hours format showing AM or PM in time. When I test like to_char('17:00'::time,'HH12:MI AM') it works fine but when I put column name in place of hardcoded value querying the table,
SELECT to_char(prepoll_start::time,'HH12:MI AM')
FROM votecast.poll_hours AS ph
WHERE ph.prepoll_start is not null
and state = 'AL'
AND tab_elec_type = 'primary'
It won't work, gives an error
Invalid operation: Specified types or functions (one per INFO message) not supported on Redshift tables.;
Postgres version is 8.0.2
Please let me know what am doing wrong :(
First I had to create a timestamp value out of the time available. Then fetch the time in a 12 hour format.
select to_char( to_timestamp('1900-01-01 '||prepoll_start||':00' ,'YYYY/MM/DD HH:MI:SS') , 'HH12:MI AM')
from votecast.poll_hours;
Amazon Redshift does not support a TIME data type.
See: Datetime Types - Amazon Redshift
However, you are correct that it seems to support TIME for non-table related operations.
I tried playing around with string manipulation but was unable to get beyond the error you experienced. I think it is because TIME is recognized on the leader node, but fails to run on the compute nodes. (This is similar to the behaviour of time_series().)
Thus, you won't be able to use the TIME data type for anything that relies on table data.
I'm using Kubernetes with kube-state-metrics and Prometheus/grafana to graph various metrics of the Kubernetes Cluster.
Now I'd like to Graph how many new PODs have been created per Hour over Time.
The Metric kube_pod_created contains the Creation-Timestamp as Value but since there is a Value in each Time-Slot, the following Query also returns Results >0 for Time-Slots where no new PODs have been created:
count(rate(kube_pod_created[1h])) by(namespace)
Can I use the Value in some sort of criteria to only count if Value is within the "current" Time-Slot ?
PODs created in past hour
count ( (time() - sum by (pod) (kube_pod_created)) < 60*60 )
As per docs https://prometheus.io/docs/prometheus/latest/querying/functions/ rate() should be used with counters only. I suggest you use changes() function as time of creation value should change within your time frame in case of pod creation and maybe sum is better than count too.
changes()
For each input time series, changes(v range-vector) returns the number of times its value has changed within the provided time range as an instant vector.
sum(changes(kube_pod_created[1h])) by(namespace)
The following query returns the number of pods created during the last hour:
count(last_over_time(kube_pod_created[1h]) > time() - 3600)
How does it work?
The last_over_time(kube_pod_created[1h]) returns creation timestamps for pods, which were active during the last hour (see last_over_time() docs). This includes pods, which could be started long time ago and are still active alongside pods, which where created during the last hour.
We need to filter out pods, which were created more than a hour ago. This is performed by comparing pod creation timestamps to time() - 3600 (see time() docs). Such comparison removes time series for pods created more than a hour ago. See these docs for details on how doe comparison operators work in PromQL.
Then the outer count() returns the number of time series, which equals to the number of pods created during the last hour.
Is it possible in grafana with a prometheus backend to determine the highest value recorded for the lifetime of a data set, and if so, determine the time that the value occurred?
For example, I'm using site_logged_in as the query in a Singlestat panel to get the current number of logged in users, along with a nice graph of recent activity over the past hour. Wrapping that in a max() seems to do nothing, and a max_over_time(site_logged_in[1y]) gives me a far too low number.
The value is a single gauge value coming from the endpoint like so
# HELP site_logged_in Logged In Members
# TYPE site_logged_in gauge
site_logged_in 583
Is something like determining highest values even a realistic use case for prometheus?
max_over_time(site_logged_in[1y]) is the max over the past year, however this presumes that you have a year worth of data to work from.
The highest value over the specified time range can be obtained with max_over_time() function. For example, the following value would return the maximum value for site_logged_in metric over the last year:
max_over_time(site_logged_in[1y])
Unfortunately Prometheus doesn't provide the function for returning the timestamp for the maximum value. If you need to obtain the timestamp for the maximum value, then you can use tmax_over_time() function from MetricsQL. For example, the following MetricsQL query returns the timestamp in seconds for the maximum value of site_logged_in metric over the last year:
tmax_over_time(site_logged_in[1y])
Is it a requirement that you must use a time or datetime column in postgres to pull metric's on a Grafana dashboard?
I ask because I have a column just with a date only and I'm unable to show metrics base on dates only. Unless I am missing something in the documentation. Postgres in Grafana
If anyone has any helpful information, it would be greatly appreciated.
All I need is just a starting point.
I am a new user to Grafana and I'm trying to figure this out.
According to documentation:
If you set Format as to Time series, for use in Graph panel for example, then the query must return a column named time that returns either a sql datetime or any numeric datatype representing unix epoch in seconds.
So, all you need is to convert your column with date to unix epoch and name it as time. You can do it yourself or use macros provided by grafana (see docs) for convertion which are expanded into native postgres expressions. It is also helpful to look at 'Generated SQL' to see the actual query sent to database.