
The current copyright refers to a non-existent group "openstack helm authors" with often out-of-date references that are confusing when adding a new file to the repo. This change removes all references to this copyright by the non-existent group and any blank lines underneath. Change-Id: Ic78d29883364378cc14b11402f16d99dcec1fc96
89 lines
3.3 KiB
Python
89 lines
3.3 KiB
Python
# 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.
|
|
|
|
import logging
|
|
from collections import Counter, defaultdict
|
|
|
|
from prometheus_client import CollectorRegistry, generate_latest, Gauge
|
|
|
|
from base import OSBase
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class NeutronAgentStats(OSBase):
|
|
""" Class to report the statistics on Neutron agents.
|
|
|
|
state of agents
|
|
"""
|
|
|
|
def build_cache_data(self):
|
|
|
|
# Get information of the state per agent
|
|
# State can be up or down
|
|
aggregated_agents = defaultdict(Counter)
|
|
stats = self.osclient.get_workers('neutron')
|
|
|
|
for agent in stats:
|
|
service = agent['service']
|
|
state = agent['state']
|
|
aggregated_agents[service][state] += 1
|
|
|
|
for service in aggregated_agents:
|
|
totala = sum(aggregated_agents[service].values())
|
|
for state in self.osclient.states:
|
|
prct = (100.0 * aggregated_agents[service][state]) / totala
|
|
stats.append({
|
|
'stat_name': "services_{}_{}_percent".format(service, state),
|
|
'stat_value': prct,
|
|
'service': service,
|
|
'state': state
|
|
})
|
|
stats.append({
|
|
'stat_name': "services_{}_{}_total".format(service, state),
|
|
'stat_value': aggregated_agents[service][state],
|
|
'service': service,
|
|
'state': state,
|
|
})
|
|
return stats
|
|
|
|
def get_cache_key(self):
|
|
return "neutron_agent_stats"
|
|
|
|
def get_stats(self):
|
|
registry = CollectorRegistry()
|
|
labels = ['region', 'host', 'service', 'state']
|
|
neutron_agent_stats_cache = self.get_cache_data()
|
|
for neutron_agent_stat in neutron_agent_stats_cache:
|
|
try:
|
|
stat_gauge = Gauge(
|
|
self.gauge_name_sanitize(
|
|
neutron_agent_stat['stat_name']),
|
|
'Openstack Neutron agent statistic',
|
|
labels,
|
|
registry=registry)
|
|
label_values = [self.osclient.region,
|
|
neutron_agent_stat.get('host', ''),
|
|
neutron_agent_stat.get('service', ''),
|
|
neutron_agent_stat.get('state', '')]
|
|
stat_gauge.labels(
|
|
*
|
|
label_values).set(
|
|
neutron_agent_stat['stat_value'])
|
|
except ValueError:
|
|
logger.debug('Unchanged value for stat {} already present in '
|
|
'neutron agent registry for host {}; ignoring.'
|
|
.format(neutron_agent_stat['stat_name'],
|
|
neutron_agent_stat['host']))
|
|
|
|
return generate_latest(registry)
|