Exemplo n.º 1
0
func main() {
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
	flag.Parse()

	ctx := context.Background()
	conn, err := client.NewRpcClient(ctx, *connectAddress)
	if err != nil {
		log.Fatalf("Error connecting to %s: %s", *connectAddress, err)
	}
	defer conn.Close()

	switch os.Args[1] {
	case "get":
		response, err := conn.GetConfig(ctx)
		if err != nil {
			log.Fatal(err)
		}

		fmt.Println(openinstrument.ProtoText(response))

	case "add_loadtest":
		runAddLoadtest(ctx, conn)
	case "slow_add_loadtest":
		runSlowAddLoadtest(ctx)
	}
}
Exemplo n.º 2
0
func main() {
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
	flag.Parse()

	conn, err := grpc.Dial(*connectAddress, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Error connecting to %s: %s", *connectAddress, err)
	}
	defer conn.Close()

	request := &oproto.SplitBlockRequest{
		Block: &oproto.Block{},
	}
	if *endKey != "" {
		request.Block.EndKey = *endKey
	} else if *ID != "" {
		request.Block.Id = *ID
	} else if len(os.Args) > 1 {
		request.Block.Id = os.Args[1]
	} else {
		log.Fatal("Specify either --end_key or --id")
	}

	stub := oproto.NewStoreClient(conn)
	response, err := stub.SplitBlock(context.Background(), request)
	if err != nil {
		log.Fatal(err)
	}

	log.Println(openinstrument.ProtoText(response))
}
Exemplo n.º 3
0
func main() {
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
	flag.Parse()

	conn, err := grpc.Dial(*connectAddress, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Error connecting to %s: %s", *connectAddress, err)
	}
	defer conn.Close()

	request := &oproto.LookupBlockRequest{}
	if *varName != "" {
		request.Variable = variable.NewFromString(*varName).AsProto()
	} else if *ID != "" {
		request.BlockId = *ID
	} else if len(os.Args) > 1 {
		request.BlockId = os.Args[1]
	} else {
		log.Fatal("Specify either --variable or --id")
	}

	stub := oproto.NewStoreClient(conn)
	response, err := stub.LookupBlock(context.Background(), request)
	if err != nil {
		log.Fatal(err)
	}

	log.Println(openinstrument.ProtoText(response))
}
Exemplo n.º 4
0
func updateMember(ctx context.Context, member *oproto.ClusterMember) error {
	if kapi == nil {
		return nil
	}
	data := openinstrument.ProtoText(member)
	_, err := kapi.Set(ctx, fmt.Sprintf("%s/members/%s", clusterEtcdPrefix, member.Name), data, nil)
	return err
}
Exemplo n.º 5
0
func main() {
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
	flag.Parse()

	ctx := context.Background()

	conn, err := grpc.Dial(*connectAddress, grpc.WithInsecure())
	if err != nil {
		log.Fatalf("Error connecting to %s: %s", *connectAddress, err)
	}
	defer conn.Close()
	stub := oproto.NewStoreClient(conn)

	request := &oproto.UpdateRetentionPolicyRequest{
		Item: &oproto.RetentionPolicyItem{},
	}

	if len(os.Args) < 2 {
		log.Fatalf("Invalid command (append/insert/delete)")
	}

	switch os.Args[1] {
	case "append":
		request.Op = oproto.UpdateRetentionPolicyRequest_APPEND
		request.Item = readAndParsePolicy()
	case "insert":
		if len(os.Args) < 3 {
			log.Fatalf("Specify position (0-indexed)")
		}
		position, err := strconv.Atoi(os.Args[2])
		if err != nil {
			log.Fatalf("Invalid position: %s", err)
		}
		request.Op = oproto.UpdateRetentionPolicyRequest_INSERT
		request.Position = uint32(position)
		request.Item = readAndParsePolicy()
	case "delete":
		if len(os.Args) < 3 {
			log.Fatalf("Specify position (0-indexed)")
		}

		position, err := strconv.Atoi(os.Args[2])
		if err != nil {
			log.Fatalf("Invalid position: %s", err)
		}
		request.Op = oproto.UpdateRetentionPolicyRequest_REMOVE
		request.Position = uint32(position)
	default:
		log.Fatalf("Invalid command (append/insert/delete)")
	}

	response, err := stub.UpdateRetentionPolicy(ctx, request)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(openinstrument.ProtoText(response))
}
Exemplo n.º 6
0
func main() {
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
	flag.Parse()
	if len(flag.Args()) < 1 {
		log.Fatal("Specify at least one variable to retrieve")
	}

	q, err := query.Parse(flag.Arg(0))
	if err != nil {
		log.Fatal("Invalid query:", err)
	}

	conn, err := client.NewRpcClient(context.Background(), *connectAddress)
	if err != nil {
		log.Fatalf("Error connecting to %s: %s", *connectAddress, err)
	}
	defer conn.Close()

	request := &oproto.GetRequest{
		Query:        q.AsProto(),
		MaxValues:    uint32(*maxValues),
		MaxVariables: uint32(*maxVariables),
	}

	log.Printf("Sending query: %s", openinstrument.ProtoText(q.AsProto()))
	c, err := conn.Get(context.Background(), request)
	if err != nil {
		log.Fatal(err)
	}

	for response := range c {
		for _, stream := range response.Stream {
			variable := variable.NewFromProto(stream.Variable).String()
			for _, value := range stream.Value {
				fmt.Printf("%s\t%s\t", variable, time.Unix(int64(value.Timestamp/1000), 0))
				if value.StringValue == "" {
					fmt.Printf("%f\n", value.DoubleValue)
				} else {
					fmt.Printf("%s\n", value.StringValue)
				}
			}
		}
	}

}
Exemplo n.º 7
0
func main() {
	log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
	flag.Parse()
	ctx := context.Background()

	conn, err := client.NewRpcClient(ctx, *connectAddress)
	if err != nil {
		log.Fatalf("Error connecting to %s: %s", *connectAddress, err)
	}
	defer conn.Close()
	in, out, err := conn.Add(ctx)
	if err != nil {
		log.Fatal(err)
	}

	snmp := gosnmp.Default
	for _, host := range []string{"192.168.1.1"} {
		snmp.Target = host
		snmp.Community = "public"
		if err := snmp.Connect(); err != nil {
			log.Fatal(err)
		}
		defer snmp.Conn.Close()

		// VDSL-LINE-MIB::vdslPhysCurrLineRate.1 = Gauge32: 20265 kbps
		// VDSL-LINE-MIB::vdslPhysCurrLineRate.2 = Gauge32: 1315 kbps
		oids := []string{"1.3.6.1.2.1.10.97.1.1.2.1.10.1", "1.3.6.1.2.1.10.97.1.1.2.1.10.2"}
		result, err := snmp.Get(oids)
		if err != nil {
			log.Fatal(err)
		}

		request := &oproto.AddRequest{
			Stream: []*oproto.ValueStream{},
		}

		for _, snmpVar := range result.Variables {
			switch snmpVar.Name {
			case ".1.3.6.1.2.1.10.97.1.1.2.1.10.1":
				request.Stream = append(request.Stream, &oproto.ValueStream{
					Variable: variable.NewFromString(fmt.Sprintf("/network/adsl/downstream_rate{host=%s,unit=bps}", host)).AsProto(),
					Value: []*oproto.Value{
						{
							DoubleValue: float64(snmpVar.Value.(uint) * 1000),
							Timestamp:   openinstrument.NowMs(),
						},
					},
				})
			case ".1.3.6.1.2.1.10.97.1.1.2.1.10.2":
				request.Stream = append(request.Stream, &oproto.ValueStream{
					Variable: variable.NewFromString(fmt.Sprintf("/network/adsl/upstream_rate{host=%s,unit=bps}", host)).AsProto(),
					Value: []*oproto.Value{
						{
							DoubleValue: float64(snmpVar.Value.(uint) * 1000),
							Timestamp:   openinstrument.NowMs(),
						},
					},
				})
			}
		}

		in <- request
	}

	close(in)
	for response := range out {
		if !response.Success {
			fmt.Println(openinstrument.ProtoText(response))
		}
	}
}