ceilometerc.py 727 Bytes
Newer Older
Burak Kelgin's avatar
Burak Kelgin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from ceilometerclient import client
import json, ast


def ceilometerc(request):
    cc1 = client.get_client(version=2,
                            os_username="admin",
                            os_password="admin",
                            os_tenant_name='admin',
                            os_auth_url='http://192.168.171.3:5000/v2.0')
    test = cc1.statistics.list('cpu_util')
    list= cc1.meters.list()
    print(list)
    # convert to str
    test = str(test[0])
    # cut unnecessary stuff
    test = test[12:(len(test) - 1)]
    test = json.dumps(test)
    test = json.loads(test)
    # convert to dict
    test = ast.literal_eval(test)
    # get cpu usage avg
    avg = test['avg']
    print(avg)
    return avg