Need help in python program
Hello Everyone, I am doing python code by using API. My first API giving fields - Itemid, clock and value second API giving fields - Itemid, key, units and delay using for loops for both API. Could you please tell me how to compare both id by using equal operator. My output should be : Itemid, clock, value, key, units and delay -- https://mail.python.org/mailman/listinfo/python-list
Re: Urgent - Would like to see output of each block of python
On Monday, June 6, 2016 at 12:35:55 PM UTC+5:30, Chris Rebert wrote: > On Sun, Jun 5, 2016 at 11:57 PM, Archana Sonavane > <archana.sonav...@gmail.com> wrote: > > Hi Team, > > > > I don't have any idea about python scripts, i have ganglia tool python > > scripts. > > > > I would like see the output of each code block, could you please guide. > > > > The code as follows: > > > With regard to your Subject line, please don't attempt to mark posts > as "urgent". > See http://www.catb.org/esr/faqs/smart-questions.html#urgent > > Regards, > Chris Ok.. Sorry, next time will take care. -- https://mail.python.org/mailman/listinfo/python-list
Would like to see python script output
Hello, I have ganglia python script, i would like to see output of each code block. Could you please guide. I don't have any idea about python. My scripts as follows: #!/usr/bin/env python # # ganglia-api.py - Ganglia Metric API # from settings import LOGFILE, PIDFILE, API_SERVER, HEARTBEAT import os import sys import glob import re import logging import socket import select import datetime import time import SocketServer from xml.etree import ElementTree from xml.parsers.expat import ExpatError from urllib import quote from threading import Thread import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options __version__ = '1.0.16' define("port", default=8080, help="run on the given port", type=int) logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s[%(process)d] %(levelname)s - %(message)s", filename=LOGFILE) global logger logger = logging.getLogger("ganglia-api") class Elem: def __init__(self, elem): self.elem = elem def __getattr__(self, name): return self.elem.get(name.upper()) class NullElem: def __getattr__(self, name): return None class ApiMetric: tag_re = re.compile("\s+") def id(self): group = self.group if self.group is not None else "" id_elements = [self.environment, self.grid.name, self.cluster.name, self.host.name, group, self.name] return str.lower(".".join(filter(lambda (e): e is not None, id_elements))) def api_dict(self): type, units = ApiMetric.metric_type(self.type, self.units, self.slope) metric = {'environment': self.environment, 'service': self.grid.name, 'cluster': self.cluster.name, 'host': self.host.name, 'id': self.id(), 'metric': self.name, 'instance': self.instance, 'group': self.group, 'title': self.title, 'tags': ApiMetric.parse_tags(self.host.tags), 'description': self.desc, 'sum': self.sum, 'num': self.num, 'value': ApiMetric.is_num(self.val), 'units': units, 'type': type, 'sampleTime': datetime.datetime.fromtimestamp( int(self.host.reported) + int(self.host.tn) - int(self.tn)).isoformat() + ".000Z", 'graphUrl': self.graph_url, 'dataUrl': self.data_url} return dict(filter(lambda (k, v): v is not None, metric.items())) @staticmethod def parse_tags(tag_string): if tag_string is None: return None else: tags = ApiMetric.tag_re.split(tag_string) if "unspecified" in tags: return list() else: return tags @staticmethod def metric_type(type, units, slope): if units == 'timestamp': return 'timestamp', 's' if 'int' in type or type == 'float' or type == 'double': return 'gauge', units if type == 'string': return 'text', units return 'undefined', units @staticmethod def is_num(val): try: return int(val) except ValueError: pass try: return float(val) except ValueError: return val def __str__(self): return "%s %s %s %s %s %s" % ( self.environment, self.grid.name, self.cluster.name, self.host.name, self.group, self.name) class Metric(Elem, ApiMetric): def __init__(self, elem, host, cluster, grid, environment): self.host = host self.cluster = cluster self.grid = grid self.environment = environment Elem.__init__(self, elem) self.metadata = dict() for extra_data in elem.findall("EXTRA_DATA"): for extra_elem in extra_data.findall("EXTRA_ELEMENT"): name = extra_elem.get("NAME") if name: self.metadata[name] = extra_elem.get('VAL') original_metric_name = self.name try: self.metadata['NAME'], self.metadata['INSTANCE'] = self.name.split('-', 1) except ValueError: self.metadata['INSTANCE'] = '' if self.name in ['fs_util', 'inode_util']: if self.instance == 'rootfs': self.metadata['INSTANCE'] = '/' else: self.metadata['INSTANCE'] = '/' + '/'.join(self.instance.split('-')) params = {"environment": self.environment, "service": self.grid.name, "cluster": self.cluster.name, "host": self.host.name, "metric": original_metric_name} url =
Urgent - Would like to see output of each block of python
Hi Team, I don't have any idea about python scripts, i have ganglia tool python scripts. I would like see the output of each code block, could you please guide. The code as follows: #!/usr/bin/env python # # ganglia-api.py - Ganglia Metric API # from settings import LOGFILE, PIDFILE, API_SERVER, HEARTBEAT import os import sys import glob import re import logging import socket import select import datetime import time import SocketServer from xml.etree import ElementTree from xml.parsers.expat import ExpatError from urllib import quote from threading import Thread import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options __version__ = '1.0.16' define("port", default=8080, help="run on the given port", type=int) logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s[%(process)d] %(levelname)s - %(message)s", filename=LOGFILE) global logger logger = logging.getLogger("ganglia-api") class Elem: def __init__(self, elem): self.elem = elem def __getattr__(self, name): return self.elem.get(name.upper()) class NullElem: def __getattr__(self, name): return None class ApiMetric: tag_re = re.compile("\s+") def id(self): group = self.group if self.group is not None else "" id_elements = [self.environment, self.grid.name, self.cluster.name, self.host.name, group, self.name] return str.lower(".".join(filter(lambda (e): e is not None, id_elements))) def api_dict(self): type, units = ApiMetric.metric_type(self.type, self.units, self.slope) metric = {'environment': self.environment, 'service': self.grid.name, 'cluster': self.cluster.name, 'host': self.host.name, 'id': self.id(), 'metric': self.name, 'instance': self.instance, 'group': self.group, 'title': self.title, 'tags': ApiMetric.parse_tags(self.host.tags), 'description': self.desc, 'sum': self.sum, 'num': self.num, 'value': ApiMetric.is_num(self.val), 'units': units, 'type': type, 'sampleTime': datetime.datetime.fromtimestamp( int(self.host.reported) + int(self.host.tn) - int(self.tn)).isoformat() + ".000Z", 'graphUrl': self.graph_url, 'dataUrl': self.data_url} return dict(filter(lambda (k, v): v is not None, metric.items())) @staticmethod def parse_tags(tag_string): if tag_string is None: return None else: tags = ApiMetric.tag_re.split(tag_string) if "unspecified" in tags: return list() else: return tags @staticmethod def metric_type(type, units, slope): if units == 'timestamp': return 'timestamp', 's' if 'int' in type or type == 'float' or type == 'double': return 'gauge', units if type == 'string': return 'text', units return 'undefined', units @staticmethod def is_num(val): try: return int(val) except ValueError: pass try: return float(val) except ValueError: return val def __str__(self): return "%s %s %s %s %s %s" % ( self.environment, self.grid.name, self.cluster.name, self.host.name, self.group, self.name) class Metric(Elem, ApiMetric): def __init__(self, elem, host, cluster, grid, environment): self.host = host self.cluster = cluster self.grid = grid self.environment = environment Elem.__init__(self, elem) self.metadata = dict() for extra_data in elem.findall("EXTRA_DATA"): for extra_elem in extra_data.findall("EXTRA_ELEMENT"): name = extra_elem.get("NAME") if name: self.metadata[name] = extra_elem.get('VAL') original_metric_name = self.name try: self.metadata['NAME'], self.metadata['INSTANCE'] = self.name.split('-', 1) except ValueError: self.metadata['INSTANCE'] = '' if self.name in ['fs_util', 'inode_util']: if self.instance == 'rootfs': self.metadata['INSTANCE'] = '/' else: self.metadata['INSTANCE'] = '/' + '/'.join(self.instance.split('-')) params = {"environment": self.environment, "service": self.grid.name, "cluster": self.cluster.name, "host": self.host.name, "metric": original_metric_name}
Would like to see output of each block of python
Hi Team, I would like to see output of each block of python. Don't have any idea about python. What is command to see the output of each code block. #!/usr/bin/env python # # ganglia-api.py - Ganglia Metric API # from settings import LOGFILE, PIDFILE, API_SERVER, HEARTBEAT import os import sys import glob import re import logging import socket import select import datetime import time import SocketServer from xml.etree import ElementTree from xml.parsers.expat import ExpatError from urllib import quote from threading import Thread import tornado.httpserver import tornado.ioloop import tornado.options import tornado.web from tornado.options import define, options __version__ = '1.0.16' define("port", default=8080, help="run on the given port", type=int) logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s[%(process)d] %(levelname)s - %(message)s", filename=LOGFILE) global logger logger = logging.getLogger("ganglia-api") class Elem: def __init__(self, elem): self.elem = elem def __getattr__(self, name): return self.elem.get(name.upper()) class NullElem: def __getattr__(self, name): return None class ApiMetric: tag_re = re.compile("\s+") def id(self): group = self.group if self.group is not None else "" id_elements = [self.environment, self.grid.name, self.cluster.name, self.host.name, group, self.name] return str.lower(".".join(filter(lambda (e): e is not None, id_elements))) def api_dict(self): type, units = ApiMetric.metric_type(self.type, self.units, self.slope) metric = {'environment': self.environment, 'service': self.grid.name, 'cluster': self.cluster.name, 'host': self.host.name, 'id': self.id(), 'metric': self.name, 'instance': self.instance, 'group': self.group, 'title': self.title, 'tags': ApiMetric.parse_tags(self.host.tags), 'description': self.desc, 'sum': self.sum, 'num': self.num, 'value': ApiMetric.is_num(self.val), 'units': units, 'type': type, 'sampleTime': datetime.datetime.fromtimestamp( int(self.host.reported) + int(self.host.tn) - int(self.tn)).isoformat() + ".000Z", 'graphUrl': self.graph_url, 'dataUrl': self.data_url} return dict(filter(lambda (k, v): v is not None, metric.items())) @staticmethod def parse_tags(tag_string): if tag_string is None: return None else: tags = ApiMetric.tag_re.split(tag_string) if "unspecified" in tags: return list() else: return tags @staticmethod def metric_type(type, units, slope): if units == 'timestamp': return 'timestamp', 's' if 'int' in type or type == 'float' or type == 'double': return 'gauge', units if type == 'string': return 'text', units return 'undefined', units @staticmethod def is_num(val): try: return int(val) except ValueError: pass try: return float(val) except ValueError: return val def __str__(self): return "%s %s %s %s %s %s" % ( self.environment, self.grid.name, self.cluster.name, self.host.name, self.group, self.name) class Metric(Elem, ApiMetric): def __init__(self, elem, host, cluster, grid, environment): self.host = host self.cluster = cluster self.grid = grid self.environment = environment Elem.__init__(self, elem) self.metadata = dict() for extra_data in elem.findall("EXTRA_DATA"): for extra_elem in extra_data.findall("EXTRA_ELEMENT"): name = extra_elem.get("NAME") if name: self.metadata[name] = extra_elem.get('VAL') original_metric_name = self.name try: self.metadata['NAME'], self.metadata['INSTANCE'] = self.name.split('-', 1) except ValueError: self.metadata['INSTANCE'] = '' if self.name in ['fs_util', 'inode_util']: if self.instance == 'rootfs': self.metadata['INSTANCE'] = '/' else: self.metadata['INSTANCE'] = '/' + '/'.join(self.instance.split('-')) params = {"environment": self.environment, "service": self.grid.name, "cluster": self.cluster.name, "host": self.host.name, "metric": original_metric_name} url = '%s/ganglia/api/v1/metrics?'