-
Notifications
You must be signed in to change notification settings - Fork 2
/
send.c
104 lines (85 loc) · 2.68 KB
/
send.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "callbacks.h"
#include "netdata.h"
#include "send.h"
struct send_statistics {
int start_delivery;
int end_msg;
int delivery_success;
int delivery_failure;
int delivery_deferral;
};
static
void *
send_data_init() {
struct send_statistics * ret;
ret = calloc(1, sizeof * ret);
return ret;
}
static
void
clear_send_statistics(struct send_statistics * data) {
memset(data, 0, sizeof * data);
}
static
int
print_send_hdr(const char * name) {
char title[BUFSIZ];
sprintf(title, "Qmail Send for %s", name);
nd_chart("qmail", name, "", "send qmail", title, "# send", NULL, "qmail.send", ND_CHART_TYPE_AREA);
nd_dimension("start_delivery", "Start/End Delivery", ND_ALG_ABSOLUTE, 1, 1, ND_VISIBLE);
nd_dimension("end_msg", "End Msg", ND_ALG_ABSOLUTE, -1, 1, ND_VISIBLE);
sprintf(title, "Qmail Send delivery status for %s", name);
nd_chart("qmail", name, "delivery", "send delivery", title,
"# deliveries", NULL, "qmail.send_delivery", ND_CHART_TYPE_LINE);
nd_dimension("delivery_success", "Success", ND_ALG_ABSOLUTE, 1, 1, ND_VISIBLE);
nd_dimension("delivery_failure", "Failure", ND_ALG_ABSOLUTE, 1, 1, ND_VISIBLE);
nd_dimension("delivery_deferral", "Deferral", ND_ALG_ABSOLUTE, 1, 1, ND_VISIBLE);
return fflush(stdout);
}
static
int
print_send_data(const char * name, const struct send_statistics * data, const unsigned long time) {
nd_begin_time("qmail", name, "", time);
nd_set("start_delivery", data->start_delivery);
nd_set("end_msg", data->end_msg);
nd_end();
nd_begin_time("qmail", name, "delivery", time);
nd_set("delivery_success", data->delivery_success);
nd_set("delivery_failure", data->delivery_failure);
nd_set("delivery_deferral", data->delivery_deferral);
nd_end();
return fflush(stdout);
}
static
void
process_send_log_line(const char * line, struct send_statistics * data) {
const char * ptr;
if (strstr(line, "starting delivery")) {
data->start_delivery++;
} else if (strstr(line, "end msg")) {
data->end_msg++;
} else if ((ptr = strstr(line, "delivery "))) {
if (strstr(ptr, "success:")) {
data->delivery_success++;
} else if (strstr(ptr, "failure:")) {
data->delivery_failure++;
} else if (strstr(ptr, "deferral:")) {
data->delivery_deferral++;
}
}
}
static
struct stat_func send = {
.init = &send_data_init,
.fini = &free,
.print_hdr = &print_send_hdr,
.print = (int (*)(const char *, const void *, unsigned long))&print_send_data,
.process = (void (*)(const char *, void *))&process_send_log_line,
.postprocess = NULL,
.clear = (void (*)(void *))&clear_send_statistics,
};
struct stat_func * send_func = &send;