I remember that you explained me last week, I thought like that is related to the servers that were down. Here I want to query such that it should give the last time when the scrape was successful for both Up and Down Servers.
The subquery you mentioned above : *max_over_time((time() * up)[24h:5m]) ----->* In This query we are getting values for both up and down, but for the servers which were down I am getting the wrong time(i.e the year was 1970) and the servers which were up, the timestamp was correct. Or *max_over_time((timestamp(up == 1))[24h:5m])* ------> This query we are getting output which were up, I am not getting the value which were down Is there any other metric or method to know the timestamp of the last successful scrape for both up and down servers? Thanks & regards, Bharath Kumar. On Friday, 16 September 2022 at 16:16:03 UTC+5:30 Brian Candler wrote: > > Unfortunately, > > *timestamp(up == 1)* > > doesn't work as you might hope; it returns the current time (the instant > that the query was made for), not the time of the last successful scrape. > > I should add: this is not a bug, this is by design, and it wouldn't do > what you want anyway. > > The query "up == 1" means "show me all values of the timeseries 'up' whose > value is 1 *at the current point in time*". It will look backwards in time > to find the most recent value of the 'up' metric, and will only look back 5 > minutes by default (*query.lookback-delta*). Once it has found the most > recent value, that's the one it will use. If the most recent value of "up" > seen is 0, the filter "== 1" will eliminate it from the answer; and if no > scrape has been attempted for more than 5 minutes, it also won't appear in > the result set. > > Hence, for what you're asking, you need to look back over a defined time > range - using a subquery, as I showed. > > On Friday, 16 September 2022 at 11:26:22 UTC+1 Brian Candler wrote: > >> > Can we check whether the scrape was successful or not? >> >> *up == 1* >> >> Unfortunately, >> *timestamp(up == 1)* >> doesn't work as you might hope; it returns the current time (the instant >> that the query was made for), not the time of the last successful scrape. >> >> You can do: >> *timestamp(up) unless up == 0* >> but then you'll only get the timestamp if the server is currently up, and >> nothing if it is down. >> >> You can use a subquery, which scans the expression over a time range - >> but I already explained that to you a few weeks ago: >> https://groups.google.com/g/prometheus-users/c/1zSp7XTbChY/m/3my54aefBwAJ >> >> *max_over_time((time() * up)[24h:5m])* >> Or I think this will work too: >> >> *max_over_time((timestamp(up == 1))[24h:5m])* >> >> Both of these give an approximation. The subquery as shown evaluates the >> expression at 5 minute intervals over the last 24 hours; so the timestamp >> you get is rounded up to the next 5 minute step. >> >> On Friday, 16 September 2022 at 07:59:31 UTC+1 [email protected] >> wrote: >> >>> Yes... It will give the timestamp... It is giving the time even though >>> the specific instance is down. It should not give the timestamp if it >>> didn't scrape as the instance/server was down. >>> >>> Can we check whether the scrape was successful or not? >>> >>> The main intention is to find the timestamp because when a server goes >>> down we can know at what time the last scrape happen. >>> >>> >>> >>> On Friday, 16 September 2022 at 12:01:50 UTC+5:30 [email protected] >>> wrote: >>> >>>> timestamp(up) >>>> >>>> On Fri, Sep 16, 2022 at 7:36 AM BHARATH KUMAR <[email protected]> >>>> wrote: >>>> >>>>> Hello, >>>>> >>>>> Can we know the last time when the Prometheus scrape the metrics. Is >>>>> there any metric to find the time when the Prometheus did the scrape? >>>>> >>>>> Thanks & regards, >>>>> Bharath Kumar. >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Prometheus Users" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/prometheus-users/e28a24ea-921a-4710-9540-0f0c66556ab8n%40googlegroups.com >>>>> >>>>> <https://groups.google.com/d/msgid/prometheus-users/e28a24ea-921a-4710-9540-0f0c66556ab8n%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> >>>> -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/82a8b179-d607-4324-be1c-b135162862d6n%40googlegroups.com.

