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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
##############################################################################
# Copyright (c) 2015 EMC and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import getopt
import json
import logging
import logging.config
import os
import socket
import sys
from fio.fio_invoker import FIOInvoker
from carbon.emitter import CarbonMetricTransmitter
from carbon.converter import JSONToCarbon
"""
"""
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def event(metric):
metrics_converter = JSONToCarbon()
metrics_emitter = CarbonMetricTransmitter()
prefix = socket.getfqdn()
carbon_metrics = metrics_converter.convert_to_dictionary(metric, prefix)
metrics_emitter.transmit_metrics(carbon_metrics)
def setup_logging(
default_path='logging.json',
default_level=logging.INFO,
env_key='LOG_CFG'
):
"""Setup logging configuration
"""
path = default_path
value = os.getenv(env_key, None)
if value:
path = value
if os.path.exists(path):
with open(path, 'rt') as f:
config = json.load(f)
logging.config.dictConfig(config)
else:
logging.basicConfig(level=default_level)
def main(argv=None):
setup_logging()
if argv is None:
argv = sys.argv
try:
try:
opts = getopt.getopt(argv[1:], "h", ["help"])
except getopt.error, msg:
raise Usage(msg)
except Usage, err:
print >> sys.stderr, err.msg
print >> sys.stderr, "for help use --help"
return 2
for o in opts:
if o in ("-h", "--help"):
print __doc__
return 0
simple_args = ['--rw=randread', '--size=32m',
'--directory=.',
'--iodepth=2',
'--direct=1', '--invalidate=1', '--numjobs=4',
'--name=random-read', '--output-format=json',
'--status-interval=60',
'--time_based', '--runtime=6000']
invoker = FIOInvoker()
invoker.register(event)
invoker.execute(simple_args)
logging.config.fileConfig('logging.ini')
if __name__ == "__main__":
sys.exit(main())
|