def data_points_to_td(self, data_points):
    if len(data_points) == 1:
      point = data_points[0]
      return '<td>{time}</td><td>{value}</td>'.format(
          time=StackdriverClient.millis_to_time(point['t']), value=point['v'])

      td_html = '<td colspan=2><table>'
      for point in data_points:
        td_html += '<tr><td>{time}</td><td>{value}</td></tr>'.format(
            time=StackdriverClient.millis_to_time(point['t']),
            value=point['v'])
      td_html += '</tr></table></td>'
      return td_html
    def data_points_to_td(self, data_points):
        if len(data_points) == 1:
            point = data_points[0]
            return '<td>{time}</td><td>{value}</td>'.format(
                time=StackdriverClient.millis_to_time(point['t']),
                value=point['v'])

            td_html = '<td colspan=2><table>'
            for point in data_points:
                td_html += '<tr><td>{time}</td><td>{value}</td></tr>'.format(
                    time=StackdriverClient.millis_to_time(point['t']),
                    value=point['v'])
            td_html += '</tr></table></td>'
            return td_html
def main():
    init_logging("metric_collector.log")
    options = get_options()

    spectator = SpectatorClient(options)
    try:
        stackdriver = StackdriverClient.make_client(options)
    except IOError as ioerror:
        logging.error("Could not create stackdriver client -- Stackdriver will be unavailable\n%s", ioerror)
        stackdriver = None

    if options.command:
        process_command(options.command, spectator, stackdriver, options)
        return

    path_handlers = {
        "/": handlers.BaseHandler(options),
        "/clear": handlers.ClearCustomDescriptorsHandler(options, stackdriver),
        "/dump": handlers.DumpMetricsHandler(options, spectator),
        "/list": handlers.ListCustomDescriptorsHandler(options, stackdriver),
        "/explore": handlers.ExploreCustomDescriptorsHandler(options, spectator),
        "/show": handlers.ShowCurrentMetricsHandler(options, spectator),
    }

    logging.info("Starting HTTP server on port %d", options.port)
    httpd = HttpServer(options.port, path_handlers)
    httpd.serve_forever()
def main():
    init_logging('metric_collector.log')
    options = get_options()

    spectator = SpectatorClient(options)
    try:
        stackdriver = StackdriverClient.make_client(options)
    except IOError as ioerror:
        logging.error(
            'Could not create stackdriver client -- Stackdriver will be unavailable\n%s',
            ioerror)
        stackdriver = None

    if options.command:
        process_command(options.command, spectator, stackdriver, options)
        return

    path_handlers = {
        '/': handlers.BaseHandler(options),
        '/clear': handlers.ClearCustomDescriptorsHandler(options, stackdriver),
        '/dump': handlers.DumpMetricsHandler(options, spectator),
        '/list': handlers.ListCustomDescriptorsHandler(options, stackdriver),
        '/explore':
        handlers.ExploreCustomDescriptorsHandler(options, spectator),
        '/show': handlers.ShowCurrentMetricsHandler(options, spectator)
    }

    logging.info('Starting HTTP server on port %d', options.port)
    httpd = HttpServer(options.port, path_handlers)
    httpd.serve_forever()