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
|
/*
* Copyright (c) 2013 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* Mark Goodwin <mgoodwin@redhat.com> May 2013.
*/
#include <ctype.h>
#include <pcp/pmapi.h>
#include <pcp/impl.h>
#include <pcp/pmda.h>
#include <pcp/import.h>
/* domains from stdpmid */
#define LINUX_DOMAIN 60
#define PROC_DOMAIN 3
/* Linux PMDA instance domain identifiers */
#include "../../pmdas/linux/indom.h"
/* PCP metric, see metrics.c */
typedef struct {
char *name;
pmDesc desc;
} metric_t;
/* parsed input buffer, split into fields. See fields_new() et al */
typedef struct {
int len;
char *buf;
int nfields;
char **fields;
int *fieldlen;
} fields_t;
/* handler to convert parsed fields into pcp metrics and emit them */
typedef struct handler {
char *pattern;
int (*handler)(struct handler *h, fields_t *f);
char *metric_name;
} handler_t;
/* global options */
extern int vflag;
extern int kernel_all_hz;
extern int utc_offset;
/* metric table, see metrics.c (generated from pmdesc) */
extern metric_t metrics[];
/* instance domain count table - needed for dynamic instances */
extern int indom_cnt[NUM_INDOMS];
/* metric value handler table */
extern handler_t handlers[];
/* handlers */
extern int header_handler(FILE *fp, char *fname, char *buf, int buflen);
extern int timestamp_flush(void);
extern int timestamp_handler(handler_t *h, fields_t *f);
extern int cpu_handler(handler_t *h, fields_t *f);
extern int proc_handler(handler_t *h, fields_t *f);
extern int disk_handler(handler_t *h, fields_t *f);
extern int net_handler(handler_t *h, fields_t *f);
extern int loadavg_handler(handler_t *h, fields_t *f);
extern int generic1_handler(handler_t *h, fields_t *f);
extern int generic2_handler(handler_t *h, fields_t *f);
/* various helpers, see util.c */
extern metric_t *find_metric(char *name);
extern handler_t *find_handler(char *buf);
extern int put_str_instance(pmInDom indom, char *instance);
extern int put_str_value(char *name, pmInDom indom, char *instance, char *val);
extern int put_int_value(char *name, pmInDom indom, char *instance, int val);
extern int put_ull_value(char *name, pmInDom indom, char *instance, unsigned long long val);
/* helpers to parse and manage input buffers */
extern int strfields(const char *s, int len, char **fields, int *fieldlen, int maxfields);
extern fields_t *fields_new(const char *s, int len);
extern fields_t *fields_dup(fields_t *f);
extern void fields_free(fields_t *f);
|