how to get precise scape timestamp

36 views
Skip to first unread message

林浩

unread,
Jun 9, 2020, 11:15:38 AM6/9/20
to Prometheus Users
when I use range query api to get data point, for example I using step 30s

API return me data like these

 "values": [
                    [
                        1591607520,
                        "2270"
                    ],
                    [
                        1591607550,
                        "2270"
                    ],
                    [
                        1591607580,
                        "2270"
                    ],

for the UNIX timestamp, is that really reflex to scrap time?
since I see some scrape setting

global:
  scrape_interval: 2m
  scrape_timeout: 2m
  evaluation_interval: 1m

because Prometheus using pull to get metric,  so is there any way I can get precise scape UNIX timestamp from API ?

Brian Brazil

unread,
Jun 9, 2020, 11:16:49 AM6/9/20
to 林浩, Prometheus Users
You can use the timestamp() function, or use a query with a range vector to get the raw samples. 

--

林浩

unread,
Jun 9, 2020, 10:38:13 PM6/9/20
to Prometheus Users
Brian,

How can I get raw samples with exactly scraping time from Prometheus by the range query?

I use this call to query data , and use parameter step=30, 

api result below show that timestamp 1591607520, 1591607550, 1591607580  are not the scape time I guess..

 "values": [
                    [
                        1591607520,
                        "2270"
                    ],
                    [
                        1591607550,
                        "2270"
                    ],
                    [
                        1591607580,
                        "2270"
                    ],



在 2020年6月9日星期二 UTC+8下午11:16:49,Brian Brazil写道:

Brian Candler

unread,
Jun 10, 2020, 3:04:15 AM6/10/20
to Prometheus Users
As Brian said, use a range vector query rather than an instant query.

# curl -Ssg 'localhost:9090/api/v1/query?query=up{instance="sw1"}[5m]' | python3 -mjson.tool
{
    "status": "success",
...
                    [
                        1591772319.53,
                        "1"
                    ],
                    [
                        1591772334.53,
                        "1"
                    ],
                    [
                        1591772349.531,
                        "1"
                    ],
                    [
                        1591772364.53,
                        "1"
                    ],
...

林浩

unread,
Jun 10, 2020, 6:38:29 AM6/10/20
to Prometheus Users
Thank Brian Candler & Brian Braizil !!

The last question, is there  the way I can transform UNIX timestamp to human readable time string in the below API you give?

curl -Ssg 'localhost:9090/api/v1/query?query=up{instance="sw1"}[5m]' 

在 2020年6月10日星期三 UTC+8下午3:04:15,Brian Candler写道:

Brian Candler

unread,
Jun 10, 2020, 8:34:36 AM6/10/20
to Prometheus Users
Not in prometheus - because it's an API.  The consumer of the API is responsible for rendering the time in human-readable form.

However, you can always write a little Python script or whatever that replaces each time value with a string.

林浩

unread,
Jun 11, 2020, 3:43:30 AM6/11/20
to Prometheus Users
I see. many thanks Brain!

在 2020年6月10日星期三 UTC+8下午8:34:36,Brian Candler写道:
Reply all
Reply to author
Forward
0 new messages