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