Show information on salactus workers. (slow)
3432
def workers():
    """"""
    counter = Counter()
    for w in Worker.all(connection=worker.connection):
        for q in w.queues:
            counter[q.name] += 1
    import pprint
    pprint.pprint(dict(counter))
341691
def _walk_through(job_dir, display_progress=False):
    '''
    
    '''
    serial = salt.payload.Serial(__opts__)

    for top in os.listdir(job_dir):
        t_path = os.path.join(job_dir, top)

        for final in os.listdir(t_path):
            load_path = os.path.join(t_path, final, '.load.p')
            with salt.utils.files.fopen(load_path, 'rb') as rfh:
                job = serial.load(rfh)

            if not os.path.isfile(load_path):
                continue

            with salt.utils.files.fopen(load_path, 'rb') as rfh:
                job = serial.load(rfh)
            jid = job['jid']
            if display_progress:
                __jid_event__.fire_event(
                    {'message': 'Found JID {0}'.format(jid)},
                    'progress'
                )
            yield jid, job, t_path, final
889349
def active(display_progress=False):
    '''
    
    '''
    ret = {}
    client = salt.client.get_local_client(__opts__['conf_file'])
    try:
        active_ = client.cmd('*', 'saltutil.running', timeout=__opts__['timeout'])
    except SaltClientError as client_error:
        print(client_error)
        return ret

    if display_progress:
        __jid_event__.fire_event({
            'message': 'Attempting to contact minions: {0}'.format(list(active_.keys()))
            }, 'progress')
    for minion, data in six.iteritems(active_):
        if display_progress:
            __jid_event__.fire_event({'message': 'Received reply from minion {0}'.format(minion)}, 'progress')
        if not isinstance(data, list):
            continue
        for job in data:
            if not job['jid'] in ret:
                ret[job['jid']] = _format_jid_instance(job['jid'], job)
                ret[job['jid']].update({'Running': [{minion: job.get('pid', None)}], 'Returned': []})
            else:
                ret[job['jid']]['Running'].append({minion: job['pid']})

    mminion = salt.minion.MasterMinion(__opts__)
    for jid in ret:
        returner = _get_returner((__opts__['ext_job_cache'], __opts__['master_job_cache']))
        data = mminion.returners['{0}.get_jid'.format(returner)](jid)
        if data:
            for minion in data:
                if minion not in ret[jid]['Returned']:
                    ret[jid]['Returned'].append(minion)

    return ret
676767
def _get_cron_info():
    '''
    
    '''
    owner = 'root'
    if __grains__['os'] == 'FreeBSD':
        group = 'wheel'
        crontab_dir = '/var/cron/tabs'
    elif __grains__['os'] == 'OpenBSD':
        group = 'crontab'
        crontab_dir = '/var/cron/tabs'
    elif __grains__['os_family'] == 'Solaris':
        group = 'root'
        crontab_dir = '/var/spool/cron/crontabs'
    elif __grains__['os'] == 'MacOS':
        group = 'wheel'
        crontab_dir = '/usr/lib/cron/tabs'
    else:
        group = 'root'
        crontab_dir = '/var/spool/cron'
    return owner, group, crontab_dir
1055739
def view_task_info(token, dstore):
    
    args = token.split(':')[1:]  # called as task_info:task_name
    if args:
        [task] = args
        array = dstore['task_info/' + task].value
        rduration = array['duration'] / array['weight']
        data = util.compose_arrays(rduration, array, 'rduration')
        data.sort(order='duration')
        return rst_table(data)

    data = ['operation-duration mean stddev min max outputs'.split()]
    for task in dstore['task_info']:
        val = dstore['task_info/' + task]['duration']
        if len(val):
            data.append(stats(task, val))
    if len(data) == 1:
        return 'Not available'
    return rst_table(data)
329642
def show():
    """"""
    items = list(collection.find())
    # JSON conversion chokes on the _id objects, so we convert
    # them to strings here
    for i in items:
        i['_id'] = str(i['_id'])
    return items
157162
def showHostDivision(self, headless):
        """"""
        scoop.logger.info('Worker d--istribution: ')
        for worker, number in self.worker_hosts:
            first_worker = (worker == self.worker_hosts[0][0])
            scoop.logger.info('   {0}:\t{1} {2}'.format(
                worker,
                number - 1 if first_worker or headless else str(number),
                "+ origin" if first_worker or headless else "",
                )
            )
329910
def get_worker_report(self, with_memory=False):
        

        greenlets = []
        for greenlet in list(self.gevent_pool):
            g = {}
            short_stack = []
            stack = traceback.format_stack(greenlet.gr_frame)
            for s in stack[1:]:
                if "/gevent/hub.py" in s:
                    break
                short_stack.append(s)
            g["stack"] = short_stack

            job = get_current_job(id(greenlet))
            if job:
                job.save()
                if job.data:
                    g["path"] = job.data["path"]
                g["datestarted"] = job.datestarted
                g["id"] = str(job.id)
                g["time"] = getattr(greenlet, "_trace_time", 0)
                g["switches"] = getattr(greenlet, "_trace_switches", None)

                # pylint: disable=protected-access
                if job._current_io is not None:
                    g["io"] = job._current_io

            greenlets.append(g)

        # When faking network latency, all sockets are affected, including OS ones, but
        # we still want reliable reports so this is disabled.
        if (not with_memory) or (self.config["add_network_latency"] != "0" and self.config["add_network_latency"]):
            cpu = {
                "user": 0,
                "system": 0,
                "percent": 0
            }
            mem = {"rss": 0, "swap": 0, "total": 0}
        else:
            cpu_times = self.process.cpu_times()
            cpu = {
                "user": cpu_times.user,
                "system": cpu_times.system,
                "percent": self.process.cpu_percent(0)
            }
            mem = self.get_memory()

        # Avoid sharing passwords or sensitive config!
        whitelisted_config = [
            "max_jobs",
            "max_memory"
            "greenlets",
            "processes",
            "queues",
            "dequeue_strategy",
            "scheduler",
            "name",
            "local_ip",
            "external_ip",
            "agent_id",
            "worker_group"
        ]

        io = None
        if self._traced_io:
            io = {}
            for k, v in iteritems(self._traced_io):
                if k == "total":
                    io[k] = v
                else:
                    io[k] = sorted(list(v.items()), reverse=True, key=lambda x: x[1])

        used_pool_slots = len(self.gevent_pool)
        used_avg = self.pool_usage_average.next(used_pool_slots)

        return {
            "status": self.status,
            "config": {k: v for k, v in iteritems(self.config) if k in whitelisted_config},
            "done_jobs": self.done_jobs,
            "usage_avg": used_avg / self.pool_size,
            "datestarted": self.datestarted,
            "datereported": datetime.datetime.utcnow(),
            "name": self.name,
            "io": io,
            "_id": str(self.id),
            "process": {
                "pid": self.process.pid,
                "cpu": cpu,
                "mem": mem
                # https://code.google.com/p/psutil/wiki/Documentation
                # get_open_files
                # get_connections
                # get_num_ctx_switches
                # get_num_fds
                # get_io_counters
                # get_nice
            },
            "jobs": greenlets
        }
266563
protected function showInformation(): void
    {
        $swOpts    = $this->swooleSettings;
        $settings  = $this->serverSettings;
        $panelData = [
            'System Info'    => [
                'PHP Version'    => PHP_VERSION,
                'Operate System' => PHP_OS,
            ],
            'Swoole Info'    => [
                'version'   => SWOOLE_VERSION,
                'coroutine' => class_exists(Coroutine::class, false),
            ],
            'Swoole Config'  => [
                'dispatch_mode'   => $swOpts['dispatch_mode'],
                'worker_num'      => $swOpts['worker_num'],
                'task_worker_num' => $swOpts['task_worker_num'],
                'max_request'     => $swOpts['max_request'],
            ],
            'Main Server'    => [
                'type'  => $settings['type'],
                'mode'  => $settings['mode'],
                'host'  => $settings['host'],
                'port'  => $settings['port'],
                'class' => static::class,
            ],
            'Project Config' => [
                'name'        => $this->name,
                'path'        => $this->config['rootPath'],
                'auto_reload' => $this->config['auto_reload'],
                'pidFile'     => $this->config['pidFile'],
            ],
            'Server Log'     => $this->config['log'],
        ];

        // 'Server Information'
        Show::mList($panelData, [
            'ucfirst' => false,
        ]);
        // Show::panel($panelData, 'Server Information');
    }
1007872
function getIndexDetails(client, namespace, done) {
  var tasks = {
    client: attach.bind(null, client),
    namespace: attach.bind(null, namespace),
    getIndexes: ['client', 'namespace', getIndexes],
    getIndexStats: ['client', 'namespace', getIndexStats],
    getIndexSizes: ['client', 'namespace', getIndexSizes],
    indexes: [
      'getIndexes',
      'getIndexStats',
      'getIndexSizes',
      combineStatsAndIndexes
    ]
  };

  async.auto(tasks, function(err, results) {
    if (err) {
      // report error
      return done(err);
    }
    // all info was collected in indexes
    return done(null, results.indexes);
  });
}
372194
def info(path):
  '''  '''

  output, err = cli_syncthing_adapter.info(folder=path)

  if err:
    click.echo(output, err=err)
  else:
    stat = output['status']
    click.echo("State: %s" % stat['state'])
    click.echo("\nTotal Files: %s" % stat['localFiles'])
    click.echo("Files Needed: %s" % stat['needFiles'])
    click.echo("\nTotal Bytes: %s" % stat['localBytes'])
    click.echo("Bytes Needed: %s" % stat['needBytes'])

    progress = output['files_needed']['progress']
    queued = output['files_needed']['queued']
    rest = output['files_needed']['rest']

    if len(progress) or len(queued) or len(rest):
      click.echo("\nFiles Needed:")

    for f in progress:
      click.echo("  " + f['name'])

    for f in queued:
      click.echo("  " + f['name'])

    for f in rest:
      click.echo("  " + f['name'])

    click.echo("\nDevices Authorized:\n%s" % output['auth_ls'])
1123413
def view_job_info(token, dstore):
    
    data = [['task', 'sent', 'received']]
    for task in dstore['task_info']:
        dset = dstore['task_info/' + task]
        if 'argnames' in dset.attrs:
            argnames = dset.attrs['argnames'].split()
            totsent = dset.attrs['sent']
            sent = ['%s=%s' % (a, humansize(s))
                    for s, a in sorted(zip(totsent, argnames), reverse=True)]
            recv = dset['received'].sum()
            data.append((task, ' '.join(sent), humansize(recv)))
    return rst_table(data)
617898
def show_info(ulog, verbose):
    """"""
    m1, s1 = divmod(int(ulog.start_timestamp/1e6), 60)
    h1, m1 = divmod(m1, 60)
    m2, s2 = divmod(int((ulog.last_timestamp - ulog.start_timestamp)/1e6), 60)
    h2, m2 = divmod(m2, 60)
    print("Logging start time: {:d}:{:02d}:{:02d}, duration: {:d}:{:02d}:{:02d}".format(
        h1, m1, s1, h2, m2, s2))

    dropout_durations = [dropout.duration for dropout in ulog.dropouts]
    if len(dropout_durations) == 0:
        print("No Dropouts")
    else:
        print("Dropouts: count: {:}, total duration: {:.1f} s, max: {:} ms, mean: {:} ms"
              .format(len(dropout_durations), sum(dropout_durations)/1000.,
                      max(dropout_durations),
                      int(sum(dropout_durations)/len(dropout_durations))))

    version = ulog.get_version_info_str()
    if not version is None:
        print('SW Version: {}'.format(version))

    print("Info Messages:")
    for k in sorted(ulog.msg_info_dict):
        if not k.startswith('perf_') or verbose:
            print(" {0}: {1}".format(k, ulog.msg_info_dict[k]))


    if len(ulog.msg_info_multiple_dict) > 0:
        if verbose:
            print("Info Multiple Messages:")
            for k in sorted(ulog.msg_info_multiple_dict):
                print(" {0}: {1}".format(k, ulog.msg_info_multiple_dict[k]))
        else:
            print("Info Multiple Messages: {}".format(
                ", ".join(["[{}: {}]".format(k, len(ulog.msg_info_multiple_dict[k])) for k in
                           sorted(ulog.msg_info_multiple_dict)])))



    print("")
    print("{:<41} {:7}, {:10}".format("Name (multi id, message size in bytes)",
                                      "number of data points", "total bytes"))

    data_list_sorted = sorted(ulog.data_list, key=lambda d: d.name + str(d.multi_id))
    for d in data_list_sorted:
        message_size = sum([ULog.get_field_size(f.type_str) for f in d.field_data])
        num_data_points = len(d.data['timestamp'])
        name_id = "{:} ({:}, {:})".format(d.name, d.multi_id, message_size)
        print(" {:<40} {:7d} {:10d}".format(name_id, num_data_points,
                                            message_size * num_data_points))
698852
def monitor(ctx, details):
    
    ingest_config_obj(ctx, silent=False)

    show_colors = ctx.obj['show_color']

    event_display = {
        JobEventName.Started: {'color': 'blue', 'label': 'started'},
        JobEventName.Succeeded: {'color': 'green', 'label': 'succeeded'},
        JobEventName.Stopped: {'color': 'yellow', 'label': 'stopped'},
        JobEventName.Aborted: {'color': 'red', 'label': 'aborted'}
    }

    click.echo('\n')
    click.echo('{:>10} {:>12} {:25} {:18} {:16} {:28} {}'.format(
        'Status',
        'Type',
        'Name',
        'Duration (sec)',
        'Queue' if details else '',
        'Workflow ID' if details else '',
        'Worker' if details else ''))

    click.echo('-' * (136 if details else 65))

    for event in workflow_events(ctx.obj['config']):
        evt_disp = event_display[event.event]
        click.echo('{:>{}} {:>{}} {:25} {:18} {:16} {:28} {}'.format(
            _style(show_colors, evt_disp['label'], fg=evt_disp['color']),
            20 if show_colors else 10,
            _style(show_colors, event.type, bold=True, fg=JOB_COLOR[event.type]),
            24 if show_colors else 12,
            event.name,
            '{0:.3f}'.format(event.duration) if event.duration is not None else '',
            event.queue if details else '',
            event.workflow_id if details else '',
            event.hostname if details else ''))
124356
def view_all_work_queues():
    """"""
    count_list = list(
        db.session.query(
            work_queue.WorkQueue.queue_name,
            work_queue.WorkQueue.status,
            func.count(work_queue.WorkQueue.task_id))
        .group_by(work_queue.WorkQueue.queue_name,
                  work_queue.WorkQueue.status))

    queue_dict = {}
    for name, status, count in count_list:
        queue_dict[(name, status)] = dict(
            name=name, status=status, count=count)

    max_created_list = list(
        db.session.query(
            work_queue.WorkQueue.queue_name,
            work_queue.WorkQueue.status,
            func.max(work_queue.WorkQueue.created))
        .group_by(work_queue.WorkQueue.queue_name,
                  work_queue.WorkQueue.status))

    for name, status, newest_created in max_created_list:
        queue_dict[(name, status)]['newest_created'] = newest_created

    min_eta_list = list(
        db.session.query(
            work_queue.WorkQueue.queue_name,
            work_queue.WorkQueue.status,
            func.min(work_queue.WorkQueue.eta))
        .group_by(work_queue.WorkQueue.queue_name,
                  work_queue.WorkQueue.status))

    for name, status, oldest_eta in min_eta_list:
        queue_dict[(name, status)]['oldest_eta'] = oldest_eta

    queue_list = list(queue_dict.values())
    queue_list.sort(key=lambda x: (x['name'], x['status']))

    context = dict(
        queue_list=queue_list,
    )
    return render_template('view_work_queue_index.html', **context)
815443
def info():
    """"""
    rc = texinfo()
    print('Running Texinfo files through makeinfo...')
    builddir = os.path.join(BUILDDIR, 'texinfo')
    subprocess.call(['make', '-C', builddir, 'info'])
    print('makeinfo finished; the Info files are in {}.'.format(builddir))
1243020
function executorSummary(computers) {

  var data = {};

  computers.forEach(function (computer) {

    var idleCount   = 0;
    var activeCount = 0;

    data[computer.displayName] = { executors: [] };

    computer.executors.forEach(function (executor) {
      data[computer.displayName].executors.push({
        idle: executor.idle,
        stuck: executor.likelyStuck,
        progress: executor.progress,
        name: (!executor.idle && executor.currentExecutable.url) ?
          executor.currentExecutable.url.replace(/.*\/job\//, '').replace(/\/.*/, '') :
          undefined
      });

      if (executor.idle) {
        idleCount += 1;
      } else {
        activeCount += 1;
      }
    });

    var summary = [];
    if (activeCount > 0) {
      summary.push(text.__('%d active', activeCount));
    }
    if (idleCount > 0) {
      summary.push(text.__('%d idle', idleCount));
    }

    data[computer.displayName].summary = summary.join(', ');
  });

  return data;
}