Merging serial model from branch; converting to the hideous indentation style of...
[lwes-journaller.git] / src / lwes_mondemand.c
blob483ce19076ef14562af9bad685e6b39a91807b8e
1 #include "lwes_mondemand.h"
2 #include "opt.h"
3 #include "stats.h"
4 #include <string.h>
6 #ifdef HAVE_MONDEMAND
8 struct mondemand_client *client;
9 #define mondemand_inc(x) mondemand_increment_key_by_val(client, #x, stats->x)
11 static void init()
13 if (client==NULL && arg_mondemand_host!=NULL && arg_mondemand_ip!=NULL)
15 struct mondemand_transport *transport = NULL;
16 client = mondemand_client_create("lwes-journaller");
17 mondemand_set_context(client,"host",arg_mondemand_host);
18 transport = mondemand_transport_lwes_create(arg_mondemand_ip,arg_mondemand_port,NULL,0,0);
19 if (transport)
21 mondemand_add_transport(client, transport);
23 else
25 LOG_WARN("Unable to create mondemand transport to connect to %s:%d",arg_mondemand_ip,arg_mondemand_port);
30 void mondemand_enqueuer_stats (const struct enqueuer_stats* stats, time_t now)
32 init();
33 if (client==NULL) return;
34 mondemand_inc(socket_errors_since_last_rotate);
35 mondemand_inc(bytes_received_total);
36 mondemand_inc(bytes_received_since_last_rotate);
37 mondemand_inc(packets_received_total);
38 mondemand_inc(packets_received_since_last_rotate);
39 mondemand_increment_key_by_val(client, "rotate", now);
40 mondemand_flush_stats(client);
43 void mondemand_dequeuer_stats (const struct dequeuer_stats* stats, time_t now)
45 init();
46 if (client==NULL) return;
47 mondemand_inc(loss_since_last_rotate);
48 mondemand_inc(bytes_written_total);
49 mondemand_inc(bytes_written_since_last_rotate);
50 mondemand_inc(packets_written_total);
51 mondemand_inc(packets_written_since_last_rotate);
52 mondemand_inc(bytes_written_in_burst);
53 mondemand_inc(packets_written_in_burst);
54 mondemand_inc(hiq);
55 mondemand_inc(hiq_start);
56 mondemand_inc(hiq_last);
57 mondemand_inc(hiq_since_last_rotate);
58 mondemand_inc(bytes_written_in_burst_since_last_rotate);
59 mondemand_inc(packets_written_in_burst_since_last_rotate);
60 mondemand_inc(start_time);
61 mondemand_inc(last_rotate);
62 mondemand_increment_key_by_val(client, "rotate", now);
63 mondemand_flush_stats(client);
66 static int get_mondemand_level (log_level_t level)
68 switch (level)
70 case LOG_ERROR:
71 return M_LOG_ERR;
72 case LOG_WARNING:
73 return M_LOG_WARNING;
74 case LOG_INFO:
75 return M_LOG_INFO;
76 default:
77 return M_LOG_DEBUG;
81 void mondemand_log_msg (log_level_t level, const char *fname, int lineno, const char *buf)
83 const int mondemand_level = get_mondemand_level(level);
84 if (mondemand_level_is_enabled(client, mondemand_level))
86 mondemand_log_real(client, fname, lineno, level, MONDEMAND_NULL_TRACE_ID, "%s", buf);
90 #else /* HAVE_MONDEMAND */
92 void mondemand_enqueuer_stats (const struct enqueuer_stats* stats, time_t now)
94 (void)stats;
95 (void)now;
98 void mondemand_dequeuer_stats (const struct dequeuer_stats* stats, time_t now)
100 (void)stats;
101 (void)now;
104 void mondemand_log_msg (log_level_t level, const char *fname, int lineno, const char *buf)
106 (void)level;
107 (void)fname;
108 (void)lineno;
109 (void)buf;
112 #endif /* HAVE_MONDEMAND */