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

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/fog/google/monitoring/mock.rb,
lib/fog/google/requests/monitoring/list_timeseries.rb,
lib/fog/google/requests/monitoring/list_metric_descriptors.rb,
lib/fog/google/requests/monitoring/list_monitored_resource_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.



7
8
9
# File 'lib/fog/google/monitoring/mock.rb', line 7

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

Class Method Details

.dataObject



11
12
13
14
15
16
17
18
19
# File 'lib/fog/google/monitoring/mock.rb', line 11

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

.resetObject



21
22
23
# File 'lib/fog/google/monitoring/mock.rb', line 21

def self.reset
  @data = nil
end

Instance Method Details

#dataObject



25
26
27
# File 'lib/fog/google/monitoring/mock.rb', line 25

def data
  self.class.data[project]
end

#list_metric_descriptors(_options = {}) ⇒ Object



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

def list_metric_descriptors(_options = {})
  body = {
    "metricDescriptors" => [
      {
        "type" => "compute.googleapis.com/instance/cpu/reserved_cores",
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/cpu/reserved_cores",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          }
        ],
        "metricKind" => "GAUGE",
        "valueType" => "DOUBLE",
        "unit" => "1",
        "description" => "Number of cores reserved on the host of the instance.",
        "displayName" => "Reserved cores"
      },
      {
        "type" => "compute.googleapis.com/instance/cpu/usage_time",
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/cpu/usage_time",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          }
        ],
        "metricKind" => "DELTA",
        "valueType" => "DOUBLE",
        "unit" => "s",
        "description" => "Delta CPU usage for all cores, in seconds. To compute the per-core CPU utilization fraction, divide this value by (end-start)*N, where end and start define this value's time interval and N is `compute.googleapis.com/instance/cpu/reserved_cores` at the end of the interval.",
        "displayName" => "CPU usage"
      },
      {
        "type" => "compute.googleapis.com/instance/disk/read_bytes_count",
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/disk/read_bytes_count",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          },
          {
            "key" => "device_name",
            "description" => "The name of the disk device."
          },
          {
            "key" => "storage_type",
            "description" => "The storage type => `pd-standard` or `pd-ssd`."
          },
          {
            "key" => "device_type",
            "description" => "The disk type => `ephemeral` or `permanent`."
          }
        ],
        "metricKind" => "DELTA",
        "valueType" => "INT64",
        "unit" => "By",
        "description" => "Delta count of bytes read from disk.",
        "displayName" => "Disk read bytes"
      },
      {
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/disk/read_ops_count",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          },
          {
            "key" => "device_name",
            "description" => "The name of the disk device."
          },
          {
            "key" => "storage_type",
            "description" => "The storage type => `pd-standard` or `pd-ssd`."
          },
          {
            "key" => "device_type",
            "description" => "The disk type => `ephemeral` or `permanent`."
          }
        ],
        "metricKind" => "DELTA",
        "valueType" => "INT64",
        "unit" => "1",
        "description" => "Delta count of disk read IO operations.",
        "displayName" => "Disk read operations",
        "type" => "compute.googleapis.com/instance/disk/read_ops_count"
      },
      {
        "type" => "compute.googleapis.com/instance/disk/write_bytes_count",
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/disk/write_bytes_count",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          },
          {
            "key" => "device_name",
            "description" => "The name of the disk device."
          },
          {
            "key" => "storage_type",
            "description" => "The storage type => `pd-standard` or `pd-ssd`."
          },
          {
            "key" => "device_type",
            "description" => "The disk type => `ephemeral` or `permanent`."
          }
        ],
        "metricKind" => "DELTA",
        "valueType" => "INT64",
        "unit" => "By",
        "description" => "Delta count of bytes written to disk.",
        "displayName" => "Disk write bytes"
      },
      {
        "type" => "compute.googleapis.com/instance/disk/write_ops_count",
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/disk/write_ops_count",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          },
          {
            "key" => "device_name",
            "description" => "The name of the disk device."
          },
          {
            "key" => "storage_type",
            "description" => "The storage type => `pd-standard` or `pd-ssd`."
          },
          {
            "key" => "device_type",
            "description" => "The disk type => `ephemeral` or `permanent`."
          }
        ],
        "metricKind" => "DELTA",
        "valueType" => "INT64",
        "unit" => "1",
        "description" => "Delta count of disk write IO operations.",
        "displayName" => "Disk write operations"
      },
      {
        "type" => "compute.googleapis.com/instance/network/received_packets_count",
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/network/received_packets_count",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          },
          {
            "key" => "loadbalanced",
            "valueType" => "BOOL",
            "description" => "Whether traffic was received by an L3 loadbalanced IP address assigned to the VM. Traffic that is externally routed to the VM's standard internal or external IP address, such as L7 loadbalanced traffic, is not considered to be loadbalanced in this metric."
          }
        ],
        "metricKind" => "DELTA",
        "valueType" => "INT64",
        "unit" => "1",
        "description" => "Delta count of packets received from the network.",
        "displayName" => "Received packets"
      },
      {
        "type" => "compute.googleapis.com/instance/network/sent_bytes_count",
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/network/sent_bytes_count",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          },
          {
            "key" => "loadbalanced",
            "valueType" => "BOOL",
            "description" => "Whether traffic was sent from an L3 loadbalanced IP address assigned to the VM. Traffic that is externally routed from the VM's standard internal or external IP address, such as L7 loadbalanced traffic, is not considered to be loadbalanced in this metric."
          }
        ],
        "metricKind" => "DELTA",
        "valueType" => "INT64",
        "unit" => "By",
        "description" => "Delta count of bytes sent over the network.",
        "displayName" => "Sent bytes"
      },
      {
        "type" => "compute.googleapis.com/instance/network/sent_packets_count",
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/network/sent_packets_count",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          },
          {
            "key" => "loadbalanced",
            "valueType" => "BOOL",
            "description" => "Whether traffic was sent from an L3 loadbalanced IP address assigned to the VM. Traffic that is externally routed from the VM's standard internal or external IP address, such as L7 loadbalanced traffic, is not considered to be loadbalanced in this metric."
          }
        ],
        "metricKind" => "DELTA",
        "valueType" => "INT64",
        "unit" => "1",
        "description" => "Delta count of packets sent over the network.",
        "displayName" => "Sent packets"
      },
      {
        "type" => "compute.googleapis.com/instance/uptime",
        "name" => "projects/#{@project}/metricDescriptors/compute.googleapis.com/instance/uptime",
        "labels" => [
          {
            "key" => "instance_name",
            "description" => "The name of the VM instance."
          }
        ],
        "metricKind" => "DELTA",
        "valueType" => "DOUBLE",
        "unit" => "s",
        "description" => "How long the VM has been running, in seconds.",
        "displayName" => "Uptime"
      }
    ]
  }

  build_excon_response(body)
end

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

def list_monitored_resource_descriptors(_options = {})
  body = {
    "resourceDescriptors" => [
      {
        "type" => "api",
        "displayName" => "Produced API",
        "description" => "An API provided by the producer.",
        "labels" => [
          {
            "key" => "project_id",
            "description" => "The identifier of the GCP project associated with this resource (e.g., my-project)."
          },
          {
            "key" => "service",
            "description" => "API service name e.g. \"cloudsql.googleapis.com\"."
          },
          {
            "key" => "method",
            "description" => "API method e.g. \"disks.list\"."
          },
          {
            "key" => "version",
            "description" => "API version e.g. \"v1\"."
          },
          {
            "key" => "location",
            "description" => "The service specific notion of location. This can be a name of a zone, region, or \"global."
          }
        ],
        "name" => "projects/#{@project}/monitoredResourceDescriptors/api"
      }
    ]
  }
  build_excon_response(body)
end

#list_timeseries(interval, _options = {}) ⇒ Object



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.rb', line 52

def list_timeseries(interval, _options = {})
  body = {
    "timeSeries" => [
      {
        "metric" => {
          "labels" => { "instance_name" => "emilyye-dev" },
          "type" => "compute.googleapis.com/instance/cpu/usage_time"
        },
        "resource" => {
          "type" => "gce_instance",
          "labels" => {
            "instance_id" => "3959348537894302241",
            "zone" => "us-central1-c",
            "project_id" => @project
          }
        },
        "metricKind" => "DELTA",
        "valueType" => "DOUBLE",
        "points" => [
          {
            "interval" => interval,
            "value" => {
              "doubleValue" => 1.8277230720141233
            }
          }
        ]
      }
    ]
  }

  build_excon_response(body)
end

#reset_dataObject



29
30
31
# File 'lib/fog/google/monitoring/mock.rb', line 29

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