File: sflow.h

package info (click to toggle)
ganglia 3.6.0-7
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 6,484 kB
  • ctags: 3,880
  • sloc: ansic: 27,874; sh: 11,052; python: 6,695; makefile: 565; perl: 366; php: 126; xml: 28
file content (309 lines) | stat: -rw-r--r-- 7,672 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/** @file sflow.h
 *  @brief sFlow definitions for gmond
 *  @author Neil McKee */

#ifndef SFLOW_H
#define SFLOW_H

/* If we use autoconf.  */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

#include "my_inet_ntop.h"
#include "gmond_internal.h"

#define SFLOW_IANA_REGISTERED_PORT 6343

#define SFLOW_VERSION_5 5
#define SFLOW_COUNTERS_SAMPLE 2
#define SFLOW_COUNTERS_SAMPLE_EXPANDED 4
#define SFLOW_DSCLASS_PHYSICAL_ENTITY 2
#define SFLOW_MIN_LEN 36

#define SFLOW_MAX_LOST_SAMPLES 7
#define SFLOW_COUNTERBLOCK_HOST_HID 2000
#define SFLOW_COUNTERBLOCK_HOST_CPU 2003
#define SFLOW_COUNTERBLOCK_HOST_MEM 2004
#define SFLOW_COUNTERBLOCK_HOST_DSK 2005
#define SFLOW_COUNTERBLOCK_HOST_NIO 2006
#define SFLOW_COUNTERBLOCK_HOST_VNODE 2100
#define SFLOW_COUNTERBLOCK_HOST_VCPU 2101
#define SFLOW_COUNTERBLOCK_HOST_VMEM 2102
#define SFLOW_COUNTERBLOCK_HOST_VDSK 2103
#define SFLOW_COUNTERBLOCK_HOST_VNIO 2104
#ifdef SFLOW_MEMCACHE_2200
#define SFLOW_COUNTERBLOCK_MEMCACHE_2200 2200
#endif
#define SFLOW_COUNTERBLOCK_MEMCACHE 2204
#define SFLOW_COUNTERBLOCK_HTTP 2201
#define SFLOW_COUNTERBLOCK_JVM 2106
#define SFLOW_COUNTERBLOCK_NVML_GPU ((5703 << 12) + 1)  /* enterprise 5703 == Nvidia */
#define SFLOW_COUNTERBLOCK_WORKERS 2206

#define SFLOW_MAX_HOSTNAME_LEN 64
#define SFLOW_MAX_FQDN_LEN 256
#define SFLOW_MAX_IPSTR_LEN 64
#define SFLOW_MAX_SPOOFHOST_LEN SFLOW_MAX_IPSTR_LEN + SFLOW_MAX_HOSTNAME_LEN + 2
#define SFLOW_MAX_OSRELEASE_LEN 32
#define SFLOW_MAX_UUIDSTR_LEN 37
#define SFLOW_MAX_INT32STR_LEN 10
#define SFLOW_MAX_DSI_LEN (SFLOW_MAX_IPSTR_LEN + SFLOW_MAX_INT32STR_LEN + 1 + SFLOW_MAX_INT32STR_LEN)

#define SFLOW_MAX_METRIC_NAME_LEN 512
#define SFLOW_MAX_METRIC_PREFIX_LEN 255

typedef struct _SFlowAddr {
  enum { SFLOW_ADDRTYPE_undefined=0, SFLOW_ADDRTYPE_IP4, SFLOW_ADDRTYPE_IP6 } type;
  union {
    uint32_t ip4;
    uint32_t ip6[4];
  } a;
} SFlowAddr;

typedef struct _SFlowXDR {
  /* cursor */
  uint32_t *datap;
  uint32_t i;
  uint32_t quads;
  /* timestamp */
  apr_time_t now;
  /* agent */
  SFlowAddr agentAddr;
  char agentipstr[SFLOW_MAX_IPSTR_LEN];
  uint32_t subAgentId;
  uint32_t uptime_mS;
  /* socket address */
  apr_sockaddr_t *remotesa;
  /* datasource */
  uint32_t dsClass;
  uint32_t dsIndex;
  /* sequence numbers */
  uint32_t datagramSeqNo;
  uint32_t csSeqNo;
  /* delta accumulation control */
  bool_t counterDeltas;
  /* structure offsets */
  struct {
    uint32_t HID;
    uint32_t CPU;
    uint32_t MEM;
    uint32_t DSK;
    uint32_t NIO;
    uint32_t VNODE;
    uint32_t VCPU;
    uint32_t VMEM;
    uint32_t VDSK;
    uint32_t VNIO;
    uint32_t foundPH;
    uint32_t foundVM;
#ifdef SFLOW_MEMCACHE_2200
    uint32_t MEMCACHE_2200;
#endif
    uint32_t MEMCACHE;
    uint32_t HTTP;
    uint32_t JVM;
    uint32_t NVML_GPU;
    uint32_t WORKERS;
  } offset;
} SFlowXDR;

#define SFLOWXDR_init(x,buf,len) do {  x->datap = (uint32_t *)buf; x->quads = (len >> 2); } while(0)
#define SFLOWXDR_next(x) ntohl(x->datap[x->i++])
#define SFLOWXDR_next_n(x) x->datap[x->i++]
#define SFLOWXDR_more(x,q) ((q + x->i) <= x->quads)
#define SFLOWXDR_skip(x,q) x->i += q
#define SFLOWXDR_skip_b(x,b) x->i += ((b+3)>>2)
#define SFLOWXDR_mark(x,q) x->i + q
#define SFLOWXDR_markOK(x,m) (m == x->i)
#define SFLOWXDR_off_b() (x->i << 2)
#define SFLOWXDR_setc(x,j) x->i = j
#define SFLOWXDR_str(x) (char *)(x->datap + x->i)
#define SFLOWXDR_next_float(x,pf) do { uint32_t tmp=SFLOWXDR_next(x); memcpy(pf, &tmp, 4); } while(0)
#define SFLOWXDR_next_int64(x,pi) do { (*pi) = SFLOWXDR_next(x); (*pi) <<= 32; (*pi) += SFLOWXDR_next(x); } while(0)

typedef struct _SFlowCounterState {
  /* CPU */
  uint32_t cpu_user;
  uint32_t cpu_nice;
  uint32_t cpu_system;
  uint32_t cpu_idle;
  uint32_t cpu_wio;
  uint32_t cpu_intr;
  uint32_t cpu_sintr;
  uint32_t interrupts;
  uint32_t contexts;

  /* memory */
  uint32_t page_in;
  uint32_t page_out;
  uint32_t swap_in;
  uint32_t swap_out;

  /* disk I/O */
  uint32_t reads;
  uint64_t bytes_read;
  uint32_t read_time;
  uint32_t writes;
  uint64_t bytes_written;
  uint32_t write_time;
  
  /* NetworkIO */
  uint64_t bytes_in;
  uint32_t pkts_in;
  uint32_t errs_in;
  uint32_t drops_in;
  uint64_t bytes_out;
  uint32_t pkts_out;
  uint32_t errs_out;
  uint32_t drops_out;

  /* VM CPU */
  uint32_t vcpu_mS;
  /* JVM CPU */
  uint32_t jvm_vcpu_mS;

  /* VM Disk */
  uint32_t vreads;
  uint64_t vbytes_read;
  uint32_t vwrites;
  uint64_t vbytes_written;
  uint32_t vdskerrs;
  
  /* VM NetworkIO */
  uint64_t vbytes_in;
  uint32_t vpkts_in;
  uint32_t verrs_in;
  uint32_t vdrops_in;
  uint64_t vbytes_out;
  uint32_t vpkts_out;
  uint32_t verrs_out;
  uint32_t vdrops_out;

  /* memcache */
  uint32_t mc_rusage_user;
  uint32_t mc_rusage_system;
  uint32_t mc_total_conns;
  uint32_t mc_cmd_get;
  uint32_t mc_cmd_set;
  uint32_t mc_cmd_flush;
  uint32_t mc_get_hits;
  uint32_t mc_get_misses;
  uint32_t mc_delete_misses;
  uint32_t mc_delete_hits;
  uint32_t mc_incr_misses;
  uint32_t mc_incr_hits;
  uint32_t mc_decr_misses;
  uint32_t mc_decr_hits;
  uint32_t mc_cas_misses;
  uint32_t mc_cas_hits;
  uint32_t mc_cas_badval;
  uint32_t mc_auth_cmds;
  uint32_t mc_auth_errors;
  uint32_t mc_bytes_read;
  uint32_t mc_bytes_written;
  uint32_t mc_conn_yields;
  uint32_t mc_bytes;
  uint32_t mc_total_items;
  uint32_t mc_evictions;
  uint32_t mc_cmd_touch;
  uint32_t mc_rejected_conns;
  uint32_t mc_reclaimed;

  /* HTTP */
  uint32_t http_meth_option;
  uint32_t http_meth_get;
  uint32_t http_meth_head;
  uint32_t http_meth_post;
  uint32_t http_meth_put;
  uint32_t http_meth_delete;
  uint32_t http_meth_trace;
  uint32_t http_meth_connect;
  uint32_t http_meth_other;
  uint32_t http_status_1XX;
  uint32_t http_status_2XX;
  uint32_t http_status_3XX;
  uint32_t http_status_4XX;
  uint32_t http_status_5XX;
  uint32_t http_status_other;
  /* HTTP workers */
  uint32_t http_workers_req_delayed;
  uint32_t http_workers_req_dropped;

  /* Java JVM */
  uint32_t jvm_thread_started;
  uint32_t jvm_gc_count;
  uint32_t jvm_gc_ms;
  uint32_t jvm_comp_ms;

  /* NVML GPU */
  uint32_t nvml_gpu_time;
  uint32_t nvml_gpu_rw_time;
  uint32_t nvml_gpu_ecc_errors;
  uint32_t nvml_gpu_energy;

} SFlowCounterState;


typedef struct _SFlowDataSource {
  struct _SFlowDataSource *nxt;
  uint32_t dsClass;
  uint32_t dsIndex;
  uint32_t csSeqNo;
  apr_time_t last_sample_time;
  /* strings */
  char *osrelease;
  char *uuidstr;
  char *hostname;
  /* counter state */
  SFlowCounterState counterState;
  /* cache metric_prefix string here */
  char *metric_prefix;
} SFlowDataSource;

typedef struct _SFlowSubAgent {
  struct _SFlowSubAgent *nxt;
  uint32_t subAgentId;
  uint32_t datagramSeqNo;
  SFlowDataSource *dataSources;
} SFlowSubAgent;

typedef struct _SFlowAgent {
  SFlowSubAgent *subAgents;
} SFlowAgent;

typedef enum {
#define SFLOW_GMETRIC(tag,mname,units,slope,format,group,desc,title) tag,
#include "sflow_gmetric.h"
#undef SFLOW_GMETRIC
  SFLOW_NUM_GMETRICS } EnumSFLOWGMetric;

typedef struct _SFLOWGMetric {
  EnumSFLOWGMetric tag;
  char *mname;
  char *units;
  ganglia_slope_t slope;
  char *format;
  char *group;
  char *desc;
  char *title;
} SFLOWGMetric;

static const SFLOWGMetric SFLOWGMetricTable[] = {
#define SFLOW_GMETRIC(tag,mname,units,slope,format,group,desc,title) {tag,mname,units,slope,format,group,desc,title},
#include "sflow_gmetric.h"
#undef SFLOW_GMETRIC
};

uint16_t init_sflow(cfg_t *config_file);
bool_t process_sflow_datagram(apr_sockaddr_t *remotesa, char *buf, apr_size_t len, apr_time_t now, char **errorMsg);


#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* SFLOW_H */