*** empty log message ***
[mmondor.git] / mmsoftware / mmlib / mmstat.h
CommitLineData
4fd4b499 1/* $Id: mmstat.h,v 1.4 2003/04/27 19:48:04 mmondor Exp $ */
47071c2b
MM
2
3/*
5eb34fba 4 * Copyright (C) 2002-2003, Matthew Mondor
47071c2b
MM
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 written 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 *
22 * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL MATTHEW MONDOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35
36
4fd4b499
MM
37#ifndef mmstat_t_H
38#define mmstat_t_H
47071c2b
MM
39
40
41
42
43/* HEADERS */
44
45#include <sys/types.h>
46
47#include <mmtypes.h>
48#include <mmlist.h>
7a56f31f 49#include <mmpool.h>
47071c2b
MM
50
51
52
53
54/* DEFINITIONS */
55
56#define MAX_TRANSACT 16
57#define KEY_SIZE 128
58
4fd4b499
MM
59typedef struct mmstat_entry mmstatent_t;
60typedef struct mmstat_handle mmstat_t;
61typedef struct mmstat_report mmstatres_t;
62
47071c2b
MM
63
64
65
66/* STRUCTURES */
67
68enum stat_type {
69 STAT_TRANSACT = 1,
70 STAT_NEWFILE = 2,
71 STAT_UPDATE = 3,
72 STAT_RESET = 4,
73 STAT_DELETE = 5
74};
75
4fd4b499 76struct mmstat_entry {
47071c2b
MM
77 int64_t value;
78 time_t created, modified;
79 uid_t uid;
80 char key[KEY_SIZE];
81 bool persistant;
4fd4b499 82};
47071c2b
MM
83
84/* We keep the hash table of the key and rest of data into separate lists so
85 * that frequently referenced hash table does not get swapped out of physical
86 * memory for speed considerations. The referenced data, only required when
87 * a matching hash is found, is potentially larger, and could be partly swapped
88 * out by the kernel. It would be possible to mlock() wanted pages but I
89 * beleive that it is better to leave physical memory to other processes
90 * requireing it, letting the kernel do it's job. The only reason we keep the
91 * data nodes in a list as well is to use the mmlist library buffering to
92 * speed up allocation/deallocation.
93 */
94struct data_node {
7a56f31f 95 pnode_t node;
4fd4b499 96 mmstatent_t entry;
47071c2b
MM
97};
98struct key_node {
7a56f31f 99 pnode_t node;
47071c2b
MM
100 u_int64_t hash;
101 struct data_node *data;
102};
103
104struct log_entry {
105 enum stat_type type;
106 uid_t uid;
5eb34fba 107 bool persistant, autoflush;
47071c2b
MM
108 char key[KEY_SIZE];
109 union {
110 struct {
111 bool begin;
112 } transact;
113 struct {
114 long lognum;
115 } newfile;
116 struct {
117 int64_t modifier;
118 } update;
119 struct {
120 int64_t value;
121 } reset;
122 struct {
123 } del;
124 } un;
125};
126
4fd4b499 127struct mmstat_handle {
5eb34fba 128 bool persistant, transaction, autoflush;
47071c2b
MM
129 int transact_pos;
130 struct log_entry entries[MAX_TRANSACT];
4fd4b499 131};
47071c2b 132
4fd4b499 133struct mmstat_report {
47071c2b 134 int fd;
4fd4b499
MM
135 mmstatent_t entry;
136};
47071c2b
MM
137
138struct mmstat_config {
139 char USER[32], GROUPS[256], LOG_FACILITY[32], PID_FILE[256],
140 LOCK_FILE[256], LOG_SOCKET[256], STAT_SOCKET[256], ENV_DIR[128],
141 LOG_GROUP[32], STAT_GROUP[32];
142 long SYNC_INTERVAL, SYNC_BYTES, MAX_LOGSIZE, STATS_RATE, STATS_TIME;
143 gid_t log_group, stat_group;
144 off_t max_logsize;
145};
146
147
148
149
150/* PROTOTYPES */
151
152bool mmstat_initialize(void);
4fd4b499
MM
153bool mmstat_init(mmstat_t *, bool, bool);
154bool mmstat(mmstat_t *, enum stat_type, int64_t, const char *, ...);
155bool mmstat_transact(mmstat_t *, bool);
156mmstatres_t *mmstat_report(const char *, ...);
157mmstatent_t *mmstat_nextres(mmstatres_t *);
158mmstatres_t *mmstat_freeres(mmstatres_t *);
159bool mmstat_rotate(const char *, const char *);
47071c2b
MM
160
161
162
163
164#endif