view mock-api/endpoints/jvm-cpu.endpoint.js @ 219:baa2100c95bb

Add jvm-cpu as a mock endpoint Reviewed-by: aazores Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/025133.html
author Christopher Koehler <chkoehle@redhat.com>
date Wed, 20 Sep 2017 13:29:27 -0400
parents
children
line wrap: on
line source

function jvmCpu (server) {
  var _ = require('lodash');
  server.init('jvmCpu');

  server.app.get('/jvm-cpu/0.0.1/jvms/:jvmId', function (req, res) {
    server.logRequest('jvm-cpu', req);
    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify(
      {
        response: [
          {
            agentId: 'foo-agentId',
            jvmId: req.params.jvmId,
            timeStamp: { $numberLong: Date.now().toString() },
            programTicks: { $numberLong: _.floor(Math.random() * 1000000).toString() },
            cpuLoad: Math.random()
          }
        ]
      }
    ));
  });

  server.app.get('/jvm-cpu/0.0.1/systems/:systemId/jvms/:jvmId', function (req, res) {
    server.logRequest('jvm-cpu', req);

    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify(
      {
        response: [
          {
            agentId: 'foo-agentId',
            systemId: req.params.systemId,
            jvmId: req.params.jvmId,
            timeStamp: { $numberLong: Date.now().toString() },
            programTicks: { $numberLong: _.floor((Math.random() * 10000000)).toString() },
            cpuLoad: Math.random()
          }
        ]
      }
    ));
  });
}

module.exports = jvmCpu;