From ab15c9e32011f712d3d6c82949f7dff2818becca Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 8 Apr 2016 13:31:23 +0100 Subject: [PATCH] added example server load tcp server --- services/clsi/app.coffee | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/services/clsi/app.coffee b/services/clsi/app.coffee index c7bbd8cf64..bdc801b2d3 100644 --- a/services/clsi/app.coffee +++ b/services/clsi/app.coffee @@ -122,3 +122,26 @@ app.listen port = (Settings.internal?.clsi?.port or 3013), host = (Settings.inte setInterval () -> ProjectPersistenceManager.clearExpiredProjects() , tenMinutes = 10 * 60 * 1000 + + + +net = require('net') +os = require('os') + +fiveMinLoad = os.loadavg()[1] +availableWorkingCpus = os.cpus().length - 1 +freeLoad = availableWorkingCpus - fiveMinLoad +freeLoadPercentage = Math.round((freeLoad / availableWorkingCpus) * 100) + +server = net.createServer (socket) -> + socket.write "#{freeLoadPercentage}%\n", "ASCII" + socket.pipe socket + return + +port = 4080 + +server.listen port, -> + console.log "listening on port #{port}" + # netcat 127.0.0.1 4080 + +