pcp_easy 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/ext/pcp_easy/agent.h DELETED
@@ -1,26 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Ryan Doyle
3
- *
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- *
17
- */
18
-
19
- #ifndef PCP_EASY_RUBY_AGENT_H
20
- #define PCP_EASY_RUBY_AGENT_H 1
21
-
22
- #include <ruby.h>
23
-
24
- void pcpeasy_agent_init(VALUE rb_cPCPEasy);
25
-
26
- #endif
@@ -1,213 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Ryan Doyle
3
- *
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- *
17
- */
18
-
19
- #include "exceptions.h"
20
-
21
- #include <ruby.h>
22
- #include <pcp/pmapi.h>
23
-
24
- /* Error classes */
25
- VALUE pcpeasy_error = Qnil;
26
- VALUE pcpeasy_pmns_error = Qnil;
27
- VALUE pcpeasy_no_pmns_error = Qnil;
28
- VALUE pcpeasy_dup_pmns_error = Qnil;
29
- VALUE pcpeasy_text_error = Qnil;
30
- VALUE pcpeasy_app_version_error = Qnil;
31
- VALUE pcpeasy_value_error = Qnil;
32
- VALUE pcpeasy_timeout_error = Qnil;
33
- VALUE pcpeasy_no_data_error = Qnil;
34
- VALUE pcpeasy_reset_error = Qnil;
35
- VALUE pcpeasy_name_error = Qnil;
36
- VALUE pcpeasy_pmid_error = Qnil;
37
- VALUE pcpeasy_indom_error = Qnil;
38
- VALUE pcpeasy_inst_error = Qnil;
39
- VALUE pcpeasy_unit_error = Qnil;
40
- VALUE pcpeasy_conv_error = Qnil;
41
- VALUE pcpeasy_trunc_error = Qnil;
42
- VALUE pcpeasy_sign_error = Qnil;
43
- VALUE pcpeasy_profile_error = Qnil;
44
- VALUE pcpeasy_ipc_error = Qnil;
45
- VALUE pcpeasy_eof_error = Qnil;
46
- VALUE pcpeasy_not_host_error = Qnil;
47
- VALUE pcpeasy_eol_error = Qnil;
48
- VALUE pcpeasy_mode_error = Qnil;
49
- VALUE pcpeasy_label_error = Qnil;
50
- VALUE pcpeasy_log_rec_error = Qnil;
51
- VALUE pcpeasy_not_archive_error = Qnil;
52
- VALUE pcpeasy_log_file_error = Qnil;
53
- VALUE pcpeasy_no_context_error = Qnil;
54
- VALUE pcpeasy_profile_spec_error = Qnil;
55
- VALUE pcpeasy_pmid_log_error = Qnil;
56
- VALUE pcpeasy_indom_log_error = Qnil;
57
- VALUE pcpeasy_inst_log_error = Qnil;
58
- VALUE pcpeasy_no_profile_error = Qnil;
59
- VALUE pcpeasy_no_agent_error = Qnil;
60
- VALUE pcpeasy_permission_error = Qnil;
61
- VALUE pcpeasy_connlimit_error = Qnil;
62
- VALUE pcpeasy_again_error = Qnil;
63
- VALUE pcpeasy_is_conn_error = Qnil;
64
- VALUE pcpeasy_not_conn_error = Qnil;
65
- VALUE pcpeasy_need_port_error = Qnil;
66
- VALUE pcpeasy_non_leaf_error = Qnil;
67
- VALUE pcpeasy_type_error = Qnil;
68
- VALUE pcpeasy_thread_error = Qnil;
69
- VALUE pcpeasy_no_container_error = Qnil;
70
- VALUE pcpeasy_bad_store_error = Qnil;
71
- VALUE pcpeasy_too_small_error = Qnil;
72
- VALUE pcpeasy_too_big_error = Qnil;
73
- VALUE pcpeasy_fault_error = Qnil;
74
- VALUE pcpeasy_pmda_ready_error = Qnil;
75
- VALUE pcpeasy_pmda_not_ready_error = Qnil;
76
- VALUE pcpeasy_nyi_error = Qnil;
77
-
78
-
79
- static const struct pmapi_to_ruby_exception {
80
- int pmapi_error;
81
- VALUE *ruby_exception;
82
- } pmapi_to_ruby_exception_map[] = {
83
- {PM_ERR_GENERIC, &pcpeasy_error},
84
- {PM_ERR_PMNS, &pcpeasy_pmns_error},
85
- {PM_ERR_NOPMNS, &pcpeasy_no_pmns_error},
86
- {PM_ERR_DUPPMNS, &pcpeasy_dup_pmns_error},
87
- {PM_ERR_TEXT, &pcpeasy_text_error},
88
- {PM_ERR_APPVERSION, &pcpeasy_app_version_error},
89
- {PM_ERR_VALUE, &pcpeasy_value_error},
90
- {PM_ERR_TIMEOUT, &pcpeasy_timeout_error},
91
- {PM_ERR_NODATA, &pcpeasy_no_data_error},
92
- {PM_ERR_RESET, &pcpeasy_reset_error},
93
- {PM_ERR_NAME, &pcpeasy_name_error},
94
- {PM_ERR_PMID, &pcpeasy_pmid_error},
95
- {PM_ERR_INDOM, &pcpeasy_indom_error},
96
- {PM_ERR_INST, &pcpeasy_inst_error},
97
- {PM_ERR_UNIT, &pcpeasy_unit_error},
98
- {PM_ERR_CONV, &pcpeasy_conv_error},
99
- {PM_ERR_TRUNC, &pcpeasy_trunc_error},
100
- {PM_ERR_SIGN, &pcpeasy_sign_error},
101
- {PM_ERR_PROFILE, &pcpeasy_profile_error},
102
- {PM_ERR_IPC, &pcpeasy_ipc_error},
103
- {PM_ERR_EOF, &pcpeasy_eof_error},
104
- {PM_ERR_NOTHOST, &pcpeasy_not_host_error},
105
- {PM_ERR_EOL, &pcpeasy_eol_error},
106
- {PM_ERR_MODE, &pcpeasy_mode_error},
107
- {PM_ERR_LABEL, &pcpeasy_label_error},
108
- {PM_ERR_LOGREC, &pcpeasy_log_rec_error},
109
- {PM_ERR_NOTARCHIVE, &pcpeasy_not_archive_error},
110
- {PM_ERR_LOGFILE, &pcpeasy_log_file_error},
111
- {PM_ERR_NOCONTEXT, &pcpeasy_no_context_error},
112
- {PM_ERR_PROFILESPEC, &pcpeasy_profile_spec_error},
113
- {PM_ERR_PMID_LOG, &pcpeasy_pmid_log_error},
114
- {PM_ERR_INDOM_LOG, &pcpeasy_indom_log_error},
115
- {PM_ERR_INST_LOG, &pcpeasy_inst_log_error},
116
- {PM_ERR_NOPROFILE, &pcpeasy_no_profile_error},
117
- {PM_ERR_NOAGENT, &pcpeasy_no_agent_error},
118
- {PM_ERR_PERMISSION, &pcpeasy_permission_error},
119
- {PM_ERR_CONNLIMIT, &pcpeasy_connlimit_error},
120
- {PM_ERR_AGAIN, &pcpeasy_again_error},
121
- {PM_ERR_ISCONN, &pcpeasy_is_conn_error},
122
- {PM_ERR_NOTCONN, &pcpeasy_not_conn_error},
123
- {PM_ERR_NEEDPORT, &pcpeasy_need_port_error},
124
- {PM_ERR_NONLEAF, &pcpeasy_non_leaf_error},
125
- {PM_ERR_TYPE, &pcpeasy_type_error},
126
- {PM_ERR_THREAD, &pcpeasy_thread_error},
127
- {PM_ERR_NOCONTAINER, &pcpeasy_no_container_error},
128
- {PM_ERR_BADSTORE, &pcpeasy_bad_store_error},
129
- {PM_ERR_TOOSMALL, &pcpeasy_too_small_error},
130
- {PM_ERR_TOOBIG, &pcpeasy_too_big_error},
131
- {PM_ERR_FAULT, &pcpeasy_fault_error},
132
- {PM_ERR_PMDAREADY, &pcpeasy_pmda_ready_error},
133
- {PM_ERR_PMDANOTREADY, &pcpeasy_pmda_not_ready_error},
134
- {PM_ERR_NYI, &pcpeasy_nyi_error},
135
- };
136
-
137
- static VALUE get_exception_from_pmapi_error_code(int error_code) {
138
- int i, number_of_pmapi_to_ruby_errors;
139
- number_of_pmapi_to_ruby_errors = sizeof(pmapi_to_ruby_exception_map) / sizeof(struct pmapi_to_ruby_exception);
140
-
141
- for(i=0; i < number_of_pmapi_to_ruby_errors; i++) {
142
- if(pmapi_to_ruby_exception_map[i].pmapi_error == error_code) {
143
- return *pmapi_to_ruby_exception_map[i].ruby_exception;
144
- }
145
- }
146
- /* Default to a generic error */
147
- return pcpeasy_error;
148
- }
149
-
150
- void pcpeasy_raise_from_pmapi_error(int error_number) {
151
- char errmsg[PM_MAXERRMSGLEN];
152
- VALUE exception_to_raise;
153
-
154
- exception_to_raise = get_exception_from_pmapi_error_code(error_number);
155
-
156
- rb_raise(exception_to_raise, (const char *)pmErrStr_r(error_number, (char *)&errmsg, sizeof(errmsg)));
157
- }
158
-
159
-
160
- void pcpeasy_exceptions_init(VALUE rb_cPCPEasy) {
161
- pcpeasy_error = rb_define_class_under(rb_cPCPEasy, "Error", rb_eStandardError);
162
- pcpeasy_pmns_error = rb_define_class_under(rb_cPCPEasy, "PMNSError", pcpeasy_error);
163
- pcpeasy_no_pmns_error = rb_define_class_under(rb_cPCPEasy, "NoPMNSError", pcpeasy_error);
164
- pcpeasy_dup_pmns_error = rb_define_class_under(rb_cPCPEasy, "DupPMNSError", pcpeasy_error);
165
- pcpeasy_text_error = rb_define_class_under(rb_cPCPEasy, "TextError", pcpeasy_error);
166
- pcpeasy_app_version_error = rb_define_class_under(rb_cPCPEasy, "AppVersionError", pcpeasy_error);
167
- pcpeasy_value_error = rb_define_class_under(rb_cPCPEasy, "ValueError", pcpeasy_error);
168
- pcpeasy_timeout_error = rb_define_class_under(rb_cPCPEasy, "TimeoutError", pcpeasy_error);
169
- pcpeasy_no_data_error = rb_define_class_under(rb_cPCPEasy, "NoDataError", pcpeasy_error);
170
- pcpeasy_reset_error = rb_define_class_under(rb_cPCPEasy, "ResetError", pcpeasy_error);
171
- pcpeasy_name_error = rb_define_class_under(rb_cPCPEasy, "NameError", pcpeasy_error);
172
- pcpeasy_pmid_error = rb_define_class_under(rb_cPCPEasy, "PMIDError", pcpeasy_error);
173
- pcpeasy_indom_error = rb_define_class_under(rb_cPCPEasy, "InDomError", pcpeasy_error);
174
- pcpeasy_inst_error = rb_define_class_under(rb_cPCPEasy, "InstError", pcpeasy_error);
175
- pcpeasy_unit_error = rb_define_class_under(rb_cPCPEasy, "UnitError", pcpeasy_error);
176
- pcpeasy_conv_error = rb_define_class_under(rb_cPCPEasy, "ConvError", pcpeasy_error);
177
- pcpeasy_trunc_error = rb_define_class_under(rb_cPCPEasy, "TruncError", pcpeasy_error);
178
- pcpeasy_sign_error = rb_define_class_under(rb_cPCPEasy, "SignError", pcpeasy_error);
179
- pcpeasy_profile_error = rb_define_class_under(rb_cPCPEasy, "ProfileError", pcpeasy_error);
180
- pcpeasy_ipc_error = rb_define_class_under(rb_cPCPEasy, "IPCError", pcpeasy_error);
181
- pcpeasy_eof_error = rb_define_class_under(rb_cPCPEasy, "EOFError", pcpeasy_error);
182
- pcpeasy_not_host_error = rb_define_class_under(rb_cPCPEasy, "NotHostError", pcpeasy_error);
183
- pcpeasy_eol_error = rb_define_class_under(rb_cPCPEasy, "EOLError", pcpeasy_error);
184
- pcpeasy_mode_error = rb_define_class_under(rb_cPCPEasy, "ModeError", pcpeasy_error);
185
- pcpeasy_label_error = rb_define_class_under(rb_cPCPEasy, "LabelError", pcpeasy_error);
186
- pcpeasy_log_rec_error = rb_define_class_under(rb_cPCPEasy, "LogRecError", pcpeasy_error);
187
- pcpeasy_not_archive_error = rb_define_class_under(rb_cPCPEasy, "NotArchiveError", pcpeasy_error);
188
- pcpeasy_log_file_error = rb_define_class_under(rb_cPCPEasy, "LogFileError", pcpeasy_error);
189
- pcpeasy_no_context_error = rb_define_class_under(rb_cPCPEasy, "NoContextError", pcpeasy_error);
190
- pcpeasy_profile_spec_error = rb_define_class_under(rb_cPCPEasy, "ProfileSpecError", pcpeasy_error);
191
- pcpeasy_pmid_log_error = rb_define_class_under(rb_cPCPEasy, "PMIDLogError", pcpeasy_error);
192
- pcpeasy_indom_log_error = rb_define_class_under(rb_cPCPEasy, "InDomLogError", pcpeasy_error);
193
- pcpeasy_inst_log_error = rb_define_class_under(rb_cPCPEasy, "InstLogError", pcpeasy_error);
194
- pcpeasy_no_profile_error = rb_define_class_under(rb_cPCPEasy, "NoProfileError", pcpeasy_error);
195
- pcpeasy_no_agent_error = rb_define_class_under(rb_cPCPEasy, "NoAgentError", pcpeasy_error);
196
- pcpeasy_permission_error = rb_define_class_under(rb_cPCPEasy, "PermissionError", pcpeasy_error);
197
- pcpeasy_connlimit_error = rb_define_class_under(rb_cPCPEasy, "ConnLimitError", pcpeasy_error);
198
- pcpeasy_again_error = rb_define_class_under(rb_cPCPEasy, "AgainError", pcpeasy_error);
199
- pcpeasy_is_conn_error = rb_define_class_under(rb_cPCPEasy, "IsConnError", pcpeasy_error);
200
- pcpeasy_not_conn_error = rb_define_class_under(rb_cPCPEasy, "NotConnError", pcpeasy_error);
201
- pcpeasy_need_port_error = rb_define_class_under(rb_cPCPEasy, "NeedPortError", pcpeasy_error);
202
- pcpeasy_non_leaf_error = rb_define_class_under(rb_cPCPEasy, "NonLeafError", pcpeasy_error);
203
- pcpeasy_type_error = rb_define_class_under(rb_cPCPEasy, "TypeError", pcpeasy_error);
204
- pcpeasy_thread_error = rb_define_class_under(rb_cPCPEasy, "ThreadError", pcpeasy_error);
205
- pcpeasy_no_container_error = rb_define_class_under(rb_cPCPEasy, "NoContainerError", pcpeasy_error);
206
- pcpeasy_bad_store_error = rb_define_class_under(rb_cPCPEasy, "BadStoreError", pcpeasy_error);
207
- pcpeasy_too_small_error = rb_define_class_under(rb_cPCPEasy, "TooSmallError", pcpeasy_error);
208
- pcpeasy_too_big_error = rb_define_class_under(rb_cPCPEasy, "TooBigError", pcpeasy_error);
209
- pcpeasy_fault_error = rb_define_class_under(rb_cPCPEasy, "FaultError", pcpeasy_error);
210
- pcpeasy_pmda_ready_error = rb_define_class_under(rb_cPCPEasy, "PMDAReadyError", pcpeasy_error);
211
- pcpeasy_pmda_not_ready_error = rb_define_class_under(rb_cPCPEasy, "PMDANotReadyError", pcpeasy_error);
212
- pcpeasy_nyi_error = rb_define_class_under(rb_cPCPEasy, "NYIError", pcpeasy_error);
213
- }
@@ -1,27 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Ryan Doyle
3
- *
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- *
17
- */
18
-
19
- #ifndef PCPEASY_RUBY_EXCEPTIONS_H
20
- #define PCPEASY_RUBY_EXCEPTIONS_H 1
21
-
22
- #include <ruby.h>
23
- extern VALUE pcpeasy_error;
24
- void pcpeasy_exceptions_init(VALUE rb_cPCPEasy);
25
- void pcpeasy_raise_from_pmapi_error(int error_number);
26
-
27
- #endif
@@ -1,5 +0,0 @@
1
- require 'mkmf'
2
- extension_name = 'pcp_easy'
3
- asplode('pcp') unless find_library('pcp', 'pmNewContext')
4
- dir_config(extension_name)
5
- create_makefile(extension_name)
@@ -1,273 +0,0 @@
1
- /*
2
- * Copyright (C) 2016 Ryan Doyle
3
- *
4
- * This program is free software: you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License as published by
6
- * the Free Software Foundation, either version 3 of the License, or
7
- * (at your option) any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
16
- *
17
- */
18
-
19
- #include <ruby.h>
20
- #include <pcp/pmapi.h>
21
-
22
- #include "exceptions.h"
23
- #include "metric_value.h"
24
-
25
- #define READ_ONLY 1, 0
26
- #define CONSTRUCTOR_ARGS 5
27
- #define rb_symbol_new(name) ID2SYM(rb_intern(name))
28
-
29
- VALUE pcpeasy_metric_class;
30
-
31
- static VALUE initialize(VALUE self, VALUE name, VALUE values, VALUE semantics, VALUE type, VALUE units) {
32
- rb_iv_set(self, "@name", name);
33
- rb_iv_set(self, "@values", values);
34
- rb_iv_set(self, "@semantics", semantics);
35
- rb_iv_set(self, "@type", type);
36
- rb_iv_set(self, "@units", units);
37
-
38
- return self;
39
- }
40
-
41
- static VALUE semantics_symbol(int semantics) {
42
- switch(semantics) {
43
- case PM_SEM_COUNTER:
44
- return rb_symbol_new("counter");
45
- case PM_SEM_DISCRETE:
46
- return rb_symbol_new("discrete");
47
- case PM_SEM_INSTANT:
48
- return rb_symbol_new("instant");
49
- default:
50
- return Qnil;
51
- }
52
- }
53
-
54
- static int is_field_equal(const char *name, VALUE self, VALUE other) {
55
- return TYPE(rb_funcall(rb_iv_get(self, name), rb_intern("=="), 1, rb_iv_get(other, name))) == T_TRUE;
56
- }
57
-
58
- static VALUE equal(VALUE self, VALUE other) {
59
- if(rb_class_of(other) != pcpeasy_metric_class)
60
- return Qfalse;
61
- if(!is_field_equal("@name", self, other))
62
- return Qfalse;
63
- if(!is_field_equal("@values", self, other))
64
- return Qfalse;
65
- if(!is_field_equal("@semantics", self, other))
66
- return Qfalse;
67
- if(!is_field_equal("@type", self, other))
68
- return Qfalse;
69
- if(!is_field_equal("@units", self, other))
70
- return Qfalse;
71
-
72
- return Qtrue;
73
- }
74
-
75
- static VALUE type(int type) {
76
- switch(type) {
77
- case PM_TYPE_32:
78
- return rb_symbol_new("int32");
79
- case PM_TYPE_U32:
80
- return rb_symbol_new("uint32");
81
- case PM_TYPE_64:
82
- return rb_symbol_new("int64");
83
- case PM_TYPE_U64:
84
- return rb_symbol_new("uint64");
85
- case PM_TYPE_FLOAT:
86
- return rb_symbol_new("float");
87
- case PM_TYPE_DOUBLE:
88
- return rb_symbol_new("double");
89
- case PM_TYPE_STRING:
90
- return rb_symbol_new("string");
91
- case PM_TYPE_AGGREGATE:
92
- return rb_symbol_new("aggregate");
93
- case PM_TYPE_AGGREGATE_STATIC:
94
- return rb_symbol_new("aggregate_static");
95
- case PM_TYPE_EVENT:
96
- return rb_symbol_new("event");
97
- case PM_TYPE_HIGHRES_EVENT:
98
- return rb_symbol_new("highres_event");
99
- case PM_TYPE_NOSUPPORT:
100
- return rb_symbol_new("nosupport");
101
- case PM_TYPE_UNKNOWN:
102
- default:
103
- return rb_symbol_new("unknown");
104
- }
105
- }
106
-
107
- static VALUE units(pmUnits pm_units) {
108
- VALUE units = rb_hash_new();
109
- VALUE dimension = Qnil;
110
-
111
- if(pm_units.dimSpace == 1 && pm_units.dimTime == 0 && pm_units.dimCount == 0)
112
- dimension = rb_symbol_new("space");
113
- if(pm_units.dimSpace == 1 && pm_units.dimTime == -1 && pm_units.dimCount == 0)
114
- dimension = rb_symbol_new("space_time");
115
- if(pm_units.dimSpace == 1 && pm_units.dimTime == 0 && pm_units.dimCount == -1)
116
- dimension = rb_symbol_new("space_count");
117
- if(pm_units.dimSpace == 0 && pm_units.dimTime == 1 && pm_units.dimCount == 0)
118
- dimension = rb_symbol_new("time");
119
- if(pm_units.dimSpace == -1 && pm_units.dimTime == 1 && pm_units.dimCount == 0)
120
- dimension = rb_symbol_new("time_space");
121
- if(pm_units.dimSpace == 0 && pm_units.dimTime == 1 && pm_units.dimCount == -1)
122
- dimension = rb_symbol_new("time_count");
123
- if(pm_units.dimSpace == 0 && pm_units.dimTime == 0 && pm_units.dimCount == 1)
124
- dimension = rb_symbol_new("count");
125
- if(pm_units.dimSpace == -1 && pm_units.dimTime == 0 && pm_units.dimCount == 1)
126
- dimension = rb_symbol_new("count_space");
127
- if(pm_units.dimSpace == 0 && pm_units.dimTime == -1 && pm_units.dimCount == 1)
128
- dimension = rb_symbol_new("count_time");
129
-
130
- rb_hash_aset(units, rb_symbol_new("dimension"), dimension);
131
-
132
- if(pm_units.dimSpace != 0) {
133
- VALUE scale_space;
134
- switch(pm_units.scaleSpace) {
135
- case PM_SPACE_BYTE:
136
- scale_space = rb_symbol_new("bytes");
137
- break;
138
- case PM_SPACE_KBYTE:
139
- scale_space = rb_symbol_new("kilobytes");
140
- break;
141
- case PM_SPACE_MBYTE:
142
- scale_space = rb_symbol_new("megabytes");
143
- break;
144
- case PM_SPACE_GBYTE:
145
- scale_space = rb_symbol_new("gigabytes");
146
- break;
147
- case PM_SPACE_TBYTE:
148
- scale_space = rb_symbol_new("terabytes");
149
- break;
150
- case PM_SPACE_PBYTE:
151
- scale_space = rb_symbol_new("petabytes");
152
- break;
153
- case PM_SPACE_EBYTE:
154
- scale_space = rb_symbol_new("exabytes");
155
- break;
156
- default:
157
- scale_space = Qnil;
158
- }
159
- rb_hash_aset(units, rb_symbol_new("space"), scale_space);
160
- }
161
-
162
- if(pm_units.dimTime != 0) {
163
- VALUE scale_time;
164
- switch(pm_units.scaleTime) {
165
- case PM_TIME_NSEC:
166
- scale_time = rb_symbol_new("nanoseconds");
167
- break;
168
- case PM_TIME_USEC:
169
- scale_time = rb_symbol_new("microseconds");
170
- break;
171
- case PM_TIME_MSEC:
172
- scale_time = rb_symbol_new("milliseconds");
173
- break;
174
- case PM_TIME_SEC:
175
- scale_time = rb_symbol_new("seconds");
176
- break;
177
- case PM_TIME_MIN:
178
- scale_time = rb_symbol_new("minutes");
179
- break;
180
- case PM_TIME_HOUR:
181
- scale_time = rb_symbol_new("hour");
182
- break;
183
- default:
184
- scale_time = Qnil;
185
- }
186
- rb_hash_aset(units, rb_symbol_new("time"), scale_time);
187
- }
188
-
189
- if(pm_units.dimCount != 0) {
190
- rb_hash_aset(units, rb_symbol_new("count_scaling"), INT2NUM(pm_units.scaleCount));
191
- }
192
-
193
- return units;
194
- }
195
-
196
-
197
- static char* get_name_from_instance_id(int instance_id, int maximum_instances, int *instance_ids, char **instance_names) {
198
- int i;
199
- for(i=0; i<maximum_instances; i++) {
200
- if(instance_id == instance_ids[i]) {
201
- return instance_names[i];
202
- }
203
- }
204
- return NULL;
205
- }
206
-
207
- static VALUE build_metric_values_for_multiple_instances(pmValueSet *pm_value_set, pmDesc pm_desc) {
208
- int error, i;
209
- int number_of_instances = pm_value_set->numval;
210
- int *instances = NULL;
211
- char **instance_names = NULL;
212
- VALUE result = rb_ary_new2(number_of_instances);
213
-
214
-
215
- if((error = pmGetInDom(pm_desc.indom, &instances, &instance_names)) < 0) {
216
- pcpeasy_raise_from_pmapi_error(error);
217
- }
218
-
219
- for(i = 0; i < number_of_instances; i++) {
220
- char *instance_name = get_name_from_instance_id(pm_value_set->vlist[i].inst, number_of_instances, instances, instance_names);
221
- rb_ary_push(result, pcpeasy_metric_value_new(instance_name, pm_value_set->valfmt, &pm_value_set->vlist[i], pm_desc.type));
222
- }
223
-
224
- free(instances);
225
- free(instance_names);
226
-
227
- return result;
228
- }
229
-
230
- static VALUE build_metrics_values(pmValueSet *pm_value_set, pmDesc pm_desc) {
231
- VALUE result = rb_ary_new2(pm_value_set->numval);
232
-
233
- if(pm_value_set->numval > 0) {
234
- if (pm_desc.indom != PM_INDOM_NULL) {
235
- rb_ary_concat(result, build_metric_values_for_multiple_instances(pm_value_set, pm_desc));
236
- } else {
237
- return rb_ary_push(result, pcpeasy_metric_value_new(NULL, pm_value_set->valfmt, &pm_value_set->vlist[0], pm_desc.type));
238
- }
239
- }
240
- return result;
241
- }
242
-
243
- VALUE pcpeasy_metric_new(char *metric_name, pmValueSet *pm_value_set) {
244
- VALUE args[CONSTRUCTOR_ARGS];
245
- int error;
246
- pmDesc pm_desc;
247
-
248
- /* Find out how to decode the metric */
249
- if((error = pmLookupDesc(pm_value_set->pmid, &pm_desc))) {
250
- pcpeasy_raise_from_pmapi_error(error);
251
- }
252
-
253
- args[0] = rb_tainted_str_new_cstr(metric_name);
254
- args[1] = build_metrics_values(pm_value_set, pm_desc);
255
- args[2] = semantics_symbol(pm_desc.sem);
256
- args[3] = type(pm_desc.type);
257
- args[4] = units(pm_desc.units);
258
-
259
- return rb_class_new_instance(CONSTRUCTOR_ARGS, args, pcpeasy_metric_class);
260
- }
261
-
262
- void pcpeasy_metric_init(VALUE rb_cPCPEasy) {
263
- pcpeasy_metric_class = rb_define_class_under(rb_cPCPEasy, "Metric", rb_cObject);
264
- pcpeasy_metric_value_init(pcpeasy_metric_class);
265
-
266
- rb_define_method(pcpeasy_metric_class, "initialize", initialize, CONSTRUCTOR_ARGS);
267
- rb_define_method(pcpeasy_metric_class, "==", equal, 1);
268
- rb_define_attr(pcpeasy_metric_class, "name", READ_ONLY);
269
- rb_define_attr(pcpeasy_metric_class, "values", READ_ONLY);
270
- rb_define_attr(pcpeasy_metric_class, "semantics", READ_ONLY);
271
- rb_define_attr(pcpeasy_metric_class, "type", READ_ONLY);
272
- rb_define_attr(pcpeasy_metric_class, "units", READ_ONLY);
273
- }