예제 #1
0
 def __call__(self):
     """Collect metrics."""
     system_metrics.collect_uptime()
     system_metrics.collect_cpu_info()
     system_metrics.collect_disk_info()
     system_metrics.collect_mem_info()
     net_metrics.collect_net_info()
     proc_metrics.collect_proc_info()
     system_metrics.collect_load_avg()
     puppet_metrics.collect_puppet_summary()
     git_metrics.collect_git_metrics()
     self._collect_osinfo()
     system_metrics.collect_unix_time()  # must be just before flush
     metrics.Flush()
예제 #2
0
    def test_collect(self):
        with open(self.tempfile, 'w') as f:
            f.write(_SUMMARY)
        with mock.patch('time.time', return_value=1500000000):
            with mock.patch.object(puppet_metrics, 'LAST_RUN_FILE',
                                   self.tempfile):
                puppet_metrics.collect_puppet_summary()

        setter = self.store.set
        calls = [
            mock.call('puppet/version/config', (),
                      None,
                      1499979608,
                      enforce_ge=mock.ANY),
            mock.call('puppet/version/puppet', (),
                      None,
                      '3.4.3',
                      enforce_ge=mock.ANY),
            mock.call('puppet/events', ('failure', ),
                      None,
                      0,
                      enforce_ge=mock.ANY),
            mock.call('puppet/events', ('success', ),
                      None,
                      7,
                      enforce_ge=mock.ANY),
            mock.call('puppet/resources', ('scheduled', ),
                      None,
                      0,
                      enforce_ge=mock.ANY),
            mock.call('puppet/resources', ('skipped', ),
                      None,
                      1,
                      enforce_ge=mock.ANY),
            mock.call('puppet/resources', ('restarted', ),
                      None,
                      0,
                      enforce_ge=mock.ANY),
            mock.call('puppet/resources', ('changed', ),
                      None,
                      7,
                      enforce_ge=mock.ANY),
            mock.call('puppet/resources', ('failed', ),
                      None,
                      0,
                      enforce_ge=mock.ANY),
            mock.call('puppet/resources', ('other', ),
                      None,
                      203,
                      enforce_ge=mock.ANY),
            mock.call('puppet/resources', ('failed_to_restart', ),
                      None,
                      0,
                      enforce_ge=mock.ANY),
            mock.call('puppet/resources', ('out_of_sync', ),
                      None,
                      7,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('vcsrepo', ),
                      None,
                      23.393381029,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('exec', ),
                      None,
                      11.494792536,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('cron', ),
                      None,
                      0.004638468,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('file_line', ),
                      None,
                      0.003589435,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('config_retrieval', ),
                      None,
                      2.862796974,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('user', ),
                      None,
                      0.001673407,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('file', ),
                      None,
                      0.618018423,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('group', ),
                      None,
                      0.017957332,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('service', ),
                      None,
                      10.242378408,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('package', ),
                      None,
                      4.315027644000001,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('mount', ),
                      None,
                      0.001416499,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('schedule', ),
                      None,
                      0.001541641,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('other', ),
                      None,
                      0.0,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('ini_subsetting', ),
                      None,
                      0.001235189,
                      enforce_ge=mock.ANY),
            mock.call('puppet/times', ('filebucket', ),
                      None,
                      0.000341392,
                      enforce_ge=mock.ANY),
            mock.call('puppet/age', (), None, 20329.0, enforce_ge=mock.ANY),
        ]
        setter.assert_has_calls(calls)
        self.assertEqual(len(setter.mock_calls), len(calls))