1: #include "first.h"
2:
3: #include "status_counter.h"
4:
5: #include <stdlib.h>
6:
7: /**
8: * The status array can carry all the status information you want
9: * the key to the array is <module-prefix>.<name>
10: * and the values are counters
11: *
12: * example:
13: * fastcgi.backends = 10
14: * fastcgi.active-backends = 6
15: * fastcgi.backend.<key>.load = 24
16: * fastcgi.backend.<key>....
17: *
18: * fastcgi.backend.<key>.disconnects = ...
19: */
20:
21: data_integer *status_counter_get_counter(server *srv, const char *s, size_t len) {
22: data_integer *di;
23:
24: if (NULL == (di = (data_integer *)array_get_element(srv->status, s))) {
25: /* not found, create it */
26:
27: if (NULL == (di = (data_integer *)array_get_unused_element(srv->status, TYPE_INTEGER))) {
28: di = data_integer_init();
29: }
30: buffer_copy_string_len(di->key, s, len);
31: di->value = 0;
32:
33: array_insert_unique(srv->status, (data_unset *)di);
34: }
35: return di;
36: }
37:
38: /* dummies of the statistic framework functions
39: * they will be moved to a statistics.c later */
40: int status_counter_inc(server *srv, const char *s, size_t len) {
41: data_integer *di = status_counter_get_counter(srv, s, len);
42:
43: di->value++;
44:
45: return 0;
46: }
47:
48: int status_counter_dec(server *srv, const char *s, size_t len) {
49: data_integer *di = status_counter_get_counter(srv, s, len);
50:
51: if (di->value > 0) di->value--;
52:
53: return 0;
54: }
55:
56: int status_counter_set(server *srv, const char *s, size_t len, int val) {
57: data_integer *di = status_counter_get_counter(srv, s, len);
58:
59: di->value = val;
60:
61: return 0;
62: }
63:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>