Example #1
0
def make_dashboards_yaml():
    os.makedirs(get_dashboards_dir(), exist_ok=True)
    with open(path.join(util.get_root_dir(), 'dashboards.yaml'), 'r') as file:
        replacements = {'absolute-path-to-cwd': os.path.abspath('.')}
        contents = templating.replace(file.read(), replacements)
        with open(path.join(get_dashboards_dir(), 'dashboards.yaml'),
                  'w') as file_to_write:
            file_to_write.write(contents)
Example #2
0
def make_dashboards(data_sources, buckets, times):
    os.makedirs(get_dashboards_dir(), exist_ok=True)
    min_time = datetime.datetime.fromtimestamp(times[0] / 1000.0)
    max_time = datetime.datetime.fromtimestamp(times[1] / 1000.0)
    template_params = \
        [{'type': 'data-source-name', 'values': data_sources},
         {'type': 'bucket', 'values': buckets}]
    meta_file_names = glob.glob(
        path.join(util.get_root_dir(), 'dashboards', '*.json'))
    for meta_file_name in meta_file_names:
        with open(meta_file_name, 'r') as meta_file:
            meta = json.loads(meta_file.read())
            base_file_name = path.basename(meta_file_name)
            dash = dashboard.make_dashboard(meta, template_params, min_time,
                                            max_time)
            dash['uid'] = base_file_name[:-len('.json')]
            with open(path.join(get_dashboards_dir(), base_file_name),
                      'w') as file:
                file.write(json.dumps(dash, indent=2))
Example #3
0
 def maybe_start(self, log_dir):
     """
     Starts the Prometheus instance that serves stats for this source.
     """
     log_path = path.join(log_dir, 'prom-{}.log'.format(self._short_name))
     listen_addr = '0.0.0.0:{}'.format(self.port())
     args = [
         Source.PROMETHEUS_BIN, '--config.file',
         path.join(util.get_root_dir(),
                   'noscrape.yml'), '--storage.tsdb.path',
         path.join(self._cbcollect_dir,
                   'stats_snapshot'), '--storage.tsdb.no-lockfile',
         '--storage.tsdb.retention.time', '10y', '--query.lookback-delta',
         '600s', '--web.listen-address', listen_addr
     ]
     logging.info(
         'starting prometheus server on {} against {}; logging to {}'.
         format(listen_addr, path.join(self._cbcollect_dir,
                                       'stats_snapshot'), log_path))
     return util.start_process(args, log_path)
Example #4
0
def make_dashboards(stats_sources, buckets, min_time_string, max_time_string,
                    refresh_string):
    os.makedirs(get_dashboards_dir(), exist_ok=True)
    data_sources = [s.short_name() for s in stats_sources]
    template_params = \
        [{'type': 'data-source-name', 'values': data_sources},
         {'type': 'bucket', 'values': buckets}]
    meta_file_names = glob.glob(
        path.join(util.get_root_dir(), 'dashboards', '*.json'))
    for meta_file_name in meta_file_names:
        with open(meta_file_name, 'r') as meta_file:
            meta = json.loads(meta_file.read())
            base_file_name = path.basename(meta_file_name)
            dash = dashboard.make_dashboard(meta, template_params,
                                            min_time_string, max_time_string,
                                            refresh_string)
            dash['uid'] = base_file_name[:-len('.json')]
            with open(path.join(get_dashboards_dir(), base_file_name),
                      'w') as file:
                file.write(json.dumps(dash, indent=2))
Example #5
0
def start_prometheuses(cbcollects, base_port, log_dir):
    nodes = []
    for i, cbcollect in enumerate(cbcollects):
        log_path = path.join(log_dir, 'prom-{}.log'.format(i))
        listen_addr = '0.0.0.0:{}'.format(base_port + i)
        args = [
            PROMETHEUS_BIN, '--config.file',
            path.join(util.get_root_dir(),
                      'noscrape.yml'), '--storage.tsdb.path',
            path.join(cbcollect,
                      'stats_snapshot'), '--storage.tsdb.retention.time',
            '10y', '--web.listen-address', listen_addr
        ]
        logging.info(
            'starting prometheus server {} (on {}; logging to {})'.format(
                i, listen_addr, log_path))
        node = util.start_process(args, log_path)
        nodes.append(node)

    return nodes
Example #6
0
def get_home_dashboard():
    with open(path.join(util.get_root_dir(), 'home.json'), 'r') as file:
        return file.read()
Example #7
0
def get_custom_ini_template():
    with open(path.join(util.get_root_dir(), 'custom.ini'), 'r') as file:
        return file.read()
Example #8
0
def get_data_source_template():
    with open(path.join(util.get_root_dir(), 'data-source.yaml'), 'r') as file:
        return file.read()
Example #9
0
def get_template(name):
    with open(path.join(util.get_root_dir(), 'templates', name + '.json'), 'r') as file:
        return file.read()
Example #10
0
 def test_get_root_dir(self):
     rd = util.get_root_dir()
     self.assertEqual("BubbleHub", os.path.split(rd)[-1])