你可以通过编程访问当前的Heroku dyno id / name吗? [英] Can you programmatically access current Heroku dyno id/name?

查看:129
本文介绍了你可以通过编程访问当前的Heroku dyno id / name吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Heroku上,你可以编程方式从应用程序中获取目前正在执行代码的dyno的某种标识符吗?例如dyno名称(如web.1或worker.1)或其他一些id。

如果是,如何在Java中执行此操作?

解决方案

总是有机器的主机名(它看起来像 d.LONG_GUID 。我想(尽管还没有尝试过),这应该工作:
$ b $ p $ String $ localhostname = java.net.InetAddress.getLocalHost ().getHostName();



另外,有一点已知的秘密,但你可以得到web.1,web。 2id通过查看环境变量的值 PS1



String hostId = System.getenv(PS1)



编辑 2013年7月26日

b

根据 Heroku更改日志,本地环境变量 DYNO 现在取代 PS ,它取代 PS1


On Heroku, can you programmatically, from within an app, get some kind of identifier for the dyno currently executing your code? For example the dyno name (e.g. "web.1" or "worker.1"), or some other id.

If yes, how to do this in Java?

解决方案

There is always the hostname of the machine (which looks something like d.LONG_GUID. I suppose (though haven't tried) that this should work:

String localhostname = java.net.InetAddress.getLocalHost().getHostName();

Also, a little known secret, but you can get the "web.1", "web.2" id's by looking at the value of the environment variable PS1

String hostId = System.getenv("PS1")

EDIT 2013-July-26

As per Heroku changelog, the local environment variable DYNO now replaces PS, which replaced PS1.

这篇关于你可以通过编程访问当前的Heroku dyno id / name吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆