Reputation: 55
Let's say I have a program running in my local machine, and I would like it to listen to HTTP requests, which triggers the program to run and respond back with the output of the program. For example, I have rrdtool (command line utility for accessing round robin database) installed in my Linux box, and I want web clients to request the web server to run the rrdtool program and respond back with the output of rrdtool.
Quesitons:
I know programming languages are used to generate dynamic html contents to be sent back to clients, but rrdtool is an already existing program that just needs to be triggered by a web request. In fact, rrdtool provides various programming language bindings such as python, but I would like to use Node.js on the server side and javascript binding to rrdtool isn't supported. So how is the interface between my javascript code and the rrdtool program (CLI) done?
I thought about using a Java implementation of rrdtool functionalities such as rrd4j, but portability isn't really a priority for me and I would like to run the official rrdtool program (written in C) for a better performance. However, I'm not sure if the cost of the interface between javascript on the server side and rrdtool would outweigh the performance benefits of running the C program.
Any help/feedback/pointers would be appreciated.
Upvotes: 0
Views: 1912
Reputation: 4072
If you are using RRDTool to generate graph images, then you should be able to call rrdtool via your NodeJS handler, having it write to a temporary file in a web accessible directory. Then, send back the URL of the newly created image file, which your web frontend can use to create a new IMG tag for display.
Upvotes: 0
Reputation: 13171
Just use NodeJS's "child_process" module to run your rrdtool. Then capture its output with child.stdin.on('data', function (data) {...
, etc. Grab its output, format it into HTML, and send it as a reply to the web request that initiated it.
Upvotes: 0