Event Types
There are two basic types of events in MonDemand - log events and stats events. Log events are
text messages that represent something that has happened, stats events represent the numerical
state of an thread of control. Most applications provide a logging framework such as log4j that can be re-used for log events, however stats events are usually created from within the application.
There is a third type of event that can be used to track workflow that is under development.
Java Example
import java.net.InetAddress;
import org.mondemand.Client;
import org.mondemand.Transport;
public class MyApp {
private static Client client = null;
public static void main(String[] args) {
// or could be implemented as singleton if desired
client = new Client("MyApp");
// setup the transport. this also only needs to be done once, not per request
try {
Transport transport = new LWESTransport(InetAddress.getByName("224.1.11.111"),
9191, null);
client.addTransport(transport);
} catch(Exception e) {}
// set some optional persistent contexts
client.addContext("clusterID", "101");
client.addContext("partitionID", "202");
/* typically everything below this line would be done in the main event loop */
// log some messages
client.emerg("Emergency!");
// log some stats
client.setKey("responseTime", 101);
client.increment("counter");
// flush the messages to the network
client.flush()
}
}
C Example
#include "mondemand.h"
int
main(void)
{
struct mondemand_client *client = NULL;
struct mondemand_transport *transport = NULL;
// create the client
client = mondemand_client_create("my_application");
// create a transport to send data
transport = mondemand_transport_lwes_create("224.1.11.111", 9191, NULL, 0, 60);
// attach the transport to the client
mondemand_add_transport(client, transport);
// add some contextual information to the client
mondemand_set_context(client, "cluster_id", "123");
// log some messages
mondemand_info(client, MONDEMAND_NULL_TRACE_ID, "Hello! I am %s", "123");
// log some stats
mondemand_set_key_by_val(client, "stat_1", 1234);
mondemand_increment_key(client, "stat_2");
// send it to the network
mondemand_flush(client);
return 0;
}