Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / snmp / lustre-snmp-util.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (c) 2005 Cluster File Systems, Inc.
5  *   Author: PJ Kirner <pjkirner@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23 #ifndef LUSTRE_SNMP_UTIL_H
24 #define LUSTRE_SNMP_UTIL_H
25
26 /*
27  * Definitions of magic values
28  */
29
30 #define SYSVERSION          20
31 #define SYSKERNELVERSION    21
32 #define SYSHEALTHCHECK      22
33 #define SYSSTATUS           23
34
35 #define OSDNUMBER           30
36 #define OSDUUID             31
37 #define OSDCOMMONNAME       32
38 #define OSDCAPACITY         33
39 #define OSDFREECAPACITY     34
40 #define OSDOBJECTS          35
41 #define OSDFREEOBJECTS      36
42
43 #define OSCNUMBER           40
44 #define OSCUUID             41
45 #define OSCCOMMONNAME       42
46 #define OSCOSTSERVERUUID    43
47 #define OSCCAPACITY         44
48 #define OSCFREECAPACITY     45
49 #define OSCOBJECTS          46
50 #define OSCFREEOBJECTS      47
51
52 #define MDDNUMBER           50
53 #define MDDUUID             51
54 #define MDDCOMMONNAME       52
55 #define MDDCAPACITY         53
56 #define MDDFREECAPACITY     54
57 #define MDDFILES            55
58 #define MDDFREEFILES        56
59 #define MDSNBSAMPLEDREQ     57
60
61 #define MDCNUMBER           60
62 #define MDCUUID             61
63 #define MDCCOMMONNAME       62
64 #define MDCMDSSERVERUUID    63
65 #define MDCCAPACITY         64
66 #define MDCFREECAPACITY     65
67 #define MDCOBJECTS          66
68 #define MDCFREEOBJECTS      67
69
70 #define CLIMOUNTNUMBER      70
71 #define CLIUUID             71
72 #define CLICOMMONNAME       72
73 #define CLIMDCUUID          73
74 #define CLIMDCCOMMONNAME    74
75 #define CLIUSESLOV          75
76 #define CLILOVUUID          76
77 #define CLILOVCOMMONNAME    77
78
79 #define LOVNUMBER           80
80 #define LOVUUID             81
81 #define LOVCOMMONNAME       82
82 #define LOVNUMOBD           83
83 #define LOVNUMACTIVEOBD     84
84 #define LOVCAPACITY         85
85 #define LOVFREECAPACITY     86
86 #define LOVFILES            87
87 #define LOVFREEFILES        88
88 #define LOVSTRIPECOUNT      89
89 #define LOVSTRIPEOFFSET     90
90 #define LOVSTRIPESIZE       91
91 #define LOVSTRIPETYPE       92
92
93 #define LDLMNUMBER          100
94 #define LDLMNAMESPACE       101
95 #define LDLMLOCKCOUNT       102
96 #define LDLMUNUSEDLOCKCOUNT 103
97 #define LDLMRESOURCECOUNT   104
98
99 /* Defining the proc paths for Lustre file system */
100 #define LUSTRE_PATH                 "/proc/fs/lustre/"
101 #define OSD_PATH                    LUSTRE_PATH "obdfilter/"
102 #define OSC_PATH                    LUSTRE_PATH "osc/"
103 #define MDS_PATH                    LUSTRE_PATH "mds/"
104 #define MDC_PATH                    LUSTRE_PATH "mdc/"
105 #define CLIENT_PATH                 LUSTRE_PATH "llite/"
106 #define LOV_PATH                    LUSTRE_PATH "lov/"
107 #define LDLM_PATH                   LUSTRE_PATH "ldlm/namespaces/"
108 #define FILEPATH_MDS_SERVER_STATS             LUSTRE_PATH "mdt/MDS/mds/stats"
109 #define FILEPATH_MDS_SERVER_READPAGE_STATS             LUSTRE_PATH "mdt/MDS/mds_readpage/stats"
110 #define FILEPATH_MDS_SERVER_SETATTR_STATS             LUSTRE_PATH "mdt/MDS/mds_setattr/stats"
111
112 /* Common procfs file entries that are refrenced in mulitple locations*/
113 #define FILENAME_SYSHEALTHCHECK     "health_check"
114 #define FILENAME_SYS_STATUS         "/var/lustre/sysStatus"
115
116 #define FILENAME_NUM_REF            "num_refs"
117 #define FILENAME_UUID               "uuid"
118 #define FILENAME_COMMON_NAME        "common_name"
119 #define FILENAME_KBYTES_TOTAL       "kbytestotal"
120 #define FILENAME_KBYTES_FREE        "kbytesfree"
121 #define FILENAME_FILES_TOTAL        "filestotal"
122 #define FILENAME_FILES_FREE         "filesfree"
123 #define STR_REQ_WAITIME             "req_waittime"
124
125 /* strings which the file /var/lustre/sysStatus can hold */
126 #define STR_ONLINE                  "online"
127 #define STR_ONLINE_PENDING          "online pending"
128 #define STR_OFFLINE                 "offline"
129 #define STR_OFFLINE_PENDING         "offline pending"
130
131
132 /* Script required for starting/stopping lustre services */
133 #define LUSTRE_SERVICE              "/etc/init.d/lustre"
134
135 #define MIN_LEN(val1,val2)          (((val1)>(val2))?(val2):(val1))
136
137 /* The max size of a lustre procfs path name*/
138 #define MAX_PATH_SIZE               512
139
140 /* The max size of a string read from procfs */
141 #define MAX_LINE_SIZE               512
142
143 /* Types passed to get_file_list() */
144 #define DIR_TYPE                    1
145 #define FILE_TYPE                   0
146
147 /* Defining return values */
148 #define SUCCESS                     0
149 #define ERROR                       -1
150
151 typedef struct counter64 counter64;
152
153 typedef enum {
154     ONLINE = 1,
155     OFFLINE,
156     ONLINE_PENDING,
157     OFFLINE_PENDING,
158     RESTART
159 } lustre_sysstatus;
160
161 /* File operation related functions */
162 char *get_file_list(const char *dirname, int file_type, uint32_t *count);
163 extern int  is_directory(const char *filename);
164 extern int  read_string(const char *filepath, char *lustre_var,size_t var_size);
165 int read_counter64(const char *file_path, counter64 *c64,int factor);
166 int read_ulong(const char *file_path,unsigned long* valuep);
167
168 /* Start/Stop/Restart Lustre Services */
169 extern void lustrefs_ctrl(int command);
170 extern int get_sysstatus();
171
172 extern void report(const char *fmt, ...);
173
174 /* Table Driven SNMP OID Handler support*/
175 typedef unsigned char* (*f_oid_handler_t)(
176     const char* file_path,
177     size_t  *var_len);
178
179 struct oid_table
180 {
181     int magic;                  /*The magic number*/ 
182     const char *name;           /*The procfs name*/
183     f_oid_handler_t fhandler;   /*The handler */
184 };
185
186 unsigned char* oid_table_ulong_handler(const char* file_path,size_t  *var_len);
187 unsigned char* oid_table_c64_handler(const char* file_path,size_t  *var_len);
188 unsigned char* oid_table_c64_kb_handler(const char* file_path,size_t  *var_len);
189 unsigned char* oid_table_obj_name_handler(const char* file_path,size_t  *var_len);
190 unsigned char* oid_table_string_handler(const char* file_path,size_t *var_len);
191 unsigned char* oid_table_is_directory_handler(const char* file_path,size_t *var_len);
192 unsigned char *
193     var_genericTable(struct variable *vp,
194         oid     *name,
195         size_t  *length,
196         int     exact,
197         size_t  *var_len,
198         WriteMethod **write_method,
199         const char *path,
200         struct oid_table *ptable);
201
202 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);
203 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);
204
205 #endif /* LUSTRE_SNMP_UTIL_H */