Skip to content

Commit

Permalink
Merge pull request #61 from utkarshmani1997/master
Browse files Browse the repository at this point in the history
Update vsm-stats command with latest mayaserver apis
  • Loading branch information
kmova authored Jun 23, 2017
2 parents 5bf7d04 + 5de8b29 commit 9b10ddf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 47 deletions.
37 changes: 21 additions & 16 deletions command/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ type Volume struct {

// Annotations describes volume struct
type Annotations struct {
VolSize string `json:"be.jiva.volume.openebs.io\/vol-size"`
// VolAddr string `json:"fe.jiva.volume.openebs.io/ip"`
Iqn string `json:"iqn"`
Targetportal string `json:"targetportal"`
// Replicas []string `json:"JIVA_REP_IP_*"`
ReplicaCount string `json:"be.jiva.volume.openebs.io\/count"`
TargetPortal string `json:"vsm.openebs.io/targetportals"`
ClusterIP string `json:"vsm.openebs.io/cluster-ips"`
Iqn string `json:"vsm.openebs.io/iqn"`
ReplicaCount string `json:"vsm.openebs.io/replica-count"`
ControllerStatus string `json:"vsm.openebs.io/controller-status"`
ReplicaStatus string `json:"vsm.openebs.io/replica-status"`
VolSize string `json:"vsm.openebs.io/volume-size"`
ControllerIP string `json:"vsm.openebs.io/controller-ips"`
VolAddr string `json:"vsm.openebs.io/replica-ips"`
Replicas string `json:"vsm.openebs.io/replica-ips"`
}

const (
Expand Down Expand Up @@ -96,21 +100,22 @@ func GetVolAnnotations(volName string) (*Annotations, error) {
}
for key, value := range volume.Metadata.Annotations.(map[string]interface{}) {
switch key {
case "be.jiva.volume.openebs.io/vol-size":
case "vsm.openebs.io/volume-size":
annotations.VolSize = value.(string)
// case "fe.jiva.volume.openebs.io/ip":
// annotations.VolAddr = value.(string)
case "iqn":
case "vsm.openebs.io/iqn":
annotations.Iqn = value.(string)
case "be.jiva.volume.openebs.io/count":
case "vsm.openebs.io/replica-count":
annotations.ReplicaCount = value.(string)
case "targetportal":
annotations.Targetportal = value.(string)
// case "JIVA_REP_IP_0":
// annotations.Replicas = append(annotations.Replicas, value.(string))
// case "JIVA_REP_IP_1":
// annotations.Replicas = append(annotations.Replicas, value.(string))

case "vsm.openebs.io/cluster-ips":
annotations.ClusterIP = value.(string)
case "vsm.openebs.io/replica-ips":
annotations.Replicas = value.(string)
case "vsm.openebs.io/targetportals":
annotations.TargetPortal = value.(string)
case "vsm.openebs.io/controller-status":
annotations.ControllerStatus = value.(string)
}
}
return &annotations, nil
Expand Down
61 changes: 30 additions & 31 deletions command/vsm_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ func (c *VsmStatsCommand) Run(args []string) int {

var (
err, err1, err2 error
//status Status
stats1 VolumeStats
stats2 VolumeStats
//statusArray []string
ReadLatency int64
WriteLatency int64
status Status
stats1 VolumeStats
stats2 VolumeStats
statusArray []string
ReadLatency int64
WriteLatency int64

AvgReadBlockCountPS int64
AvgWriteBlockCountPS int64
Expand All @@ -126,30 +126,31 @@ func (c *VsmStatsCommand) Run(args []string) int {

annotations, err := GetVolAnnotations(args[0])
if err != nil || annotations == nil {
fmt.Println(err)
return -1
}
/*
for _, replica := range annotations.Replicas {
err, errCode1 := GetStatus(replica+":9502", &status)
if err != nil {
if errCode1 == 500 || strings.Contains(err.Error(), "EOF") {
statusArray = append(statusArray, fmt.Sprintf("%-15s %-12s%-10s", replica, "Waiting", "Unknown"))
} else {
statusArray = append(statusArray, fmt.Sprintf("%-15s %-12s%-10s", replica, "Offline", "Unknown"))
}
if annotations.ControllerStatus != "Running" {
fmt.Println("Volume not reachable")
return -1
}
replicas := strings.Split(annotations.Replicas, ",")
for _, replica := range replicas {
err, errCode1 := GetStatus(replica+":9502", &status)
if err != nil {
if errCode1 == 500 || strings.Contains(err.Error(), "EOF") {
statusArray = append(statusArray, fmt.Sprintf("%-15s %-12s%-10s", replica, "Waiting", "Unknown"))

} else {
statusArray = append(statusArray, fmt.Sprintf("%-15s %-10s %d", replica, "Online", status.RevisionCounter))
statusArray = append(statusArray, fmt.Sprintf("%-15s %-12s%-10s", replica, "Offline", "Unknown"))
}
} else {
statusArray = append(statusArray, fmt.Sprintf("%-15s %-10s %d", replica, "Online", status.RevisionCounter))
}
*/
}

//Get VolumeStats
parts := strings.Split(annotations.Targetportal, ":")
volumeAddr := parts[0]
err1, _ = GetVolumeStats(volumeAddr+":9501", &stats1)
err1, _ = GetVolumeStats(annotations.ClusterIP+":9501", &stats1)
time.Sleep(1 * time.Second)
err2, _ = GetVolumeStats(volumeAddr+":9501", &stats2)
err2, _ = GetVolumeStats(annotations.ClusterIP+":9501", &stats2)

if (err1 != nil) || (err2 != nil) {
fmt.Println("Volume not reachable")
Expand Down Expand Up @@ -204,7 +205,7 @@ func (c *VsmStatsCommand) Run(args []string) int {

IQN: annotations.Iqn,
Volume: args[0],
Portal: annotations.Targetportal,
Portal: annotations.TargetPortal,
Size: annotations.VolSize,

ReadIOPS: ReadIOPSPS,
Expand Down Expand Up @@ -234,15 +235,13 @@ func (c *VsmStatsCommand) Run(args []string) int {
} else {
fmt.Printf("%7s: %-48s\n", "IQN", annotations.Iqn)
fmt.Printf("%7s: %-16s\n", "Volume", args[0])
fmt.Printf("%7s: %-15s\n", "Portal", annotations.Targetportal)
fmt.Printf("%7s: %-15s\n", "Portal", annotations.TargetPortal)
fmt.Printf("%7s: %-6s\n\n", "Size", annotations.VolSize)
/*
fmt.Printf("%s %s %s\n", "Replica", "Status", "DataUpdateIndex")
fmt.Printf("%s %s %s\n", "Replica", "Status", "DataUpdateIndex")

for i, _ := range statusArray {
fmt.Printf("%s\n", statusArray[i])
}
*/
for i, _ := range statusArray {
fmt.Printf("%s\n", statusArray[i])
}
fmt.Println("------------------------------------")

// Printing in tabular form
Expand Down

0 comments on commit 9b10ddf

Please sign in to comment.