1
0
mirror of https://github.com/dkmstr/openuds.git synced 2025-01-05 09:17:54 +03:00

* Added basic charting to server (used nowhere right now, but it's now available :-), posiblily used in a future when adding REST api)

* Added basic counter stats retrieval to xmlrpc api (for charts on administration client)
This commit is contained in:
Adolfo Gómez 2013-02-11 17:54:29 +00:00
parent 8a35b7bd69
commit d1d2a1cbe8
8 changed files with 84 additions and 11 deletions

View File

@ -200,6 +200,8 @@ encoding//src/uds/xmlrpc/services/Publications.py=utf-8
encoding//src/uds/xmlrpc/services/ServiceProviders.py=utf-8 encoding//src/uds/xmlrpc/services/ServiceProviders.py=utf-8
encoding//src/uds/xmlrpc/services/Services.py=utf-8 encoding//src/uds/xmlrpc/services/Services.py=utf-8
encoding//src/uds/xmlrpc/services/UserDeployedServices.py=utf-8 encoding//src/uds/xmlrpc/services/UserDeployedServices.py=utf-8
encoding//src/uds/xmlrpc/stats/__init__.py=utf-8
encoding//src/uds/xmlrpc/stats/stats.py=utf-8
encoding//src/uds/xmlrpc/tools/Cache.py=utf-8 encoding//src/uds/xmlrpc/tools/Cache.py=utf-8
encoding//src/uds/xmlrpc/tools/Config.py=utf-8 encoding//src/uds/xmlrpc/tools/Config.py=utf-8
encoding//src/uds/xmlrpc/transports/Networks.py=utf-8 encoding//src/uds/xmlrpc/transports/Networks.py=utf-8

View File

@ -29,9 +29,12 @@
''' '''
@author: Adolfo Gómez, dkmaster at dkmon dot com @author: Adolfo Gómez, dkmaster at dkmon dot com
''' '''
import datetime import datetime
import cairo import cairo
import pycha.line import pycha.line
import StringIO
import time
from uds.models import getSqlDatetime from uds.models import getSqlDatetime
@ -56,7 +59,7 @@ def make(obj, counterType, **kwargs):
limit = width limit = width
dataset1 = tuple(counters.getCounters(obj, counterType, since=since, to=to, limit=limit, use_max = kwargs.get('use_max', False))) dataset1 = tuple((int(time.mktime(x[0].timetuple())), x[1]) for x in counters.getCounters(obj, counterType, since=since, to=to, limit=limit, use_max = kwargs.get('use_max', False)))
if len(dataset1) == 0: if len(dataset1) == 0:
dataset1 = ( (getSqlDatetime(True)-3600, 0), (getSqlDatetime(True), 0) ) dataset1 = ( (getSqlDatetime(True)-3600, 0), (getSqlDatetime(True), 0) )
@ -72,7 +75,7 @@ def make(obj, counterType, **kwargs):
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
dataset = ( ( counters.getCounterTitle(counterType).encode('ascii'), dataset1 ),) dataset = ( ( counters.getCounterTitle(counterType).encode('iso-8859-1', errors='ignore'), dataset1 ),)
options = { options = {
'axis': { 'axis': {
@ -108,11 +111,11 @@ def make(obj, counterType, **kwargs):
chart = pycha.line.LineChart(surface, options) chart = pycha.line.LineChart(surface, options)
chart.addDataset(dataset) chart.addDataset(dataset)
chart.minxval = dataset1[0][0]
chart.render() chart.render()
surface.write_to_png('/tmp/test.png')
def _initialize(): output = StringIO.StringIO()
global __typeTitles
surface.write_to_png(output)
return output.getvalue()

View File

@ -31,6 +31,7 @@
''' '''
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from uds.core.managers import statsManager from uds.core.managers import statsManager
import datetime
import logging import logging
@ -102,7 +103,7 @@ def getCounters(obj, counterType, **kwargs):
owner_ids = fnc(obj) owner_ids = fnc(obj)
for i in statsManager().getCounters(__transDict[type(obj)], counterType, owner_ids, since, to, limit, use_max): for i in statsManager().getCounters(__transDict[type(obj)], counterType, owner_ids, since, to, limit, use_max):
val = (i.stamp, i.value) val = (datetime.datetime.fromtimestamp(i.stamp), i.value)
yield val yield val
def getCounterTitle(counterType): def getCounterTitle(counterType):

View File

@ -111,6 +111,7 @@ def needs_credentials(xmlrpc_func):
cred = validateCredentials(request, credentials) cred = validateCredentials(request, credentials)
if cred is not None: if cred is not None:
logger.debug('Credentials valid, executing') logger.debug('Credentials valid, executing')
logger.debug('args: {0}'.format(args))
return xmlrpc_func(cred, *args, **kwargs) return xmlrpc_func(cred, *args, **kwargs)
raise AuthException(_('Credentials no longer valid')) raise AuthException(_('Credentials no longer valid'))
return _wrapped_xmlrcp_func return _wrapped_xmlrcp_func

View File

View File

@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013 Virtual Cable S.L.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from django.utils.translation import ugettext as _
from ..auths.AdminAuth import needs_credentials
from ..util.Exceptions import FindException
from uds.core.util.stats import counters
from uds.core.util.Cache import Cache
from uds.models import DeployedService
import logging
logger = logging.getLogger(__name__)
cache = Cache('StatsDispatcher')
@needs_credentials
def getDeployedServiceCounters(credentials, id, counter_type, since, to, points, use_max):
try:
us = DeployedService.objects.get(pk=id)
logger.debug(us)
res = []
for x in counters.getCounters(us, counter_type, since=since, to=to, limit=points, use_max=use_max):
res.append({ 'stamp': x[0], 'value': x[1] })
return { 'title': counters.getCounterTitle(counter_type), 'data': res }
return ()
except:
logger.exception('exception')
raise FindException(_('Service does not exists'))
# Registers XML RPC Methods
def registerStatsFunctions(dispatcher):
dispatcher.register_function(getDeployedServiceCounters, 'getDeployedServiceCounters')

View File

@ -58,10 +58,10 @@ def DuplicateEntryException(msg):
return Fault(DUPLICATE_FAIL, msg) return Fault(DUPLICATE_FAIL, msg)
def InsertException(msg): def InsertException(msg):
return Fault(FIND_FAIL, msg) return Fault(INSERT_FAIL, msg)
def FindException(msg): def FindException(msg):
return Fault() return Fault(FIND_FAIL, msg)
def DeleteException(msg): def DeleteException(msg):
return Fault(DELETE_FAIL, msg) return Fault(DELETE_FAIL, msg)

View File

@ -53,6 +53,7 @@ from auths.UserPreferences import registerPreferencesFunctions
from tools.Cache import registerCacheFunctions from tools.Cache import registerCacheFunctions
from tools.Config import registerConfigurationFunctions from tools.Config import registerConfigurationFunctions
from log.logs import registerLogFunctions from log.logs import registerLogFunctions
from stats.stats import registerStatsFunctions
import logging import logging
@ -144,3 +145,4 @@ registerPreferencesFunctions(dispatcher)
registerCacheFunctions(dispatcher) registerCacheFunctions(dispatcher)
registerConfigurationFunctions(dispatcher) registerConfigurationFunctions(dispatcher)
registerLogFunctions(dispatcher) registerLogFunctions(dispatcher)
registerStatsFunctions(dispatcher)