Whamcloud - gitweb
LU-15279 ptlrpc: use a cached value
[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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*
27  * This file is part of Lustre, http://www.lustre.org/
28  *
29  * snmp/lustre-snmp-util.h
30  *
31  * Author: PJ Kirner <pjkirner@clusterfs.com>
32  */
33
34 #ifndef LUSTRE_SNMP_UTIL_H
35 #define LUSTRE_SNMP_UTIL_H
36
37 #include <libcfs/util/param.h>
38
39 /*
40  * Definitions of magic values
41  */
42
43 #define SYSVERSION          20
44 #define SYSKERNELVERSION    21
45 #define SYSHEALTHCHECK      22
46 #define SYSSTATUS           23
47
48 #define OSDNUMBER           30
49 #define OSDUUID             31
50 #define OSDCOMMONNAME       32
51 #define OSDCAPACITY         33
52 #define OSDFREECAPACITY     34
53 #define OSDOBJECTS          35
54 #define OSDFREEOBJECTS      36
55
56 #define OSCNUMBER           40
57 #define OSCUUID             41
58 #define OSCCOMMONNAME       42
59 #define OSCOSTSERVERUUID    43
60 #define OSCCAPACITY         44
61 #define OSCFREECAPACITY     45
62 #define OSCOBJECTS          46
63 #define OSCFREEOBJECTS      47
64
65 #define MDDNUMBER           50
66 #define MDDUUID             51
67 #define MDDCOMMONNAME       52
68 #define MDDCAPACITY         53
69 #define MDDFREECAPACITY     54
70 #define MDDFILES            55
71 #define MDDFREEFILES        56
72 #define MDSNBSAMPLEDREQ     57
73
74 #define MDCNUMBER           60
75 #define MDCUUID             61
76 #define MDCCOMMONNAME       62
77 #define MDCMDSSERVERUUID    63
78 #define MDCCAPACITY         64
79 #define MDCFREECAPACITY     65
80 #define MDCOBJECTS          66
81 #define MDCFREEOBJECTS      67
82
83 #define CLIMOUNTNUMBER      70
84 #define CLIUUID             71
85 #define CLICOMMONNAME       72
86 #define CLIMDCUUID          73
87 #define CLIMDCCOMMONNAME    74
88 #define CLIUSESLOV          75
89 #define CLILOVUUID          76
90 #define CLILOVCOMMONNAME    77
91
92 #define LOVNUMBER           80
93 #define LOVUUID             81
94 #define LOVCOMMONNAME       82
95 #define LOVNUMOBD           83
96 #define LOVNUMACTIVEOBD     84
97 #define LOVCAPACITY         85
98 #define LOVFREECAPACITY     86
99 #define LOVFILES            87
100 #define LOVFREEFILES        88
101 #define LOVSTRIPECOUNT      89
102 #define LOVSTRIPEOFFSET     90
103 #define LOVSTRIPESIZE       91
104 #define LOVSTRIPETYPE       92
105
106 #define LDLMNUMBER          100
107 #define LDLMNAMESPACE       101
108 #define LDLMLOCKCOUNT       102
109 #define LDLMUNUSEDLOCKCOUNT 103
110 #define LDLMRESOURCECOUNT   104
111
112 #define LNETNUMBER          110
113 #define LNETMSGSALLOC       111
114 #define LNETMSGSMAX         112
115 #define LNETERRORS          113
116 #define LNETSENDCOUNT       114
117 #define LNETRECVCOUNT       115
118 #define LNETROUTECOUNT      116
119 #define LNETDROPCOUNT       117
120 #define LNETSENDBYTES       118
121 #define LNETRECVBYTES       119
122 #define LNETROUTEBYTES      120
123 #define LNETDROPBYTES       121
124
125 /* Common procfs file entries that are refrenced in mulitple locations*/
126 #define FILENAME_SYS_STATUS         "/var/lustre/sysStatus"
127
128 #define FILENAME_NUM_REF            "num_refs"
129 #define FILENAME_UUID               "uuid"
130 #define FILENAME_COMMON_NAME        "common_name"
131 #define FILENAME_KBYTES_TOTAL       "kbytestotal"
132 #define FILENAME_KBYTES_FREE        "kbytesfree"
133 #define FILENAME_FILES_TOTAL        "filestotal"
134 #define FILENAME_FILES_FREE         "filesfree"
135 #define STR_REQ_WAITIME             "req_waittime"
136
137 /* strings which the file /var/lustre/sysStatus can hold */
138 #define STR_ONLINE                  "online"
139 #define STR_ONLINE_PENDING          "online pending"
140 #define STR_OFFLINE                 "offline"
141 #define STR_OFFLINE_PENDING         "offline pending"
142
143
144 /* Script required for starting/stopping lustre services */
145 #define LUSTRE_SERVICE              "/etc/init.d/lustre"
146
147 #define MIN_LEN(val1,val2)          (((val1)>(val2))?(val2):(val1))
148
149 /* The max size of a lustre procfs path name*/
150 #define MAX_PATH_SIZE               512
151
152 /* The max size of a string read from procfs */
153 #define MAX_LINE_SIZE               512
154
155 /* Types passed to get_file_list() */
156 #define DIR_TYPE                    1
157 #define FILE_TYPE                   0
158
159 /* Defining return values */
160 #define SUCCESS                     0
161 #define ERROR                       -1
162
163 typedef struct counter64 counter64;
164
165 typedef enum {
166     ONLINE = 1,
167     OFFLINE,
168     ONLINE_PENDING,
169     OFFLINE_PENDING,
170     RESTART
171 } lustre_sysstatus;
172
173 /* File operation related functions */
174 char *get_file_list(const char *dirname, int file_type, uint32_t *count);
175 extern int  is_directory(const char *filename);
176 extern int  read_string(const char *filepath, char *lustre_var,size_t var_size);
177 int read_counter64(const char *file_path, counter64 *c64,int factor);
178 int read_ulong(const char *file_path,unsigned long* valuep);
179
180 /* Start/Stop/Restart Lustre Services */
181 extern void lustrefs_ctrl(int command);
182 extern int get_sysstatus();
183
184 extern void report(const char *fmt, ...);
185
186 /* Table Driven SNMP OID Handler support*/
187 typedef unsigned char* (*f_oid_handler_t)(
188     const char* file_path,
189     size_t  *var_len);
190
191 struct oid_table
192 {
193     int magic;                  /*The magic number*/ 
194     const char *name;           /*The procfs name*/
195     f_oid_handler_t fhandler;   /*The handler */
196 };
197
198 unsigned char* oid_table_ulong_handler(const char* file_path,size_t  *var_len);
199 unsigned char* oid_table_c64_handler(const char* file_path,size_t  *var_len);
200 unsigned char* oid_table_c64_kb_handler(const char* file_path,size_t  *var_len);
201 unsigned char* oid_table_obj_name_handler(const char* file_path,size_t  *var_len);
202 unsigned char* oid_table_string_handler(const char* file_path,size_t *var_len);
203 unsigned char* oid_table_is_directory_handler(const char* file_path,size_t *var_len);
204 unsigned char *
205     var_genericTable(struct variable *vp,
206         oid     *name,
207         size_t  *length,
208         int     exact,
209         size_t  *var_len,
210         WriteMethod **write_method,
211         const char *path,
212         struct oid_table *ptable);
213
214 void convert_ull(counter64 *c64, unsigned long long ull, size_t *var_len);
215 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);
216 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);
217
218  /* export for net-snmp util-funcs */
219 int             header_simple_table(struct variable *, oid *, size_t *,
220                                     int, size_t *,
221                                     WriteMethod ** write_method, int);
222 int             header_generic(struct variable *, oid *, size_t *, int,
223                                size_t *, WriteMethod **);
224
225 #endif /* LUSTRE_SNMP_UTIL_H */