专栏首页Jerry的SAP技术分享如何打印CloudFoundry上应用运行时的环境变量

如何打印CloudFoundry上应用运行时的环境变量

如果是运行在SAP云平台CloudFoundry环境下的应用,可以直接在云平台操作台的Environment Variables里查看环境变量:

{
	"VCAP_SERVICES": {
		"redis": [
			{
				"label": "redis",
				"provider": null,
				"plan": "v3.0-dev",
				"name": "jerryredis",
				"tags": [
					"redis",
					"keyvalue"
				],
				"instance_name": "jerryredis",
				"binding_name": null,
				"credentials": {
					"hostname": "10.0.241.43",
					"ports": {
						"6379/tcp": "51431"
					},
					"port": "50432",
					"password": "IFGX3bKPRt7Mu4Lk",
					"end_points": [
						{
							"network_id": "SF",
							"host": "10.11.241.43",
							"port": "50431"
						}
					]
				},
				"syslog_drain_url": null,
				"volume_mounts": []
			}
		]
	}
}
{
	"VCAP_APPLICATION": {
		"cf_api": "https://api.cf.eu10.hana.ondemand.com",
		"limits": {
			"fds": 16384,
			"mem": 56,
			"disk": 1024
		},
		"application_name": "jerry demo server",
		"application_uris": [
			"jerry-demo-server.cfapps.eu10.hana.ondemand.com"
		],
		"name": "jerry demo server",
		"space_name": "dev",
		"space_id": "3c737cf5-81eb-4da4-852c-d08739c74def",
		"uris": [
			"jerry-demo-server.cfapps.eu10.hana.ondemand.com"
		],
		"users": null,
		"application_id": "cfa18882-e702-4f9b-a773-ce6e6de385fd",
		"version": "374967a5-b7b9-4c59-802a-4c5f737ad95f",
		"application_version": "374967a5-b7b9-4c59-802a-4c5f737ad95f"
	}
}

或者是使用下面这段代码,直接把部署到CloudFoundry上应用的process.env环境变量打印出来:

var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);

server.listen(8080);

function print_env(){
  console.log(process.env);
}

app.get('/', function (req, res) {

  print_env();
  // res.sendFile(__dirname + '/index.html');
  var response = JSON.stringify(process.env);
  res.send(response);
});

io.on('connection', function (socket) {
  console.log("connect comming from client: " + socket.id);
  socket.emit('messages_jerry', { hello: 'world greeting from Server!' });
  socket.on('messages', function (data) {
    console.log("data received from Client:" + JSON.stringify(data,2,2));
  });
});

同样能达到效果: Tree Chart JSON Input

{
"CF_INSTANCE_ADDR": "10.0.75.23:61004",
"LANG": "en_US.UTF-8",
"OLDPWD": "/home/vcap",
"NODE_PATH": "/home/vcap/app/node_modules",
"CF_INSTANCE_PORT": "61004",
"NODE_HOME": "/home/vcap/deps/0/node",
"VCAP_APPLICATION": "{"application_id":"cfa18882-e702-4f9b-a773-ce6e6de385fd","application_name":"jerry demo server","application_uris":["jerry-demo-server.cfapps.eu10.hana.ondemand.com"],"application_version":"6dc4f14f-f01e-4af0-a1b9-aa4b5ff94b72","cf_api":"https://api.cf.eu10.hana.ondemand.com","host":"0.0.0.0","instance_id":"0cfa6559-cf9a-4ce1-4897-1f70","instance_index":0,"limits":{"disk":1024,"fds":16384,"mem":56},"name":"jerry demo server","port":8080,"space_id":"3c737cf5-81eb-4da4-852c-d08739c74def","space_name":"dev","uris":["jerry-demo-server.cfapps.eu10.hana.ondemand.com"],"version":"6dc4f14f-f01e-4af0-a1b9-aa4b5ff94b72"}",
"NODE_ENV": "production",
"MEMORY_LIMIT": "56m",
"WEB_MEMORY": "512",
"USER": "vcap",
"CF_INSTANCE_INTERNAL_IP": "10.159.133.212",
"VCAP_APP_PORT": "8080",
"PWD": "/home/vcap/app",
"HOME": "/home/vcap/app",
"CF_INSTANCE_KEY": "/etc/cf-instance-credentials/instance.key",
"PORT": "8080",
"TMPDIR": "/home/vcap/tmp",
"MEMORY_AVAILABLE": "56",
"DEPS_DIR": "/home/vcap/deps",
"CF_INSTANCE_GUID": "0cfa6559-cf9a-4ce1-4897-1f70",
"CF_INSTANCE_PORTS": "[{"external":61004,"internal":8080}]",
"CF_SYSTEM_CERT_PATH": "/etc/cf-system-certificates",
"CF_INSTANCE_IP": "10.0.75.23",
"INSTANCE_INDEX": "0",
"WEB_CONCURRENCY": "1",
"CF_INSTANCE_INDEX": "0",
"SHLVL": "1",
"INSTANCE_GUID": "0cfa6559-cf9a-4ce1-4897-1f70",
"VCAP_SERVICES": "{"redis":[{
  "label": "redis",
  "provider": null,
  "plan": "v3.0-dev",
  "name": "jerryredis",
  "tags": [
    "redis",
    "keyvalue"
  ],
  "instance_name": "jerryredis",
  "binding_name": null,
  "credentials": {
    "hostname": "10.11.241.43",
    "ports": {
      "6379/tcp": "50431"
    },
    "port": "50431",
    "password": "IF5X3bKPRt7Mu4Lk",
    "end_points": [
      {
        "network_id": "SF",
        "host": "10.11.241.43",
        "port": "50431"
      }
    ]
  },
  "syslog_drain_url": null,
  "volume_mounts": [

  ]
}]}",
"CREDHUB_API": "https://credhub.service.cf.internal",
"VCAP_APP_HOST": "0.0.0.0",
"PATH": "/home/vcap/deps/0/bin:/usr/local/bin:/usr/bin:/bin:/home/vcap/app/bin:/home/vcap/app/node_modules/.bin",
"CF_INSTANCE_CERT": "/etc/cf-instance-credentials/instance.crt",
"_": "/home/vcap/deps/0/bin/node"
}

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • SAP Spartacus core模块的单元测试

    Jerry Wang
  • rxjs里delay operators的用法

    delayed Observable emit value的时间戳总是比normal Observable晚一秒钟。

    Jerry Wang
  • Spring JDBC 框架一个最简单的Hello World级别的例子

    https://blog.csdn.net/i042416/article/details/107600796

    Jerry Wang
  • Node中间件multer文件上传实践

    单文件上传,接收一个以fieldname命名的文件,文件信息保存在req.file

    RtyXmd
  • Mybatis逆向工程构建项目实例.

    一枝花算不算浪漫
  • Mybatis逆向工程构建项目实例

    mybaits需要程序员自己编写sql语句,mybatis官方提供逆向工程 可以针对单表自动生成mybatis执行所需要的代码(mapper.java,mapp...

    Java学习
  • Spring使用注解配置依赖注入

    大部分情况下,使用Spring配置依赖注入时,都是使用注解来进行配置,因为注解比xml要方便和简单。不过类似于数据源对象这种配置信息容易变更的对象除外,这种对象...

    端碗吹水
  • laravel框架学习记录之表单操作详解

    本文实例讲述了laravel框架学习记录之表单操作。分享给大家供大家参考,具体如下:

    砸漏
  • Laravel基础

    Tips: 业务逻辑不应该写在路由当中,路由只是接收参数后转发给控制器(Controller)进行处理

    唐成勇
  • Spring JDBC 框架一个最简单的Hello World级别的例子

    https://blog.csdn.net/i042416/article/details/107600796

    Jerry Wang

扫码关注云+社区

领取腾讯云代金券