*** empty log message ***
[mmondor.git] / mmsoftware / mmlib / mmstat.h
CommitLineData
5eb34fba 1/* $Id: mmstat.h,v 1.2 2003/01/01 14:54:11 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
37#ifndef MMSTAT_H
38#define MMSTAT_H
39
40
41
42
43/* HEADERS */
44
45#include <sys/types.h>
46
47#include <mmtypes.h>
48#include <mmlist.h>
49
50
51
52
53/* DEFINITIONS */
54
55#define MAX_TRANSACT 16
56#define KEY_SIZE 128
57
58
59
60
61/* STRUCTURES */
62
63enum stat_type {
64 STAT_TRANSACT = 1,
65 STAT_NEWFILE = 2,
66 STAT_UPDATE = 3,
67 STAT_RESET = 4,
68 STAT_DELETE = 5
69};
70
71typedef struct mmstat_entry {
72 int64_t value;
73 time_t created, modified;
74 uid_t uid;
75 char key[KEY_SIZE];
76 bool persistant;
77} MMSTATENT;
78
79/* We keep the hash table of the key and rest of data into separate lists so
80 * that frequently referenced hash table does not get swapped out of physical
81 * memory for speed considerations. The referenced data, only required when
82 * a matching hash is found, is potentially larger, and could be partly swapped
83 * out by the kernel. It would be possible to mlock() wanted pages but I
84 * beleive that it is better to leave physical memory to other processes
85 * requireing it, letting the kernel do it's job. The only reason we keep the
86 * data nodes in a list as well is to use the mmlist library buffering to
87 * speed up allocation/deallocation.
88 */
89struct data_node {
90 node nod;
91 struct mmstat_entry entry;
92};
93struct key_node {
94 node nod;
95 u_int64_t hash;
96 struct data_node *data;
97};
98
99struct log_entry {
100 enum stat_type type;
101 uid_t uid;
5eb34fba 102 bool persistant, autoflush;
47071c2b
MM
103 char key[KEY_SIZE];
104 union {
105 struct {
106 bool begin;
107 } transact;
108 struct {
109 long lognum;
110 } newfile;
111 struct {
112 int64_t modifier;
113 } update;
114 struct {
115 int64_t value;
116 } reset;
117 struct {
118 } del;
119 } un;
120};
121
122typedef struct mmstat_handle {
5eb34fba 123 bool persistant, transaction, autoflush;
47071c2b
MM
124 int transact_pos;
125 struct log_entry entries[MAX_TRANSACT];
126} MMSTAT;
127
128typedef struct mmstat_report {
129 int fd;
130 struct mmstat_entry entry;
131} MMSTATRES;
132
133struct mmstat_config {
134 char USER[32], GROUPS[256], LOG_FACILITY[32], PID_FILE[256],
135 LOCK_FILE[256], LOG_SOCKET[256], STAT_SOCKET[256], ENV_DIR[128],
136 LOG_GROUP[32], STAT_GROUP[32];
137 long SYNC_INTERVAL, SYNC_BYTES, MAX_LOGSIZE, STATS_RATE, STATS_TIME;
138 gid_t log_group, stat_group;
139 off_t max_logsize;
140};
141
142
143
144
145/* PROTOTYPES */
146
147bool mmstat_initialize(void);
5eb34fba 148bool mmstat_init(MMSTAT *, bool, bool);
47071c2b
MM
149bool mmstat(MMSTAT *, enum stat_type, int64_t, char *, ...);
150bool mmstat_transact(MMSTAT *, bool);
151MMSTATRES *mmstat_report(char *, ...);
152MMSTATENT *mmstat_nextres(MMSTATRES *);
153MMSTATRES *mmstat_freeres(MMSTATRES *);
154bool mmstat_rotate(char *, char *);
155
156
157
158
159#endif