コード例 #1
0
class TestMemoryCollector(CollectorTestCase):
    def setUp(self):
        config = get_collector_config('MemoryCollector', {
            'interval': 10
        })

        self.collector = MemoryCollector(config, None)

    @patch('__builtin__.open')
    @patch.object(Collector, 'publish')
    def test_should_open_proc_meminfo(self, publish_mock, open_mock):
        open_mock.return_value = StringIO('')
        self.collector.collect()
        open_mock.assert_called_once_with('/proc/meminfo')

    @patch.object(Collector, 'publish')
    def test_should_work_with_real_data(self, publish_mock):
        MemoryCollector.PROC = get_fixture_path('proc_meminfo')
        self.collector.collect()

        self.assertPublishedMany(publish_mock, {
            'total'       : '49554212',
            'free'        : '35194496',
            'buffers'     : '1526304',
            'cached'      : '10726736',
            'active'      : '10022168',
            'inactive'    : '2524928',
            'swap_total'  : '262143996',
            'swap_free'   : '262143996',
            'swap_cached' : '0',
            'vm_total'    : '34359738367',
            'vm_used'     : '445452',
            'vm_chunk'    : '34311049240'
        })
コード例 #2
0
class SystemAggregator(object):
    def __init__(self):
        self._cpu_collector = CpuCollector()
        self._disk_collector = DiskCollector()
        self._memory_collector = MemoryCollector()
        self._network_collector = NetworkCollector()

    def get_usage(self):
        return {
            "CPU": self._cpu_collector.get_usage(),
            "Disk": self._disk_collector.get_usage(),
            "Memory": self._memory_collector.get_usage(),
            "Network": self._network_collector.get_usage()
        }

    def get_cpu_usage(self):
        return self._cpu_collector.get_usage()

    def get_disk_usage(self):
        return self._disk_collector.get_usage()

    def get_memory_usage(self):
        return self._memory_collector.get_usage()

    def get_network_usage(self):
        return self._network_collector.get_usage()

    def __str__(self):
        return json.dumps(self.get_usage(), indent=4, sort_keys=True)
コード例 #3
0
    def setUp(self):
        config = get_collector_config('MemoryCollector', {
            'interval': 10
        })

        self.collector = MemoryCollector(config, None)
コード例 #4
0
 def __init__(self):
     self._cpu_collector = CpuCollector()
     self._disk_collector = DiskCollector()
     self._memory_collector = MemoryCollector()
     self._network_collector = NetworkCollector()
コード例 #5
0
ファイル: main.py プロジェクト: strombom/ppo2
    # define model
    model = torch.hub.load('andompesta/ppo2',
                           'ppo2',
                           reset_param=True,
                           force_reload=True,
                           input_dim=obs_size,
                           hidden_dim=args.hidden_dim,
                           action_space=action_space,
                           dropout=0)
    model.to(device)

    # setup training function
    train_fn, optm = step_setup(args, model, device)

    # create memory collector for different episode. Used for batch training
    memory_collector = MemoryCollector(env, model, args.n_step, args.gamma,
                                       args.lam, device)
    ep_info_buf = deque(maxlen=100)

    n_env = 1
    n_batch = n_env * args.n_step
    n_updates = args.total_timesteps // args.batch_size
    n_batch_train = n_batch // args.mini_batchs

    for update in range(1, n_updates + 1):
        assert n_batch % args.mini_batchs == 0

        # Start timer
        frac = 1.0 - (update - 1.0) / n_updates

        if update % args.log_every == 0:
            print('Stepping environment...')