root = E.BusinessTransactions(Controller=c.base_url, GenerationTime=now_rfc3339()) root.set('{%s}noNamespaceSchemaLocation' % XSI, 'bt_metrics.xsd') for k, v in sorted(rows.items()): v['calls'] = v['cpm'] * time_in_mins v['errors'] = v['epm'] * time_in_mins v['error_pct'] = round(float(v['errors']) / float(v['calls']) * 100.0, 1) if v['calls'] > 0 else 0 root.append( E.BusinessTransaction( E.ApplicationName(v['app_name']), E.BusinessTransactionName(v['bt_name']), E.TierName(v['tier_name']), E.AverageResponseTime(str(v['art'])), E.CallsPerMinute(str(v['cpm'])), E.TotalCalls(str(v['calls'])), E.TotalErrors(str(v['errors'])), E.ErrorsPerMinute(str(v['epm'])), E.ErrorPercentage(str(v['error_pct'])), E.SlowCalls(str(v['slow'])), E.VerySlowCalls(str(v['veryslow'])), E.Stalls(str(v['stalls'])), )) # Print the report to stdout. print(etree.ProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"')) print(etree.tostring(root, pretty_print=True, encoding='UTF-8'))
XSI = 'http://www.w3.org/2001/XMLSchema-instance' E = ElementMaker(nsmap={'xsi': XSI}) root = E.BackendResponseTimes(Controller=c.base_url, GenerationTime=now_rfc3339()) root.set('{%s}noNamespaceSchemaLocation' % XSI, 'backend_metrics.xsd') for k, v in sorted(rows.items()): v.setdefault('cpm_max_time', '') v.setdefault('epm_max_time', '') root.append( E.Backend( E.ApplicationName(v['app']), E.BackendName(k), E.AverageResponseTime(str(v.get('art', 0))), E.CallsPerMinute(str(v.get('cpm_average', 0))), E.TotalCalls(str(v.get('total_calls', 0))), E.MaximumCallsPerMinute(str(v.get('cpm_max', 0))), E.MaximumCallTime( v['cpm_max_time'].isoformat('T') if v['cpm_max_time'] else ''), E.ErrorsPerMinute(str(v.get('epm_avg', 0))), E.TotalErrors(str(v.get('total_errors', 0))), E.MaximumErrorsPerMinute(str(v.get('epm_max', 0))), E.MaximumErrorTime( v['epm_max_time'].isoformat('T') if v['epm_max_time'] else ''), )) # Print the report to stdout. print(etree.ProcessingInstruction('xml', 'version="1.0" encoding="UTF-8"')) print(etree.tostring(root, pretty_print=True, encoding='UTF-8'))