예제 #1
0
 def setUp(self):
   config = get_collector_config('DockerStatsCollector', {
     'client_url': 'localhost:4243',
     'name_from_env': None,
     'interval': 1,
   })
   self.collector = DockerStatsCollector(config, None)
예제 #2
0
class TestDockerStatsCollector(CollectorTestCase):
  def setUp(self):
    config = get_collector_config('DockerStatsCollector', {
      'client_url': 'localhost:4243',
      'name_from_env': None,
      'interval': 1,
    })
    self.collector = DockerStatsCollector(config, None)

  def test_import(self):
    self.assertTrue(DockerStatsCollector)

  @patch.object(Collector, 'publish')
  @patch('docker.Client')
  def test_should_publish_values_correctly(self, docker_client_mock, publish_mock):
    client_mock = get_client_mock()
    docker_client_mock.return_value = client_mock
    self.collector.collect()
    metrics = {
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.mem.rss': 100,
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.net.tx_bytes': 100,
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.net.rx_bytes': 100,
    }
    self.assertPublishedMany(publish_mock, metrics)

    self.collector.collect()
    metrics = {
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.mem.rss': 200,
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.net.tx_bytes': 200,
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.net.rx_bytes': 200,
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.cpu0.user': 1,
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.cpu1.user': 2,
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.cpu2.user': 3,
      'test.146979a5328952af505cd43123b45b06c38db8679aaadb2a4c18ad699a5cbeec.cpu3.user': 4,
    }
    self.assertPublishedMany(publish_mock, metrics)