https://github.com/bodgit/libevent-graphite
Non-blocking Graphite client for libevent-based applications
https://github.com/bodgit/libevent-graphite
Last synced: 4 months ago
JSON representation
Non-blocking Graphite client for libevent-based applications
- Host: GitHub
- URL: https://github.com/bodgit/libevent-graphite
- Owner: bodgit
- Created: 2013-03-28T11:37:00.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-06-20T16:22:38.000Z (about 12 years ago)
- Last Synced: 2025-03-05T04:34:01.242Z (4 months ago)
- Language: C
- Size: 148 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
libevent-graphite - asynchronous non-blocking Graphite client
=============================================================Based around libevent bufferevents and designed to be used as part of a bigger
libevent-based application.Example usage:
#include
#include "graphite.h"
void
connect_cb(struct graphite_connection *c, void *arg)
{
struct event *ev = (struct event *)arg;
struct timeval tv = { 60, 0 };
printf("Connected\n");
evtimer_add(ev, &tv);
}
void
disconnect_cb(struct graphite_connection *c, void *arg)
{
struct event *ev = (struct event *)arg;
printf("Disconnected\n");
evtimer_del(ev);
}
void
timer(int fd, short event, void *arg)
{
struct graphite_connection *c = (struct graphite_connection *)arg;
struct timeval tv;
gettimeofday(&tv, NULL);
graphite_send(c, "universe.answer", "42", tv.tv_sec);
}
int
main(int argc, char *argv[])
{
struct event_base *base;
struct timeval tv = { 10, 0 };
struct graphite_connection *c;
struct event *ev;
base = event_base_new();
if (graphite_init(base) < 0)
return (-1);
if ((c = graphite_connection_new("192.0.2.1",
GRAPHITE_DEFAULT_PORT, tv)) == NULL)
return (-1);
ev = event_new(base, -1, EV_PERSIST, timer, (void *)c);
graphite_connection_setcb(c, connect_cb, disconnect_cb,
(void *)ev);
graphite_connect(c);
event_base_dispatch(base);
return (0);
}