Jelastic API 间歇性会话身份验证错误 "not authenticated (different session key)"

Jelastic API intermittent session authentication error "not authenticated (different session key)"

我创建了以下脚本来从 Jelastic api 中提取统计信息,这样我就可以在一段时间内收集资源统计信息。最终目标是将数据记录到电子表格中。

下面是我的代码,它处理身份验证然后向 GetSumStats 发出请求。

如果我 运行 代码,有时返回的结果是预期的。

{ 
  iops_used: 0,
  duration: 3600,
  cpumhz: 7,
  start: '',
  disk: 7857,
  mem: 725212,
  cpu: 24002,
  capacity: 9,
  net: { in_int: 96004, out_int: 96004, in_ext: 9181, out_ext: 9395 },
  chanksused: 7,
  nodeid: 'sum' 
}

但其他时候请求会因错误而失败。

{ result: 702,
  source: 'JEL',
  error: 'not authenticated (different session key)',
  stats: [] }

这是时间问题还是已知问题?也许脚本太快了 API 还不知道会话 ID?这就是我引入 setTimeout

的原因
var sites               = require('./sites.json').sites,
    credentials         = require('./credentials.json'),
    Client              = require('node-rest-client').Client,
    util                = require('./util.js');

(function () { 
    "use strict";

    var client = new Client();
    var session;

    login();

    function login() {
        var args = {
            parameters: { 
                appid: sites[2].appId, 
                login: credentials.email,
                password: credentials.password
            }
        };

        client.registerMethod("login", "https://app.j.hostapi.co.uk/1.0/users/authentication/rest/signin", "GET");

        client.methods.login(args, function (data, response) {

            // parsed response body as js object
            data = util.parseResponse(data);

            session = data.session;
            console.log(session);

            // Tried to pause here in case it was too quick
            setTimeout(function() {
                getSumStats();
            }, 3000);


        });
    }

    function logout() {
        var args = {
            parameters: { 
                appid: sites[2].appId, 
                session: session
            }
        };

        client.registerMethod("logout", "https://app.j.hostapi.co.uk/1.0/users/authentication/rest/signout", "GET");

        client.methods.logout(args, function (data, response) {

            // parsed response body as js object
            data = util.parseResponse(data);

            console.log(data);
            // raw response
            //console.log(response);
        });
    }

    // Failure here
    function getSumStats() {
        var args = {
            parameters: { 
                domain: sites[2].domain, 
                session: session,
                duration: 3600
            }
        };

        client.registerMethod("getSumStats", "https://app.j.hostapi.co.uk/1.0/environment/control/rest/getsumstat", "GET");

        client.methods.getSumStats(args, function (data, response) {

            // parsed response body as js object
            data = util.parseResponse(data);
            console.log(data.stats);
            logout();
        });
    }



})();

您只能同时登录 1 个会话。登录由 IP / 用户代理固定。

如果您需要创建多个并发登录会话,您可以尝试为每个会话使用唯一的 UA 以避免冲突。