forked from jordant/openstack-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
keystone-timings.py
executable file
·49 lines (40 loc) · 1.05 KB
/
keystone-timings.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
import os
import time
import sys
import socket
from keystoneclient.v2_0 import client
STATS_PREFIX = "openstack.keystone.timings"
USER=os.environ['OS_USERNAME']
PASS=os.environ['OS_PASSWORD']
TENANT_NAME=os.environ['OS_TENANT_NAME']
KEYSTONE_URL=os.environ['OS_AUTH_URL']
GRAPHITE_HOST="127.0.0.1"
def keystoneConnect():
return client.Client(username=USER,
password=PASS,
tenant_name=TENANT_NAME,
auth_url=KEYSTONE_URL,
timeout=10)
def collect_metric(name, value, timestamp):
try:
sock = socket.socket()
sock.settimeout(5)
sock.connect( (GRAPHITE_HOST, 2003) )
print "%s %s %d\n" % (name, value, timestamp)
sock.send("%s %s %d\n" % (name, value, timestamp))
sock.close()
except:
print "Put to graphite failed"
def now():
return int(time.time())
t0 = time.time()
try:
keystone = keystoneConnect()
except:
print "Keystone connection failed"
sys.exit()
t1 = time.time()
total = round(t1-t0,2)
KMETRIC = STATS_PREFIX + ".token_get." + USER
collect_metric(KMETRIC, total, now())