Welcome To MCC‎ > ‎

Performance Statistics

In order to create high-performance applications it is usually helpful to gather performance statistics from benchmarks of the application. The graphite monitoring service can be used for this purpose. The code example below demonstrate how to do this in c. The code sends a UDP packet to the carbon monitoring service at mon1. For information about the data format please see the carbon documentation and when deciding on a metric path please note that it's structure must avoid the graphite overview becoming unmanageable. In practice this means your metric path must begin either with your username or application name (if statistics are gathered from several applications your metric path must begin with your username). This means your packets should have the following structure:
username.application.jobid.worker datafield datavalue unixtimestamp

Please also note that the data resolution is in seconds and your applications must therefore not send more than 1 UDP packet pr. worker pr. sec.
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>

int main()
    //create socket
    struct addrinfo hints, *servinfo, *p;
    int rc, s;
    const char* addr = "mon1";
    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_INET;
    hints.ai_socktype = SOCK_DGRAM;
    hints.ai_protocol = IPPROTO_UDP;

    if ((rc = getaddrinfo(addr, "2003", &hints, &servinfo)) != 0) {
        fprintf(stderr,"Failed to resolve remote socket address (err=%d)",rc);

    if ((s=socket(servinfo->ai_family, servinfo->ai_socktype, servinfo->ai_protocol)) == -1) {
        fprintf(stderr,"Error creating socket: %s)", strerror(errno));

    const char* base_path =  "username.app";
    const char* job_id = getenv("SLURM_JOB_ID");
    int WORKER_ID = 0;
    const char* data_name = "covered";
    int data = 42;
    char buf[100];

    sprintf(buf, "%s.job_%s.core_%d.%s %d %d\n", base_path, job_id, WORKER_ID,data_name, data, time(NULL));
    if (sendto(s, buf, strlen(buf), 0, servinfo->ai_addr,servinfo->ai_addrlen)==-1) {
        fprintf(stderr,"Failed to send msg: %s", strerror(errno));