*** empty log message ***
[mmondor.git] / mmsoftware / mmlib / mmstat.h
1 /* $Id: mmstat.h,v 1.10 2004/06/01 19:11:57 mmondor Exp $ */
2
3 /*
4 * Copyright (C) 2002-2004, Matthew Mondor
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Matthew Mondor.
18 * 4. The name of Matthew Mondor may not be used to endorse or promote
19 * products derived from this software without specific prior written
20 * permission.
21 * 5. Redistribution of source code may not be released under the terms of
22 * any GNU Public License derivate.
23 *
24 * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL MATTHEW MONDOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36
37
38
39 #ifndef MMSTAT_H
40 #define MMSTAT_H
41
42
43
44
45 #include <sys/types.h>
46
47 #include <mmtypes.h>
48 #include <mmlist.h>
49 #include <mmpool.h>
50 #include <mmhash.h>
51
52
53
54
55 #define MAX_TRANSACT 32
56 #define KEY_SIZE 256
57
58 typedef struct mmstat_entry mmstatent_t;
59 typedef struct mmstat_handle mmstat_t;
60 typedef struct mmstat_report mmstatres_t;
61
62
63
64
65 enum stat_type {
66 STAT_TRANSACT = 1,
67 STAT_NEWFILE = 2,
68 STAT_UPDATE = 3,
69 STAT_RESET = 4,
70 STAT_DELETE = 5
71 };
72
73 struct mmstat_entry {
74 int64_t value;
75 time_t created, modified;
76 uid_t uid;
77 char key[KEY_SIZE];
78 bool persistent;
79 };
80
81 struct log_entry {
82 enum stat_type type;
83 uid_t uid;
84 time_t time;
85 bool persistent, autoflush;
86 char key[KEY_SIZE];
87 union {
88 struct {
89 bool begin;
90 } transact;
91 struct {
92 long lognum;
93 } newfile;
94 struct {
95 int64_t modifier;
96 } update;
97 struct {
98 int64_t value;
99 } reset;
100 struct {
101 } del;
102 } un;
103 };
104
105 struct mmstat_handle {
106 bool persistent, transaction, autoflush;
107 int transact_pos;
108 struct log_entry entries[MAX_TRANSACT];
109 };
110
111 struct mmstat_report {
112 int fd;
113 mmstatent_t entry;
114 };
115
116 struct mmstat_config {
117 char USER[32], GROUPS[256], LOG_FACILITY[32], PID_FILE[256],
118 LOCK_FILE[256], LOG_SOCKET[256], STAT_SOCKET[256], ENV_DIR[128],
119 LOG_GROUP[32], STAT_GROUP[32];
120 long SYNC_INTERVAL, SYNC_BYTES, MAX_LOGSIZE, STATS_RATE, STATS_TIME;
121 gid_t log_group, stat_group;
122 off_t max_logsize;
123 };
124
125
126
127
128 extern bool mmstat_initialize(void);
129 extern bool mmstat_init(mmstat_t *, bool, bool);
130 extern bool mmstat(mmstat_t *, enum stat_type, int64_t,
131 const char *, ...);
132 extern bool mmstat_transact(mmstat_t *, bool);
133 extern mmstatres_t * mmstat_report(const char *, ...);
134 extern mmstatent_t * mmstat_nextres(mmstatres_t *);
135 extern mmstatres_t * mmstat_freeres(mmstatres_t *);
136 extern bool mmstat_rotate(const char *, const char *);
137
138
139
140
141 #endif