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.
- checksums.yaml +4 -4
- data/lib/pcp_easy.rb +11 -0
- data/lib/pcp_easy/agent.rb +58 -0
- data/lib/pcp_easy/error.rb +120 -0
- data/lib/pcp_easy/metric.rb +153 -0
- data/lib/pcp_easy/metric/value.rb +19 -0
- data/lib/pcp_easy/pmapi.rb +248 -0
- data/lib/pcp_easy/pmapi/pm_atom_value.rb +49 -0
- data/lib/pcp_easy/pmapi/pm_desc.rb +49 -0
- data/lib/pcp_easy/pmapi/pm_result.rb +36 -0
- data/lib/pcp_easy/pmapi/pm_units.rb +62 -0
- data/lib/pcp_easy/pmapi/pm_value.rb +34 -0
- data/lib/pcp_easy/pmapi/pm_value_set.rb +38 -0
- data/lib/pcp_easy/pmapi/timeval.rb +16 -0
- metadata +33 -17
- data/ext/pcp_easy/agent.c +0 -117
- data/ext/pcp_easy/agent.h +0 -26
- data/ext/pcp_easy/exceptions.c +0 -213
- data/ext/pcp_easy/exceptions.h +0 -27
- data/ext/pcp_easy/extconf.rb +0 -5
- data/ext/pcp_easy/metric.c +0 -273
- data/ext/pcp_easy/metric.h +0 -28
- data/ext/pcp_easy/metric_value.c +0 -102
- data/ext/pcp_easy/metric_value.h +0 -28
- data/ext/pcp_easy/pcp_easy.c +0 -34
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module PCPEasy
|
4
|
+
class PMAPI
|
5
|
+
class PmAtomValue < FFI::Union
|
6
|
+
layout :l, :int32,
|
7
|
+
:ul, :uint32,
|
8
|
+
:ll, :int64,
|
9
|
+
:ull, :uint64,
|
10
|
+
:f, :float,
|
11
|
+
:d, :double,
|
12
|
+
:cp, :pointer,
|
13
|
+
:vbp, :pointer
|
14
|
+
|
15
|
+
def l
|
16
|
+
self[:l]
|
17
|
+
end
|
18
|
+
|
19
|
+
def ul
|
20
|
+
self[:ul]
|
21
|
+
end
|
22
|
+
|
23
|
+
def ll
|
24
|
+
self[:ll]
|
25
|
+
end
|
26
|
+
|
27
|
+
def ull
|
28
|
+
self[:ull]
|
29
|
+
end
|
30
|
+
|
31
|
+
def f
|
32
|
+
self[:f]
|
33
|
+
end
|
34
|
+
|
35
|
+
def d
|
36
|
+
self[:d]
|
37
|
+
end
|
38
|
+
|
39
|
+
def cp
|
40
|
+
self[:cp]
|
41
|
+
end
|
42
|
+
|
43
|
+
def vbp
|
44
|
+
self[:vbp]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'pcp_easy/pmapi/pm_units'
|
3
|
+
|
4
|
+
module PCPEasy
|
5
|
+
class PMAPI
|
6
|
+
class PmDesc < FFI::Struct
|
7
|
+
layout :pmid, :uint,
|
8
|
+
:type, :int,
|
9
|
+
:indom, :uint,
|
10
|
+
:sem, :int,
|
11
|
+
:units, :uint32
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
"<#{self.class.to_s}:#{object_id} pmid=#{pmid} type=#{type} indom=#{indom} sem=#{sem} units=#{units.inspect}>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def pmid
|
18
|
+
self[:pmid]
|
19
|
+
end
|
20
|
+
|
21
|
+
def type
|
22
|
+
self[:type]
|
23
|
+
end
|
24
|
+
|
25
|
+
def indom
|
26
|
+
self[:indom]
|
27
|
+
end
|
28
|
+
|
29
|
+
def sem
|
30
|
+
self[:sem]
|
31
|
+
end
|
32
|
+
|
33
|
+
def units
|
34
|
+
@units ||= PmUnits.new(self[:units])
|
35
|
+
end
|
36
|
+
|
37
|
+
def ==(other)
|
38
|
+
self.class == other.class && \
|
39
|
+
pmid == other.pmid && \
|
40
|
+
type == other.type && \
|
41
|
+
indom == other.indom && \
|
42
|
+
sem == other.sem && \
|
43
|
+
units == other.units
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
require 'pcp_easy/pmapi/timeval'
|
4
|
+
require 'pcp_easy/pmapi/pm_value_set'
|
5
|
+
|
6
|
+
module PCPEasy
|
7
|
+
class PMAPI
|
8
|
+
class PmResult < FFI::Struct
|
9
|
+
layout :timestamp, Timeval,
|
10
|
+
:numpmid, :int,
|
11
|
+
:vset, :pointer
|
12
|
+
# pointer to start of PmValueSet
|
13
|
+
|
14
|
+
def vset
|
15
|
+
numpmid.times.collect do |n|
|
16
|
+
PmValueSet.new((start_of_vset + FFI::Pointer.size * n).get_pointer(0))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def numpmid
|
21
|
+
self[:numpmid]
|
22
|
+
end
|
23
|
+
|
24
|
+
def timestamp
|
25
|
+
self[:timestamp]
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def start_of_vset
|
31
|
+
pointer + (self.size - FFI::Pointer.size)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module PCPEasy
|
2
|
+
class PMAPI
|
3
|
+
class PmUnits
|
4
|
+
|
5
|
+
# Decodes a 32bit integer into the correct fields of pmUnits.
|
6
|
+
# This implementation assumes little-endian encoding
|
7
|
+
|
8
|
+
def initialize(pm_units)
|
9
|
+
@pm_units = pm_units
|
10
|
+
end
|
11
|
+
|
12
|
+
def dim_space
|
13
|
+
signed_4_bit(@pm_units >> 28)
|
14
|
+
end
|
15
|
+
|
16
|
+
def dim_time
|
17
|
+
signed_4_bit(@pm_units >> 24)
|
18
|
+
end
|
19
|
+
|
20
|
+
def dim_count
|
21
|
+
signed_4_bit(@pm_units >> 20)
|
22
|
+
end
|
23
|
+
|
24
|
+
def scale_space
|
25
|
+
unsigned_4_bit(@pm_units >> 16)
|
26
|
+
end
|
27
|
+
|
28
|
+
def scale_time
|
29
|
+
unsigned_4_bit(@pm_units >> 12)
|
30
|
+
end
|
31
|
+
|
32
|
+
def scale_count
|
33
|
+
signed_4_bit(@pm_units >> 8)
|
34
|
+
end
|
35
|
+
|
36
|
+
def inspect
|
37
|
+
"<#{self.class.to_s}:#{object_id} @pm_units=#{@pm_units} {#{dim_space},#{dim_time},#{dim_count},#{scale_space},#{scale_time},#{scale_count}}>"
|
38
|
+
end
|
39
|
+
|
40
|
+
def ==(other)
|
41
|
+
self.class == other.class && \
|
42
|
+
dim_space == other.dim_space && \
|
43
|
+
dim_time == other.dim_time && \
|
44
|
+
dim_count == other.dim_count && \
|
45
|
+
scale_space == other.scale_space && \
|
46
|
+
scale_time == other.scale_time && \
|
47
|
+
scale_count == other.scale_count
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def signed_4_bit(lowest_4_bits)
|
53
|
+
lowest_4_bits & 0x8 == 0 ? lowest_4_bits & 0xf : -((~lowest_4_bits & 0xf) + 1)
|
54
|
+
end
|
55
|
+
|
56
|
+
def unsigned_4_bit(lowest_4_bits)
|
57
|
+
lowest_4_bits & 0xf
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module PCPEasy
|
4
|
+
class PMAPI
|
5
|
+
|
6
|
+
class PmValueU < FFI::Union
|
7
|
+
layout :pval, :pointer,
|
8
|
+
:lval, :int
|
9
|
+
|
10
|
+
def pval
|
11
|
+
self[:pval]
|
12
|
+
end
|
13
|
+
|
14
|
+
def lval
|
15
|
+
self[:lval]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class PmValue < FFI::Struct
|
20
|
+
layout :inst, :int,
|
21
|
+
:value, PmValueU
|
22
|
+
def inst
|
23
|
+
self[:inst]
|
24
|
+
end
|
25
|
+
|
26
|
+
def value
|
27
|
+
self[:value]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
require 'pcp_easy/pmapi/pm_value'
|
3
|
+
|
4
|
+
module PCPEasy
|
5
|
+
class PMAPI
|
6
|
+
class PmValueSet < FFI::Struct
|
7
|
+
|
8
|
+
layout :pmid, :uint,
|
9
|
+
:numval, :int,
|
10
|
+
:valfmt, :int,
|
11
|
+
:vlist, PmValue
|
12
|
+
# Can have one or more PmValue
|
13
|
+
|
14
|
+
def vlist
|
15
|
+
@vlist ||= numval.times.collect {|n| PmValue.new(start_of_vlist + PmValue.size * n)}
|
16
|
+
end
|
17
|
+
|
18
|
+
def numval
|
19
|
+
self[:numval]
|
20
|
+
end
|
21
|
+
|
22
|
+
def pmid
|
23
|
+
self[:pmid]
|
24
|
+
end
|
25
|
+
|
26
|
+
def valfmt
|
27
|
+
self[:valfmt]
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def start_of_vlist
|
33
|
+
pointer + (self.size - PmValue.size)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ffi'
|
2
|
+
|
3
|
+
module PCPEasy
|
4
|
+
class PMAPI
|
5
|
+
class Timeval < FFI::Struct
|
6
|
+
layout :tv_sec, :long,
|
7
|
+
:tv_usec, :long
|
8
|
+
|
9
|
+
def ==(other)
|
10
|
+
self.class == other.class && \
|
11
|
+
self[:tv_sec] == other[:tv_sec] && \
|
12
|
+
self[:tv_usec] == other[:tv_usec]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pcp_easy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Doyle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: ffi
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
@@ -52,23 +52,39 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
executables: []
|
58
|
-
extensions:
|
59
|
-
- ext/pcp_easy/extconf.rb
|
72
|
+
extensions: []
|
60
73
|
extra_rdoc_files: []
|
61
74
|
files:
|
62
|
-
-
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
69
|
-
-
|
70
|
-
-
|
71
|
-
-
|
75
|
+
- lib/pcp_easy.rb
|
76
|
+
- lib/pcp_easy/agent.rb
|
77
|
+
- lib/pcp_easy/error.rb
|
78
|
+
- lib/pcp_easy/metric.rb
|
79
|
+
- lib/pcp_easy/metric/value.rb
|
80
|
+
- lib/pcp_easy/pmapi.rb
|
81
|
+
- lib/pcp_easy/pmapi/pm_atom_value.rb
|
82
|
+
- lib/pcp_easy/pmapi/pm_desc.rb
|
83
|
+
- lib/pcp_easy/pmapi/pm_result.rb
|
84
|
+
- lib/pcp_easy/pmapi/pm_units.rb
|
85
|
+
- lib/pcp_easy/pmapi/pm_value.rb
|
86
|
+
- lib/pcp_easy/pmapi/pm_value_set.rb
|
87
|
+
- lib/pcp_easy/pmapi/timeval.rb
|
72
88
|
homepage:
|
73
89
|
licenses: []
|
74
90
|
metadata: {}
|
@@ -88,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
104
|
version: '0'
|
89
105
|
requirements: []
|
90
106
|
rubyforge_project:
|
91
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.2.2
|
92
108
|
signing_key:
|
93
109
|
specification_version: 4
|
94
110
|
summary: Simple query interface for Performance Co-Pilot
|
data/ext/pcp_easy/agent.c
DELETED
@@ -1,117 +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.h"
|
24
|
-
|
25
|
-
VALUE pcpeasy_agent_class = Qnil;
|
26
|
-
|
27
|
-
|
28
|
-
typedef struct {
|
29
|
-
int pm_context;
|
30
|
-
} PcpEasyAgent;
|
31
|
-
|
32
|
-
static void deallocate(void *untyped_pcpeasy_agent) {
|
33
|
-
PcpEasyAgent *pcpqz_agent = (PcpEasyAgent*)untyped_pcpeasy_agent;
|
34
|
-
pmDestroyContext(pcpqz_agent->pm_context);
|
35
|
-
xfree(pcpqz_agent);
|
36
|
-
}
|
37
|
-
|
38
|
-
static VALUE allocate(VALUE self) {
|
39
|
-
PcpEasyAgent *pcpeasy_agent;
|
40
|
-
return Data_Make_Struct(self, PcpEasyAgent, 0, deallocate, pcpeasy_agent);
|
41
|
-
};
|
42
|
-
|
43
|
-
static VALUE initialize(VALUE self, VALUE hostname_rb) {
|
44
|
-
PcpEasyAgent *pcpeasy_agent;
|
45
|
-
const char *hostname;
|
46
|
-
int pm_context;
|
47
|
-
|
48
|
-
Data_Get_Struct(self, PcpEasyAgent, pcpeasy_agent);
|
49
|
-
hostname = StringValueCStr(hostname_rb);
|
50
|
-
|
51
|
-
if((pm_context = pmNewContext(PM_CONTEXT_HOST, hostname)) < 0) {
|
52
|
-
pcpeasy_raise_from_pmapi_error(pm_context);
|
53
|
-
}
|
54
|
-
|
55
|
-
rb_iv_set(self, "@host", hostname_rb);
|
56
|
-
|
57
|
-
/* Store away with this instance */
|
58
|
-
pcpeasy_agent->pm_context = pm_context;
|
59
|
-
|
60
|
-
return self;
|
61
|
-
}
|
62
|
-
|
63
|
-
static VALUE decode_pm_result(pmResult *pm_result, char *metric_name) {
|
64
|
-
/* No values (or somehow more than 1) */
|
65
|
-
if (pm_result->numpmid != 1) {
|
66
|
-
return Qnil;
|
67
|
-
}
|
68
|
-
|
69
|
-
return pcpeasy_metric_new(metric_name, pm_result->vset[0]);
|
70
|
-
}
|
71
|
-
|
72
|
-
static VALUE metric(VALUE self, VALUE metric_string_rb) {
|
73
|
-
/* Get our context */
|
74
|
-
PcpEasyAgent *pcpeasy_agent;
|
75
|
-
Data_Get_Struct(self, PcpEasyAgent, pcpeasy_agent);
|
76
|
-
pmUseContext(pcpeasy_agent->pm_context);
|
77
|
-
|
78
|
-
/* Get the pmID */
|
79
|
-
int error;
|
80
|
-
pmID pmid;
|
81
|
-
pmID *pmid_list = ALLOC(pmID);
|
82
|
-
char **metric_list = ALLOC(char*);
|
83
|
-
char *metric_name = StringValueCStr(metric_string_rb);
|
84
|
-
metric_list[0] = metric_name;
|
85
|
-
if((error = pmLookupName(1, metric_list, pmid_list)) < 0) {
|
86
|
-
xfree(pmid_list);
|
87
|
-
xfree(metric_list);
|
88
|
-
pcpeasy_raise_from_pmapi_error(error);
|
89
|
-
}
|
90
|
-
pmid = pmid_list[0];
|
91
|
-
xfree(pmid_list);
|
92
|
-
xfree(metric_list);
|
93
|
-
|
94
|
-
|
95
|
-
/* Do the fetch */
|
96
|
-
pmResult *pm_result;
|
97
|
-
VALUE result;
|
98
|
-
if((error = pmFetch(1, &pmid, &pm_result))) {
|
99
|
-
pcpeasy_raise_from_pmapi_error(error);
|
100
|
-
}
|
101
|
-
|
102
|
-
/* Decode the result */
|
103
|
-
result = decode_pm_result(pm_result, metric_name);
|
104
|
-
pmFreeResult(pm_result);
|
105
|
-
|
106
|
-
return result;
|
107
|
-
}
|
108
|
-
|
109
|
-
|
110
|
-
void pcpeasy_agent_init(VALUE rb_cPCPEasy) {
|
111
|
-
pcpeasy_agent_class = rb_define_class_under(rb_cPCPEasy, "Agent", rb_cObject);
|
112
|
-
|
113
|
-
rb_define_alloc_func(pcpeasy_agent_class, allocate);
|
114
|
-
rb_define_method(pcpeasy_agent_class, "initialize", initialize, 1);
|
115
|
-
rb_define_method(pcpeasy_agent_class, "metric", metric, 1);
|
116
|
-
rb_define_attr(pcpeasy_agent_class, "host", 1, 0);
|
117
|
-
}
|