# Path: collectors/lib/docker_engine/docker_metrics.py
# class DockerMetrics(object):
#     def __init__(self, url):
#         self._url = url
#         self.event_time = time.gmtime()
# 
#     def get_endpoint(self):
#         """ Fetches the endpoint """
#         ret = []
#         r = requests.get(self._url)
#         if r.status_code != 200:
#             print("Error %s: %s" % (r.status_code, r.text))
#         else:
#             for line in r.iter_lines(decode_unicode=True):
#                 if not line.startswith('#'):
#                     ret.extend(self.eval_prometheus_line(self.event_time, line))
#         return ret
# 
#     @staticmethod
#     def eval_prometheus_line(etime, line):
#         ret = []
#         for family in text_string_to_metric_families(line):
#             for sample in family.samples:
#                 dims = []
#                 for kv in sample[1].items():
#                     dims.append("%s=%s" % kv)
#                 m = Metric("docker.{0}".format(*sample), etime, sample[2], dims)
#                 ret.append(m)
#         return ret
# 
# Path: collectors/lib/docker_engine/metric.py
# class Metric(object):
#     def __init__(self, name, etime, value, tags=None):
#         self.name = name
#         self.value = value
#         self.event_time = etime
#         if tags is None:
#             self.dims = set([])
#         else:
#             self.dims = set(tags)
#         self.dims.update(set(DEFAULT_DIMS))
# 
#     def add_dims(self, dims):
#         self.dims.update(set(dims))
# 
#     def get_metric_lines(self):
#         """ return in OpenTSDB format
#         <name> <time_epoch> <value> [key=val] [key1=val1]...
#         """
#         m = "%s %s %s" % (self.name, int(time.mktime(self.event_time)), self.value)
#         return "%s %s" % (m, " ".join(sorted(list(self.dims))))


import unittest
import time
from collectors.lib.docker_engine.docker_metrics import DockerMetrics
from collectors.lib.docker_engine.metric import Metric
#!/usr/bin/env python
# This file is part of tcollector.
# Copyright (C) 2010-2013  The tcollector Authors.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.  This program is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
# General Public License for more details.  You should have received a copy
# of the GNU Lesser General Public License along with this program.  If not,
# see <http://www.gnu.org/licenses/>.





class TestDockerMetrics(unittest.TestCase):
    def setUp(self):
        self.now = time.gmtime()

# Path: collectors/lib/docker_engine/docker_metrics.py
# class DockerMetrics(object):
#     def __init__(self, url):
#         self._url = url
#         self.event_time = time.gmtime()
# 
#     def get_endpoint(self):
#         """ Fetches the endpoint """
#         ret = []
#         r = requests.get(self._url)
#         if r.status_code != 200:
#             print("Error %s: %s" % (r.status_code, r.text))
#         else:
#             for line in r.iter_lines(decode_unicode=True):
#                 if not line.startswith('#'):
#                     ret.extend(self.eval_prometheus_line(self.event_time, line))
#         return ret
# 
#     @staticmethod
#     def eval_prometheus_line(etime, line):
#         ret = []
#         for family in text_string_to_metric_families(line):
#             for sample in family.samples:
#                 dims = []
#                 for kv in sample[1].items():
#                     dims.append("%s=%s" % kv)
#                 m = Metric("docker.{0}".format(*sample), etime, sample[2], dims)
#                 ret.append(m)
#         return ret
# 
# Path: collectors/lib/docker_engine/metric.py
# class Metric(object):
#     def __init__(self, name, etime, value, tags=None):
#         self.name = name
#         self.value = value
#         self.event_time = etime
#         if tags is None:
#             self.dims = set([])
#         else:
#             self.dims = set(tags)
#         self.dims.update(set(DEFAULT_DIMS))
# 
#     def add_dims(self, dims):
#         self.dims.update(set(dims))
# 
#     def get_metric_lines(self):
#         """ return in OpenTSDB format
#         <name> <time_epoch> <value> [key=val] [key1=val1]...
#         """
#         m = "%s %s %s" % (self.name, int(time.mktime(self.event_time)), self.value)
#         return "%s %s" % (m, " ".join(sorted(list(self.dims))))


# Path: collectors/test/docker_engine/test_docker_metrics.py
import unittest
import time
from collectors.lib.docker_engine.docker_metrics import DockerMetrics
from collectors.lib.docker_engine.metric import Metric

#!/usr/bin/env python
# This file is part of tcollector.
# Copyright (C) 2010-2013  The tcollector Authors.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.  This program is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
# General Public License for more details.  You should have received a copy
# of the GNU Lesser General Public License along with this program.  If not,
# see <http://www.gnu.org/licenses/>.





class TestDockerMetrics(unittest.TestCase):
    def setUp(self):
        self.now = time.gmtime()

        self.line = 'engine_daemon_network_actions_seconds_count{action="connect"} 2'