Class: Fog::Google::Monitoring::Mock

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/fog/google/monitoring.rb,
lib/fog/google/requests/monitoring/list_timeseries.rb,
lib/fog/google/requests/monitoring/list_metric_descriptors.rb,
lib/fog/google/requests/monitoring/list_timeseries_descriptors.rb

Instance Attribute Summary

Attributes included from Shared

#api_url, #api_version, #project

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared

#build_excon_response, #create_signing_key, #initialize_google_client, #new_pk12_google_client, #request, #shared_initialize

Constructor Details

#initialize(options) ⇒ Mock

Returns a new instance of Mock.



46
47
48
# File 'lib/fog/google/monitoring.rb', line 46

def initialize(options)
  shared_initialize(options[:google_project], GOOGLE_MONITORING_API_VERSION, GOOGLE_MONITORING_BASE_URL)
end

Class Method Details

.dataObject



50
51
52
53
54
55
56
57
58
# File 'lib/fog/google/monitoring.rb', line 50

def self.data
  @data ||= Hash.new do |hash, key|
    hash[key] = {
      :timeseries => {},
      :timeseries_descriptors => {},
      :metric_descriptors => {},
    }
  end
end

.resetObject



60
61
62
# File 'lib/fog/google/monitoring.rb', line 60

def self.reset
  @data = nil
end

Instance Method Details

#dataObject



64
65
66
# File 'lib/fog/google/monitoring.rb', line 64

def data
  self.class.data[project]
end

#list_metric_descriptors(options = {}) ⇒ Object



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
# File 'lib/fog/google/requests/monitoring/list_metric_descriptors.rb', line 25

def list_metric_descriptors(options = {})
  body = {
    'kind' => 'cloudmonitoring#listMetricDescriptorsResponse',
    'metrics' => [
      { 'name' => 'compute.googleapis.com/instance/cpu/reserved_cores',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'gauge', 'valueType' => 'double' },
        'description' => 'Number of cores reserved on the host of the instance.'
      },
      {
        'name' => 'compute.googleapis.com/instance/cpu/usage_time',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'double' },
        'description' => 'Delta CPU usage time. Units are seconds. You can get the per-core CPU utilization ratio by performing a rate operation on a point: doubleValue/(end-start), then divide by compute.googleapis.com/instance/cpu/reserved_cores at the corresponding end timestamp.'
      },
      {
        'name' => 'compute.googleapis.com/instance/disk/read_bytes_count',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'compute.googleapis.com/device_name' },
          { 'key' => 'compute.googleapis.com/device_type' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'int64' },
        'description' => 'Delta count of bytes read from disk.'
      },
      {
        'name' => 'compute.googleapis.com/instance/disk/read_ops_count',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'compute.googleapis.com/device_name' },
          { 'key' => 'compute.googleapis.com/device_type' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'int64' },
        'description' => 'Delta count of disk read IO operations.'
      },
      {
        'name' => 'compute.googleapis.com/instance/disk/write_bytes_count',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'compute.googleapis.com/device_name' },
          { 'key' => 'compute.googleapis.com/device_type' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => '"compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'int64' },
        'description' => 'Delta count of bytes written to disk.'
      },
      {
        'name' => 'compute.googleapis.com/instance/disk/write_ops_count',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'compute.googleapis.com/device_name' },
          { 'key' => '"compute.googleapis.com/device_type' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'int64' },
        'description' => 'Delta count of disk write IO operations.'
      },
      {
        'name' => 'compute.googleapis.com/instance/network/received_bytes_count',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'compute.googleapis.com/loadbalanced' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'int64' },
        'description' => 'Delta count of bytes received from network.'
      },
      {
        'name' => 'compute.googleapis.com/instance/network/received_packets_count',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'compute.googleapis.com/loadbalanced' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'int64' },
        'description' => 'Delta count of packets received from network.'
      },
      {
        'name' => 'compute.googleapis.com/instance/network/sent_bytes_count',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'compute.googleapis.com/loadbalanced' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'int64' },
        'description' => 'Delta count of bytes sent over network.'
      },
      {
        'name' => 'compute.googleapis.com/instance/network/sent_packets_count',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'compute.googleapis.com/loadbalanced' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'int64' },
        'description' => 'Delta count of packets sent over network.'
      },
      {
        'name' => 'compute.googleapis.com/instance/uptime',
        'project' => @project,
        'labels' => [
          { 'key' => 'compute.googleapis.com/instance_name' },
          { 'key' => 'cloud.googleapis.com/location' },
          { 'key' => 'compute.googleapis.com/resource_id' },
          { 'key' => 'compute.googleapis.com/resource_type' },
          { 'key' => 'cloud.googleapis.com/service' }
        ],
        'typeDescriptor' => { 'metricType' => 'delta', 'valueType' => 'double' },
        'description' => 'Indicates the VM running time in seconds.'
      },
    ]
  }

  build_excon_response(body)
end

#list_timeseries(metric, youngest, options = {}) ⇒ Object



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
# File 'lib/fog/google/requests/monitoring/list_timeseries.rb', line 29

def list_timeseries(metric, youngest, options = {})
  body = {
    'kind' => 'cloudmonitoring#listTimeseriesResponse',
    'youngest' => youngest,
    'oldest' => youngest,
    'timeseries' => [
      {
        'timeseriesDesc' => {
          'project' => @project,
          'metric' => metric,
          'labels' => {
            'cloud.googleapis.com/service' => 'compute.googleapis.com',
            'compute.googleapis.com/resource_type' => 'instance',
            'cloud.googleapis.com/location' => 'us-central1-a',
            'compute.googleapis.com/resource_id' => Fog::Mock.random_numbers(20).to_s,
            'compute.googleapis.com/instance_name' => Fog::Mock.random_hex(40),
          },
        },
        'points' => [
          {
            'start' => '2014-07-17T20:06:58.000Z',
            'end' => '2014-07-17T20:07:58.000Z',
            'doubleValue' => 60.0
          },
          {
            'start' => '2014-07-17T20:05:58.000Z',
            'end' => '2014-07-17T20:06:58.000Z',
            'doubleValue' => 60.0
          },
        ],
      }
    ]
  }

  build_excon_response(body)
end

#list_timeseries_descriptors(metric, youngest, options = {}) ⇒ Object



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
# File 'lib/fog/google/requests/monitoring/list_timeseries_descriptors.rb', line 29

def list_timeseries_descriptors(metric, youngest, options = {})
  body = {
    'kind' => 'cloudmonitoring#listTimeseriesDescriptorsResponse',
    'youngest' => youngest,
    'oldest' => youngest,
    'timeseries' => [
      {
        'project' => @project,
        'metric' => metric,
        'labels' => {
          'cloud.googleapis.com/service' => 'compute.googleapis.com',
          'compute.googleapis.com/resource_type' => 'instance',
          'cloud.googleapis.com/location' => 'us-central1-a',
          'compute.googleapis.com/resource_id' => Fog::Mock.random_numbers(20).to_s,
          'compute.googleapis.com/instance_name' => Fog::Mock.random_hex(40),
        },
      },
      {
        'project' => @project,
        'metric' => metric,
        'labels' => {
          'cloud.googleapis.com/service' => 'compute.googleapis.com',
          'compute.googleapis.com/resource_type' => 'instance',
          'cloud.googleapis.com/location' => 'us-central1-a',
          'compute.googleapis.com/resource_id' => Fog::Mock.random_numbers(20).to_s,
          'compute.googleapis.com/instance_name' => Fog::Mock.random_hex(40),
         },
      },
      {
        'project' => @project,
        'metric' => metric,
        'labels' => {
          'cloud.googleapis.com/service' => 'compute.googleapis.com',
          'compute.googleapis.com/resource_type' => 'instance',
          'cloud.googleapis.com/location' => 'us-central1-a',
          'compute.googleapis.com/resource_id' => Fog::Mock.random_numbers(20).to_s,
          'compute.googleapis.com/instance_name' => Fog::Mock.random_hex(40),
         },
      },
      {
        'project' => @project,
        'metric' => metric,
        'labels' => {
          'cloud.googleapis.com/service' => 'compute.googleapis.com',
          'compute.googleapis.com/resource_type' => 'instance',
          'cloud.googleapis.com/location' => 'us-central1-a',
          'compute.googleapis.com/resource_id' => Fog::Mock.random_numbers(20).to_s,
          'compute.googleapis.com/instance_name' => Fog::Mock.random_hex(40),
         },
      },
    ]
  }

  build_excon_response(body)
end

#reset_dataObject



68
69
70
# File 'lib/fog/google/monitoring.rb', line 68

def reset_data
  self.class.data.delete(project)
end