Revert "F OpenNebula/engineering#716: Add opennebula-exporter funct (#4129)"

This reverts commit 68d74e4afc.
This commit is contained in:
Ruben S. Montero committed 2026-03-30 10:16:07 +02:00
1 parent ebbb7be5d4
commit cf5fbf92e0
4 files changed
+3 -382

No files matched your search

@@ -1,128 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2026, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require 'opennebula'
require 'rexml/document'
# OpenNebula Address Range collector.
#
# Metrics exposed:
# - opennebula_vnet_free_lease_ratio{vnet_id="...",vnet_name="...",ar_id="..."} 0.00-1.00
class OpenNebulaARCollector
LABELS = [:vnet_id, :vnet_name, :ar_id].freeze
METRIC_NAME = 'vnet_free_lease_ratio'
def initialize(registry, client, namespace)
@client = client
@metric = registry.gauge(
"#{namespace}_#{METRIC_NAME}".to_sym,
:docstring => 'Fraction of free leases in each VNet Address Range',
:labels => LABELS
)
end
def collect
pool = fetch_vnet_pool
return if pool.nil?
pool.each do |vnet|
process_vnet(vnet)
rescue StandardError => e
warn("[OpenNebulaARCollector] VNet error: #{e.class}: #{e.message}")
end
rescue StandardError => e
warn("[OpenNebulaARCollector] #{e.class}: #{e.message}")
nil
end
private
def fetch_vnet_pool
pool = OpenNebula::VirtualNetworkPool.new(@client)
rc = pool.info_all
if OpenNebula.is_error?(rc)
warn("[OpenNebulaARCollector] pool.info_all failed: #{rc.message}")
return
end
pool
end
def process_vnet(vnet)
doc = REXML::Document.new(vnet.to_xml)
vnet_id = text(doc, 'VNET/ID')
vnet_name = text(doc, 'VNET/NAME')
doc.elements.each('VNET/AR_POOL/AR') do |ar_el|
process_ar(ar_el, vnet_id, vnet_name)
end
end
def process_ar(ar_el, vnet_id, vnet_name)
size = ar_size(ar_el)
return if size <= 0
free_ratio = compute_ratio(size, used_leases(ar_el))
@metric.set(
free_ratio,
:labels => metric_labels(vnet_id, vnet_name, ar_el)
)
end
def ar_size(ar_el)
ar_el.elements['SIZE']&.text.to_i
end
def metric_labels(vnet_id, vnet_name, ar_el)
{
:vnet_id => vnet_id.to_s,
:vnet_name => vnet_name.to_s,
:ar_id => ar_el.elements['AR_ID']&.text.to_s
}
end
def compute_ratio(size, used)
ratio = (size - used).to_f / size
ratio = 0.0 if ratio < 0.0
ratio = 1.0 if ratio > 1.0
ratio.round(2)
end
def text(doc, xpath)
el = doc.elements[xpath]
el ? el.text.to_s : ''
end
# Prefer AR/USED_LEASES if present.
# Fallback to AR/ALLOCATED parsing (pairs: INDEX ENCODED_VMID).
def used_leases(ar_el)
used_el = ar_el.elements['USED_LEASES']
return used_el.text.to_i if used_el && !used_el.text.to_s.empty?
allocated = ar_el.elements['ALLOCATED']&.text.to_s
tokens = allocated.split
tokens.size / 2
end
end
@@ -1,5 +1,5 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2026, OpenNebula Project, OpenNebula Systems #
# Copyright 2002-2025, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
@@ -18,11 +18,9 @@ require 'opennebula'
require 'prometheus/client'
require_relative 'opennebula_server_collector'
require_relative 'opennebula_ha_collector'
require_relative 'opennebula_host_collector'
require_relative 'opennebula_datastore_collector'
require_relative 'opennebula_vm_collector'
require_relative 'opennebula_ar_collector'
module Prometheus
@@ -85,10 +83,6 @@ module Prometheus
@registry, @client, NAMESPACE)
@collectors << OpenNebulaVMCollector.new(
@registry, @client, NAMESPACE)
@collectors << OpenNebulaARCollector.new(
@registry, @client, NAMESPACE)
@collectors << OpenNebulaHACollector.new(
@registry, @client, NAMESPACE)
end
def call(env)
@@ -1,239 +0,0 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2026, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require 'socket'
require 'timeout'
require 'xmlrpc/client'
require 'rexml/document'
require 'opennebula'
# Metrics exposed:
# - opennebula_ha_is_leader{one_server_fqdn="..."} 0|1
# - opennebula_ha_error_members{one_server_fqdn="..."} N
# - opennebula_ha_members{one_server_fqdn="..."} N
class OpenNebulaHACollector
LABELS = [:one_server_fqdn].freeze
STATE_FOLLOWER = 2
STATE_LEADER = 3
METRICS = {
'ha_is_leader' => {
:type => :gauge,
:docstr => 'This server is RAFT leader (1) or not (0)',
:labels => LABELS
},
'ha_error_members' => {
:type => :gauge,
:docstr => 'Number of HA members with failed or unexpected RAFT state',
:labels => LABELS
},
'ha_members' => {
:type => :gauge,
:docstr => 'Total number of HA members reported by zone pool',
:labels => LABELS
}
}.freeze
def initialize(registry, _client, namespace)
@metrics = build_metrics(registry, namespace)
@auth = load_auth
@xmlrpc_endpoint = load_xmlrpc_endpoint
@timeout = load_timeout
@fqdn = resolve_fqdn
@one_client = build_one_client
end
def collect
labels = metric_labels
statuses = cluster_statuses
return if statuses.empty?
write_metrics(statuses, labels)
rescue StandardError => e
warn("[OpenNebulaHACollector] #{e.class}: #{e.message}")
nil
end
private
def build_metrics(registry, namespace)
metrics = {}
METRICS.each do |name, conf|
metrics[name] = registry.public_send(
conf[:type],
"#{namespace}_#{name}".to_sym,
:docstring => conf[:docstr],
:labels => conf[:labels]
)
end
metrics
end
def load_auth
path = ENV.fetch('ONE_AUTH', File.expand_path('~/.one/one_auth'))
File.read(path).strip
end
def load_xmlrpc_endpoint
ENV.fetch('ONE_XMLRPC', 'http://localhost:2633/RPC2')
end
def load_timeout
(ENV['ONEZONE_TIMEOUT'] || '5').to_i
end
def build_one_client
OpenNebula::Client.new(@auth, @xmlrpc_endpoint)
end
def metric_labels
{ :one_server_fqdn => @fqdn }
end
def cluster_statuses
servers = fetch_zone_servers
return [] if servers.empty?
servers.map {|srv| fetch_server_status(srv) }
end
def write_metrics(statuses, labels)
@metrics['ha_members'].set(member_count(statuses), :labels => labels)
@metrics['ha_error_members'].set(error_member_count(statuses), :labels => labels)
@metrics['ha_is_leader'].set(local_leader_value, :labels => labels)
end
def member_count(statuses)
statuses.size
end
def error_member_count(statuses)
statuses.count {|status| problem_state?(status) }
end
def local_leader_value
local_status = fetch_local_status
local_status[:state_num] == STATE_LEADER ? 1 : 0
end
def fetch_zone_servers
pool = OpenNebula::ZonePool.new(@one_client)
rc = pool.info
raise rc.message if OpenNebula.is_error?(rc)
extract_servers(pool)
end
def extract_servers(pool)
servers = []
pool.each do |zone|
zone.each('SERVER_POOL/SERVER') do |srv|
servers << zone_server_hash(srv)
end
end
servers
end
def zone_server_hash(server)
{
:id => server['ID'].to_i,
:name => server['NAME'].to_s,
:endpoint => server['ENDPOINT'].to_s
}
end
def fetch_local_status
fetch_raft(@xmlrpc_endpoint)
rescue StandardError
error_status
end
def fetch_server_status(server)
status = fetch_raft(server[:endpoint])
merge_server_status(status, server)
rescue StandardError
merge_server_status(error_status, server)
end
def merge_server_status(status, server)
status.merge(
:id => server[:id],
:name => server[:name]
)
end
def error_status
{
:state_num => nil,
:rpc_error => true
}
end
def fetch_raft(endpoint)
xml = rpc_call(endpoint, 'one.zone.raftstatus')
parse_raft(xml)
end
def rpc_call(endpoint, method)
Timeout.timeout(@timeout) do
client = XMLRPC::Client.new2(endpoint)
ok, payload, error_code = client.call(method, @auth)
raise "#{method} failed: #{error_code}" unless ok
payload
end
end
def parse_raft(xml)
doc = REXML::Document.new(xml)
raft = REXML::XPath.first(doc, '//RAFT')
raise 'RAFT not found' unless raft
{
:state_num => text(raft, 'STATE')&.to_i,
:rpc_error => false
}
end
def text(node, name)
el = REXML::XPath.first(node, name)
el&.text
end
def problem_state?(status)
return true if status[:rpc_error]
state = status[:state_num]
state != STATE_LEADER && state != STATE_FOLLOWER
end
def resolve_fqdn
host = Socket.gethostname
Addrinfo.getaddrinfo(host, nil).first.getnameinfo.first
rescue StandardError
Socket.gethostname
end
end
@@ -1,5 +1,5 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2026, OpenNebula Project, OpenNebula Systems #
# Copyright 2002-2025, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
@@ -57,13 +57,7 @@ class OpenNebulaServerCollector
:docstr => 'OpenNebula Gate service state 0:down 1:up',
:labels => LABELS,
:systemd => 'opennebula-gate.service'
},
'fireedge_state' => {
:type => :gauge,
:docstr => 'OpenNebula FireEdge service state 0:down 1:up',
:labels => LABELS,
:systemd => 'opennebula-fireedge.service'
},
}
}
def initialize(registry, client, namespace)