1
0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-11-24 02:46:36 +01:00

Add example code for storing data to graphite

This commit is contained in:
Pavel Odintsov 2015-05-10 16:19:24 +03:00
parent e8afbcd75a
commit bfa3951487

@ -0,0 +1,45 @@
#include <iostream>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
#include <time.h>
int main() {
int sockfd = 0;
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("\n Error : Could not create socket \n");
return 1;
}
struct sockaddr_in serv_addr;
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(2003);
if (inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr) <= 0) {
printf("\n inet_pton error occured\n");
return 1;
}
if ( connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
printf("\n Error : Connect Failed \n");
return 1;
}
unsigned long long pps = 10000778;
char buffer[256];
sprintf(buffer, "client.ip.in.udp %ld %ld\n", pps, time(NULL));
int write_result = write(sockfd, buffer, strlen(buffer));
printf("We store %d bytes\n", write_result);
}