Whamcloud - gitweb
LU-3652 luref: Fix building
[fs/lustre-release.git] / snmp / lustre-snmp-util.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * snmp/lustre-snmp-util.h
35  *
36  * Author: PJ Kirner <pjkirner@clusterfs.com>
37  */
38
39 #ifndef LUSTRE_SNMP_UTIL_H
40 #define LUSTRE_SNMP_UTIL_H
41
42 /*
43  * Definitions of magic values
44  */
45
46 #define SYSVERSION          20
47 #define SYSKERNELVERSION    21
48 #define SYSHEALTHCHECK      22
49 #define SYSSTATUS           23
50
51 #define OSDNUMBER           30
52 #define OSDUUID             31
53 #define OSDCOMMONNAME       32
54 #define OSDCAPACITY         33
55 #define OSDFREECAPACITY     34
56 #define OSDOBJECTS          35
57 #define OSDFREEOBJECTS      36
58
59 #define OSCNUMBER           40
60 #define OSCUUID             41
61 #define OSCCOMMONNAME       42
62 #define OSCOSTSERVERUUID    43
63 #define OSCCAPACITY         44
64 #define OSCFREECAPACITY     45
65 #define OSCOBJECTS          46
66 #define OSCFREEOBJECTS      47
67
68 #define MDDNUMBER           50
69 #define MDDUUID             51
70 #define MDDCOMMONNAME       52
71 #define MDDCAPACITY         53
72 #define MDDFREECAPACITY     54
73 #define MDDFILES            55
74 #define MDDFREEFILES        56
75 #define MDSNBSAMPLEDREQ     57
76
77 #define MDCNUMBER           60
78 #define MDCUUID             61
79 #define MDCCOMMONNAME       62
80 #define MDCMDSSERVERUUID    63
81 #define MDCCAPACITY         64
82 #define MDCFREECAPACITY     65
83 #define MDCOBJECTS          66
84 #define MDCFREEOBJECTS      67
85
86 #define CLIMOUNTNUMBER      70
87 #define CLIUUID             71
88 #define CLICOMMONNAME       72
89 #define CLIMDCUUID          73
90 #define CLIMDCCOMMONNAME    74
91 #define CLIUSESLOV          75
92 #define CLILOVUUID          76
93 #define CLILOVCOMMONNAME    77
94
95 #define LOVNUMBER           80
96 #define LOVUUID             81
97 #define LOVCOMMONNAME       82
98 #define LOVNUMOBD           83
99 #define LOVNUMACTIVEOBD     84
100 #define LOVCAPACITY         85
101 #define LOVFREECAPACITY     86
102 #define LOVFILES            87
103 #define LOVFREEFILES        88
104 #define LOVSTRIPECOUNT      89
105 #define LOVSTRIPEOFFSET     90
106 #define LOVSTRIPESIZE       91
107 #define LOVSTRIPETYPE       92
108
109 #define LDLMNUMBER          100
110 #define LDLMNAMESPACE       101
111 #define LDLMLOCKCOUNT       102
112 #define LDLMUNUSEDLOCKCOUNT 103
113 #define LDLMRESOURCECOUNT   104
114
115 #define LNETNUMBER          110
116 #define LNETMSGSALLOC       111
117 #define LNETMSGSMAX         112
118 #define LNETERRORS          113
119 #define LNETSENDCOUNT       114
120 #define LNETRECVCOUNT       115
121 #define LNETROUTECOUNT      116
122 #define LNETDROPCOUNT       117
123 #define LNETSENDBYTES       118
124 #define LNETRECVBYTES       119
125 #define LNETROUTEBYTES      120
126 #define LNETDROPBYTES       121
127
128 /* Defining the proc paths for Lustre file system */
129 #define LUSTRE_PATH                 "/proc/fs/lustre/"
130 #define LNET_PATH                   "/proc/sys/lnet/"
131 #define OSD_PATH                    LUSTRE_PATH "obdfilter/"
132 #define OSC_PATH                    LUSTRE_PATH "osc/"
133 #define MDS_PATH                    LUSTRE_PATH "mds/"
134 #define MDC_PATH                    LUSTRE_PATH "mdc/"
135 #define CLIENT_PATH                 LUSTRE_PATH "llite/"
136 #define LOV_PATH                    LUSTRE_PATH "lov/"
137 #define LDLM_PATH                   LUSTRE_PATH "ldlm/namespaces/"
138 #define FILEPATH_MDS_SERVER_STATS             LUSTRE_PATH "mdt/MDS/mds/stats"
139 #define FILEPATH_MDS_SERVER_READPAGE_STATS             LUSTRE_PATH "mdt/MDS/mds_readpage/stats"
140 #define FILEPATH_MDS_SERVER_SETATTR_STATS             LUSTRE_PATH "mdt/MDS/mds_setattr/stats"
141
142 /* Common procfs file entries that are refrenced in mulitple locations*/
143 #define FILENAME_SYSHEALTHCHECK     "health_check"
144 #define FILENAME_SYS_STATUS         "/var/lustre/sysStatus"
145
146 #define FILENAME_NUM_REF            "num_refs"
147 #define FILENAME_UUID               "uuid"
148 #define FILENAME_COMMON_NAME        "common_name"
149 #define FILENAME_KBYTES_TOTAL       "kbytestotal"
150 #define FILENAME_KBYTES_FREE        "kbytesfree"
151 #define FILENAME_FILES_TOTAL        "filestotal"
152 #define FILENAME_FILES_FREE         "filesfree"
153 #define STR_REQ_WAITIME             "req_waittime"
154
155 /* strings which the file /var/lustre/sysStatus can hold */
156 #define STR_ONLINE                  "online"
157 #define STR_ONLINE_PENDING          "online pending"
158 #define STR_OFFLINE                 "offline"
159 #define STR_OFFLINE_PENDING         "offline pending"
160
161
162 /* Script required for starting/stopping lustre services */
163 #define LUSTRE_SERVICE              "/etc/init.d/lustre"
164
165 #define MIN_LEN(val1,val2)          (((val1)>(val2))?(val2):(val1))
166
167 /* The max size of a lustre procfs path name*/
168 #define MAX_PATH_SIZE               512
169
170 /* The max size of a string read from procfs */
171 #define MAX_LINE_SIZE               512
172
173 /* Types passed to get_file_list() */
174 #define DIR_TYPE                    1
175 #define FILE_TYPE                   0
176
177 /* Defining return values */
178 #define SUCCESS                     0
179 #define ERROR                       -1
180
181 typedef struct counter64 counter64;
182
183 typedef enum {
184     ONLINE = 1,
185     OFFLINE,
186     ONLINE_PENDING,
187     OFFLINE_PENDING,
188     RESTART
189 } lustre_sysstatus;
190
191 /* File operation related functions */
192 char *get_file_list(const char *dirname, int file_type, uint32_t *count);
193 extern int  is_directory(const char *filename);
194 extern int  read_string(const char *filepath, char *lustre_var,size_t var_size);
195 int read_counter64(const char *file_path, counter64 *c64,int factor);
196 int read_ulong(const char *file_path,unsigned long* valuep);
197
198 /* Start/Stop/Restart Lustre Services */
199 extern void lustrefs_ctrl(int command);
200 extern int get_sysstatus();
201
202 extern void report(const char *fmt, ...);
203
204 /* Table Driven SNMP OID Handler support*/
205 typedef unsigned char* (*f_oid_handler_t)(
206     const char* file_path,
207     size_t  *var_len);
208
209 struct oid_table
210 {
211     int magic;                  /*The magic number*/ 
212     const char *name;           /*The procfs name*/
213     f_oid_handler_t fhandler;   /*The handler */
214 };
215
216 unsigned char* oid_table_ulong_handler(const char* file_path,size_t  *var_len);
217 unsigned char* oid_table_c64_handler(const char* file_path,size_t  *var_len);
218 unsigned char* oid_table_c64_kb_handler(const char* file_path,size_t  *var_len);
219 unsigned char* oid_table_obj_name_handler(const char* file_path,size_t  *var_len);
220 unsigned char* oid_table_string_handler(const char* file_path,size_t *var_len);
221 unsigned char* oid_table_is_directory_handler(const char* file_path,size_t *var_len);
222 unsigned char *
223     var_genericTable(struct variable *vp,
224         oid     *name,
225         size_t  *length,
226         int     exact,
227         size_t  *var_len,
228         WriteMethod **write_method,
229         const char *path,
230         struct oid_table *ptable);
231
232 void convert_ull(counter64 *c64, unsigned long long ull, size_t *var_len);
233 int stats_values(char * filepath,char * name_value, unsigned long long * nb_sample, unsigned long long * min, unsigned long long * max, unsigned long long * sum, unsigned long long * sum_square);
234 extern int mds_stats_values(char * name_value, unsigned long long * nb_sample, unsigned long long * min, unsigned long long * max, unsigned long long * sum, unsigned long long * sum_square);
235
236  /* export for net-snmp util-funcs */
237 int             header_simple_table(struct variable *, oid *, size_t *,
238                                     int, size_t *,
239                                     WriteMethod ** write_method, int);
240 int             header_generic(struct variable *, oid *, size_t *, int,
241                                size_t *, WriteMethod **);
242
243 #endif /* LUSTRE_SNMP_UTIL_H */