示例#1
0
    def test_failed_parse_destinations(self):
        self.config.replication_factor = Mock(return_value=2)
        self.config.destinations = Mock(
            return_value=['192.168.9.13:2124;0', '192.168.9.15:2124:0']
            )

        self.assertRaises(SystemExit, lambda: list(Cluster(self.config)))
示例#2
0
def carbon_lookup():
    parser = common_parser('Lookup where a metric lives in a carbon cluster')

    parser.add_argument('metric',
                        metavar='METRIC',
                        nargs=1,
                        type=str,
                        help='Full metric name to search for')

    parser.add_argument(
        '-s',
        '--short',
        action='store_true',
        help='Only display the address, without port and cluster name')

    args = parser.parse_args()

    config = Config(args.config_file)
    cluster = Cluster(config, args.cluster)

    results = lookup(str(args.metric[0]), cluster)

    if args.short:
        for i, _ in enumerate(results):
            results[i] = results[i].split(':')[0]

    print "\n".join(results)
示例#3
0
    def test_parse_destinations(self):
        self.config.replication_factor = Mock(return_value=2)
        self.config.destinations = Mock(return_value=[
            '192.168.9.13:2124:0', '192.168.9.15:2124:0',
            '192.168.6.20:2124:0', '192.168.6.19:2124:0', '192.168.6.16:2124:0'
        ])

        self.cluster = Cluster(self.config)
        assert self.cluster.ring
示例#4
0
def carbon_hosts():
    parser = common_parser('Return the addresses for all nodes in a cluster')

    args = parser.parse_args()

    config = Config(args.config_file)
    cluster = Cluster(config, args.cluster)

    cluster_hosts = [d[0] for d in cluster.destinations]

    print "\n".join(cluster_hosts)
示例#5
0
    def test_lookup(self):
        self.config.replication_factor = Mock(return_value=2)
        self.config.destinations = Mock(return_value=[
            '192.168.9.13:2124:0', '192.168.9.15:2124:0',
            '192.168.6.20:2124:0', '192.168.6.19:2124:0', '192.168.6.16:2124:0'
        ])

        self.cluster = Cluster(self.config)

        assert lookup('metric.one', self.cluster) == \
            ['192.168.6.16:2124:0', '192.168.6.19:2124:0']
示例#6
0
def carbon_sieve():
    parser = common_parser(
        'Given a list of metrics, output those that belong to a node')

    parser.add_argument(
        '-f',
        '--metrics-file',
        default='-',
        help='File containing metric names to filter, or \'-\' ' +
        'to read from STDIN')

    parser.add_argument('-n',
                        '--node',
                        default="self",
                        help='Filter for metrics belonging to this node')

    parser.add_argument(
        '-I',
        '--invert',
        action='store_true',
        help='Invert the sieve, match metrics that do NOT belong to a node')

    args = parser.parse_args()

    config = Config(args.config_file)
    cluster = Cluster(config, args.cluster)
    invert = args.invert

    if args.metrics_file and args.metrics_file[0] != '-':
        fi = args.metrics_file
    else:
        fi = []

    if args.node:
        match_dests = [args.node]
    else:
        match_dests = local_addresses()

    try:
        for metric in fileinput.input(fi):
            m = metric.strip()
            for match in filterMetrics([m], match_dests, cluster, invert):
                print metric.strip()
    except KeyboardInterrupt:
        sys.exit(1)