Add CPU info to stats
This patch adds a cpu info to api server stats. Adds a new requirement psutils Change-Id: I5644c74b8c22450df0d431e03acb6923d8c15873
This commit is contained in:
parent
4feae463f9
commit
26233e56c7
@ -14,6 +14,7 @@
|
||||
|
||||
import eventlet
|
||||
import json
|
||||
import psutil
|
||||
import socket
|
||||
import time
|
||||
|
||||
@ -68,7 +69,9 @@ class StatsCollectingService(service.Service):
|
||||
v1.stats.request_count,
|
||||
v1.stats.error_count,
|
||||
v1.stats.average_time,
|
||||
v1.stats.requests_per_tenant)
|
||||
v1.stats.requests_per_tenant,
|
||||
psutil.NUM_CPUS,
|
||||
psutil.cpu_percent())
|
||||
return
|
||||
|
||||
now = time.time()
|
||||
@ -85,6 +88,7 @@ class StatsCollectingService(service.Service):
|
||||
requests_per_tenant)
|
||||
stats.requests_per_second = requests_per_second
|
||||
stats.errors_per_second = errors_per_second
|
||||
stats.cpu_percent = psutil.cpu_percent()
|
||||
self._stats_db.update(self._hostname, stats)
|
||||
except Exception as e:
|
||||
LOG.error(_("Failed to get statistics object "
|
||||
|
61
muranoapi/db/migrate_repo/versions/008_cpu_stats.py
Normal file
61
muranoapi/db/migrate_repo/versions/008_cpu_stats.py
Normal file
@ -0,0 +1,61 @@
|
||||
# Copyright (c) 2013 Mirantis, Inc.
|
||||
#
|
||||
# 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.
|
||||
from sqlalchemy import schema
|
||||
from sqlalchemy import types
|
||||
|
||||
meta = schema.MetaData()
|
||||
|
||||
|
||||
def upgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
table = schema.Table('apistats', meta, autoload=True, extend_existing=True)
|
||||
table.drop()
|
||||
stats = schema.Table(
|
||||
'apistats',
|
||||
meta,
|
||||
schema.Column('id', types.Integer(), primary_key=True),
|
||||
schema.Column('host', types.String(80)),
|
||||
schema.Column('request_count', types.BigInteger()),
|
||||
schema.Column('error_count', types.BigInteger()),
|
||||
schema.Column('average_response_time', types.Float()),
|
||||
schema.Column('requests_per_tenant', types.Text()),
|
||||
schema.Column('requests_per_second', types.Float()),
|
||||
schema.Column('errors_per_second', types.Float()),
|
||||
schema.Column('created', types.DateTime, nullable=False),
|
||||
schema.Column('updated', types.DateTime, nullable=False),
|
||||
schema.Column('cpu_count', types.Integer()),
|
||||
schema.Column('cpu_percent', types.Float()), extend_existing=True)
|
||||
stats.create()
|
||||
|
||||
|
||||
def downgrade(migrate_engine):
|
||||
meta.bind = migrate_engine
|
||||
table = schema.Table('apistats', meta, autoload=True, extend_existing=True)
|
||||
table.drop()
|
||||
stats = schema.Table(
|
||||
'apistats',
|
||||
meta,
|
||||
schema.Column('id', types.Integer(), primary_key=True),
|
||||
schema.Column('host', types.String(80)),
|
||||
schema.Column('request_count', types.BigInteger()),
|
||||
schema.Column('error_count', types.BigInteger()),
|
||||
schema.Column('average_response_time', types.Float()),
|
||||
schema.Column('requests_per_tenant', types.Text()),
|
||||
schema.Column('requests_per_second', types.Float()),
|
||||
schema.Column('errors_per_second', types.Float()),
|
||||
schema.Column('created', types.DateTime, nullable=False),
|
||||
schema.Column('updated', types.DateTime, nullable=False),
|
||||
extend_existing=True
|
||||
)
|
||||
stats.create()
|
@ -206,6 +206,8 @@ class ApiStats(BASE, ModificationsTrackedObject):
|
||||
requests_per_tenant = sa.Column(sa.Text())
|
||||
requests_per_second = sa.Column(sa.Float())
|
||||
errors_per_second = sa.Column(sa.Float())
|
||||
cpu_count = sa.Column(sa.Integer())
|
||||
cpu_percent = sa.Column(sa.Float())
|
||||
|
||||
def to_dict(self):
|
||||
dictionary = super(ApiStats, self).to_dict()
|
||||
|
@ -39,7 +39,8 @@ class Statistics(object):
|
||||
|
||||
@staticmethod
|
||||
def create(host, request_count, error_count,
|
||||
average_response_time, request_per_tenant):
|
||||
average_response_time, request_per_tenant, cpu_count,
|
||||
cpu_percent):
|
||||
stats = m.ApiStats()
|
||||
stats.host = host
|
||||
stats.request_count = request_count
|
||||
@ -48,6 +49,8 @@ class Statistics(object):
|
||||
stats.request_per_tenant = request_per_tenant
|
||||
stats.request_per_second = 0.0
|
||||
stats.errors_per_second = 0.0
|
||||
stats.cpu_count = cpu_count
|
||||
stats.cpu_percent = cpu_percent
|
||||
|
||||
db = db_session.get_session()
|
||||
stats.save(db)
|
||||
|
@ -14,6 +14,7 @@ httplib2>=0.7.5
|
||||
kombu>=2.4.8
|
||||
lockfile>=0.8
|
||||
pycrypto>=2.6
|
||||
psutil>=1.1.1
|
||||
iso8601>=0.1.9
|
||||
six>=1.5.2
|
||||
netaddr>=0.7.6
|
||||
|
Loading…
x
Reference in New Issue
Block a user