Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support converting epoch time to datetime #6297

Closed
potchin opened this issue Oct 17, 2016 · 36 comments
Closed

Support converting epoch time to datetime #6297

potchin opened this issue Oct 17, 2016 · 36 comments

Comments

@potchin
Copy link

potchin commented Oct 17, 2016

I have a metric which stores a datetime in epoch format. I would like to show this as a human-readable string in singlestat

@galindro
Copy link

+1

11 similar comments
@skebo
Copy link

skebo commented Nov 11, 2016

+1

@wanderingnewfie
Copy link

+1

@koallen
Copy link

koallen commented Mar 6, 2017

+1

@nagimov
Copy link

nagimov commented Mar 8, 2017

+1

@nindza
Copy link

nindza commented Mar 17, 2017

+1

@rodrigocastrillon
Copy link

+1

@fretty
Copy link

fretty commented Apr 14, 2017

+1

@aknapp112
Copy link

+1

@mikeyfreshh
Copy link

+1

@edwardslabs
Copy link

+1

@schbrongx
Copy link

+1

@liyuankui
Copy link

I think it's solved, just multiply it by 1000, and choose the type as Date

@kilteer
Copy link

kilteer commented Jul 17, 2017

Thanks @liyuankui. That's a quick & easy solution.

@ipsecguy
Copy link

Do we have a type Date?

@rohitnagpal88
Copy link

I am looking to do the exact same thing , display an epoch timestamp in human readable date in a singlestat. Can't seem to find the type Date . Is it there in any specific version ? Any help appreciated.

@rohitnagpal88
Copy link

I ended up using the prometheus query language itself to get the time in seconds and selected the stat as a duration in seconds (time() - singlestatquery)

@ipsecguy
Copy link

ipsecguy commented Sep 5, 2017

would you mind sharing the promQL snippet?

@rohitnagpal88
Copy link

rohitnagpal88 commented Sep 6, 2017

time()-(process_start_time_seconds)

time() function in prometheus is used to get the current time in epoch. So you can use it to calculate the no. of seconds since the process last started. Choose the singlestat unit as time duration in seconds .

@torkelo
Copy link
Member

torkelo commented Sep 21, 2017

implemented in #6297

add 3 new unit formats for dates

@torkelo torkelo closed this as completed Sep 21, 2017
@torkelo torkelo added this to the 4.6/5.0 milestone Sep 21, 2017
@bergquist bergquist modified the milestones: 4.6/5.0, 4.6 Oct 12, 2017
@karlsoon
Copy link

Hi!
How to use this?
I have this timestamp from metric: 1540655070
grafana-unixtime

@rafawhs
Copy link

rafawhs commented Apr 20, 2018

@karlsoon use scale function to multiply it by 1000

screen shot 2018-04-20 at 14 36 52

@caiges
Copy link

caiges commented May 16, 2018

... and how might you do this for table data?

@ResolveWang
Copy link

@rafawhs Hi,rafawhs, what's the data source? I use prometheus and i can't find the scale function ?

@rafawhs
Copy link

rafawhs commented Jun 18, 2018

@ResolveWang Graphite!

@Rekhs123
Copy link

I am also not able to view scale function. im using prometheus as data source. Please help

@enzobes
Copy link

enzobes commented Jul 6, 2018

@ResolveWang @Rekhs123
If you use Prometheus, Grafana wants metrics in Milliseconds.
For example : process_start_time_seconds * 1000
Then you can put your metrics in Date Format.

@cvernooy23
Copy link

anyway to convert epoch to human datetime in a table graph with a postgresql datasource?

@marefr
Copy link
Member

marefr commented Jul 27, 2018

@cvernooy23 use the column style date and select date format

@mjtrangoni
Copy link
Contributor

mjtrangoni commented Aug 31, 2018

@marefr How do you convert epoch to milliseconds inside a Prometheus Table? This is why I can`t use the date format.

@marefr
Copy link
Member

marefr commented Sep 3, 2018

@mjtrangoni see comment above. If not applicable please share your query you're using.

@mjtrangoni
Copy link
Contributor

@marefr Yes, sorry, I was wrong and thought it was a column from a metric label, but it turn out this is indeed the value.
JIC, what if it would have been a label and not the value itself?

@marefr
Copy link
Member

marefr commented Sep 3, 2018

@mjtrangoni Given you have a label with epoch timestamp in millisecond format I think it should work to use column style date. If you need to do conversion your limited to solve that using prometheus query api. For the singlestat panel the support is broader, see demo.

@vivekj11
Copy link

Hi, I want to show uptime of my container on grafana, for that I have used something like
(( container_start_time*1000 )) and it is working absolutely fine. My problem is, as soon as this container is down, grafana is showing 63 years/122 years for this metrics.
I am using prometheus, cadvisor and grafana.
Any Help..!!

@CH-MN
Copy link

CH-MN commented Jul 22, 2020

Putting Date and Time on a dashboard seems pretty fundamental. How do I do that? I used a singlestat to get Time of last point, of some arbitrary metric, which returns it in some non human readable format. I select YYYY-MM-DD HH:mm:ss for Unit, which converts it to just time. I assume it is because it is so recent? Why would Grafana make that kind of decision. If I wanted just time, there should be a HH:mm:ss selection! This thread goes back and forth I never see a definitive answer yet it is closed.

Using 6.4.1.

@harvey945
Copy link

harvey945 commented Sep 20, 2022

Hi .i solved this problem.

HUAWEI-ENTITY-EXTENT-MIB::hwEntityManufacturedDate.67108873 = STRING: 2018-11-19,0:0:0.0

HELP hwEntityManufacturedDate This object indicates the manufacturing date of an entity.

image

The verification obtained by snmp is not accurate, let's correct it.


[root@TDengine generator]# date -d@1542585600 +"%Y-%m-%d %H:%M:%S"
2018-11-19 08:00:00
CST + 8:00:00 (28800s)
max((hwEntityManufacturedDate{instance="x.x.x.x"}) - 28800 ) * 1000

image

Thanks.

zhengyi13 added a commit to zhengyi13/cert-exporter that referenced this issue Jul 7, 2023
In the process, I've learned that:

1) I need to know my config at Collector creation time; I can't create
a stub Collector and have it read the config - That way leads to
panics that I don't understand /shrug

2) Prometheus will take the timestamp (a simple in), *force* me to
cast it to a float64, and then display it in scientific notation

3) Grafana can and will handle this stupidity, but not before adding
its own: it assumes timestamps are in milliseconds, so I have to take
my field/value, multiply it by 1000, and then select a Date type, per
a whole bunch of threads where people want to do exactly that,
e.g. grafana/grafana#6297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests