views:

114

answers:

5

The user, administrators and support staff need detailed runtime and monitoring information from a daemon developed in C.

In my case these information are e.g.

  • the current system health, like throughput (MB/s), already written data, ...
  • the current configuration

I would use JMX in the Java world and the procfs (or sysfs) interface for a kernel module. A log file doesn't seem to be the best way.

What is the best way for such a information interface for a C daemon?

I thought about opening a socket and implementing a bare-metal http or xmlrpc server, but that seems to be overkill. What are alternatives?

+1  A: 

If you are using a relational database anyway, create another table and fill it with the current status as frequent as necessary. If you don't have a relational database, write the status in a file, and implement some rotation scheme to avoid overwriting a file that somebody reads at that very moment.

Martin v. Löwis
Using an RDBMS for logging is not a good idea - how do you log "database connection failure"? A log should use the simplest, least likely to fail mechanism available.
anon
I didn't propose to use it for logging, nor did the OP ask for logging. Instead, he wanted to query the current status (not a historical one). I completely agree that error reporting should use a very simple mechanism - but I believe this was not the question.
Martin v. Löwis
OK, I aolso believe that an RDBMS is a bad solution for sharing information between processes in real time. Having your GUI (or whatever) poll the database for status changes is a poor solution, IMHO.
anon
A: 

Write to a file. Use a file locking protocol to force atomic reads and writes. Anything you agree on will work. There's probably a UUCP locking library floating around that you can use. In a previous life I found one for Linux. I've also implemented it from scratch. It's fairly trivial to do that too.

Check out the lockdev(3) library on Linux. It's for devices, but it may work for plain files too.

Rob Jones
You normally don't need any locking for logs.
anon
I wasn't suggesting the OP use a log file. I was thinking of a small file that contained a snapshot of the data mentioned. The file would be of a fixed size, and all data would be at known locations. Hence, updating it would require some form of locking to prevent invalid reads.
Rob Jones
+4  A: 

You can use a signal handler in your daemon that reacts to, say USR1, and dumps information to the screen/log/net. This way, you can just send the process a USR1 signal whenever you need the info.

ezpz
+1. SIGINFO is a great choice.
outis
+1  A: 

You could listen on a UNIX-domain socket, and write regularly write the current status (say once a second) to anyone who connects to it. You don't need to implement a protocol like HTTP or XMLRPC - since the communication will be one-way just regularly write a single line of plain text containing the state.

caf
A: 

I like the socket idea best. There's no need to support HTTP or any RPC protocol. You can create a simple application specific protocol that returns requested information. If the server always returns the same info, then handling incoming requests is trivial, though the trivial approach may cause problems down the line if you ever want to expand on the possible queries. The main reason to use a pre-existing protocol is to leverage existing libraries and tools.

Speaking of leveraging, another option is to use SNMP and access the daemon as a managed component. If you need to query/manage the daemon remotely, this option has its advantages, but otherwise can turn out to be greater overkill than an HTTP server.

outis