Skip to content

Commit

Permalink
Telemetry: Make Driver naming consistent with exporter (#744)
Browse files Browse the repository at this point in the history
*  lvm metric driver naming consistency
  • Loading branch information
NajmudheenCT authored and leonwanghui committed May 19, 2019
1 parent 88af9ae commit 4c9bbbf
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 109 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ubuntu-dev-setup:
sudo apt-get update && sudo apt-get install -y \
build-essential gcc librados-dev librbd-dev

build:osdsdock osdslet osdsapiserver osdsctl
build:osdsdock osdslet osdsapiserver osdsctl metricexporter

prebuild:
mkdir -p $(BUILD_DIR)
Expand All @@ -45,6 +45,8 @@ osdsapiserver: prebuild
osdsctl: prebuild
go build -ldflags '-w -s' -o $(BUILD_DIR)/bin/osdsctl github.com/opensds/opensds/osdsctl

metricexporter: prebuild
go build -ldflags '-w -s' -o $(BUILD_DIR)/bin/lvm_exporter github.com/opensds/opensds/pkg/controller/metrics/exporters/lvm_exporter
docker: build
cp $(BUILD_DIR)/bin/osdsdock ./cmd/osdsdock
cp $(BUILD_DIR)/bin/osdslet ./cmd/osdslet
Expand Down
73 changes: 37 additions & 36 deletions contrib/drivers/lvm/lvm_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,34 @@ var data = `
resources:
- resource: volume
metrics:
- IOPS
- ReadThroughput
- WriteThroughput
- ResponseTime
- ServiceTime
- UtilizationPercentage
- iops
- read_throughput
- write_throughput
- response_time
- service_time
- utilization_prcnt
units:
- tps
- KB/s
- KB/s
- kbs
- kbs
- ms
- ms
- '%'
- resource: pool
- resource: disk
metrics:
- ReadRequests
- WriteRequests
- ReponseTime
- iops
- read_throughput
- write_throughput
- response_time
- service_time
- utilization_prcnt
units:
- tps
- KB/s
- KB/s
- kbs
- kbs
- ms
- ms
- '%'
`
- '%'`

type Config struct {
Resource string
Expand Down Expand Up @@ -91,13 +93,13 @@ func getMetricToUnitMap() map[string]string {

error := yaml.Unmarshal(source, &configs)
if error != nil {
log.Fatalf("Unmarshal error: %v", error)
log.Fatalf("unmarshal error: %v", error)
}
metricToUnitMap := make(map[string]string)
for _, resources := range configs.Cfgs {
switch resources.Resource {
//ToDo: Other Cases needs to be added
case "volume":
case "volume", "disk":
for index, metricName := range resources.Metrics {

metricToUnitMap[metricName] = resources.Units[index]
Expand All @@ -119,19 +121,21 @@ func (d *MetricDriver) ValidateMetricsSupportList(metricList []string, resourceT
source := []byte(data)
error := yaml.Unmarshal(source, &configs)
if error != nil {
log.Fatalf("Unmarshal error: %v", error)
log.Fatalf("unmarshal error: %v", error)
}

for _, resources := range configs.Cfgs {
switch resources.Resource {
//ToDo: Other Cases needs to be added
case "volume":
for _, metricName := range metricList {
if metricInMetrics(metricName, resources.Metrics) {
supportedMetrics = append(supportedMetrics, metricName)

} else {
log.Infof("metric:%s is not in the supported list", metricName)
if resources.Resource == resourceType {
switch resourceType {
//ToDo: Other Cases needs to be added
case "volume", "disk":
for _, metricName := range metricList {
if metricInMetrics(metricName, resources.Metrics) {
supportedMetrics = append(supportedMetrics, metricName)

} else {
log.Infof("metric:%s is not in the supported list", metricName)
}
}
}
}
Expand All @@ -150,16 +154,13 @@ func (d *MetricDriver) CollectMetrics(metricsList []string, instanceID string) (
//validate metric support list
supportedMetrics, err := d.ValidateMetricsSupportList(metricsList, "volume")
if supportedMetrics == nil {
log.Infof("No metrics found in the supported metric list")
log.Infof("no metrics found in the supported metric list")
}
metricMap, err := d.cli.CollectMetrics(supportedMetrics, instanceID)
metricMap, labelMap, err := d.cli.CollectMetrics(supportedMetrics, instanceID)

var tempMetricArray []*model.MetricSpec
for _, element := range metricsList {
val, _ := strconv.ParseFloat(metricMap[element], 64)
//Todo: See if association is required here, resource discovery could fill this information
associatorMap := make(map[string]string)
associatorMap["device"] = metricMap["InstanceName"]
metricValue := &model.Metric{
Timestamp: getCurrentUnixTimestamp(),
Value: val,
Expand All @@ -170,10 +171,10 @@ func (d *MetricDriver) CollectMetrics(metricsList []string, instanceID string) (
metric := &model.MetricSpec{
InstanceID: instanceID,
InstanceName: metricMap["InstanceName"],
Job: "OpenSDS",
Labels: associatorMap,
Job: "lvm",
Labels: labelMap,
//Todo Take Componet from Post call, as of now it is only for volume
Component: "Volume",
Component: "volume",
Name: element,
//Todo : Fill units according to metric type
Unit: metricToUnitMap[element],
Expand Down
14 changes: 7 additions & 7 deletions contrib/drivers/lvm/lvm_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"github.com/opensds/opensds/pkg/utils/exec"
)

var metricMap map[string]float64 = map[string]float64{"IOPS": 3.16, "ReadThroughput": 4.17, "WriteThroughput": 134.74, "ResponseTime": 2.67, "ServiceTime": 4.00, "UtilizationPercentage": 1.26}
var metricToUnitMap map[string]string = map[string]string{"IOPS": "tps", "ReadThroughput": "KB/s", "WriteThroughput": "KB/s", "ResponseTime": "ms", "ServiceTime": "ms", "UtilizationPercentage": "%"}
var metricMap map[string]float64 = map[string]float64{"iops": 3.16, "read_throughput": 4.17, "write_throughput": 134.74, "response_time": 2.67, "service_time": 4.00, "utilization_prcnt": 1.26}
var metricToUnitMap map[string]string = map[string]string{"iops": "tps", "read_throughput": "kbs", "write_throughput": "kbs", "response_time": "ms", "service_time": "ms", "utilization_prcnt": "%"}
var respMap map[string]*MetricFakeResp = map[string]*MetricFakeResp{
"sar": {`05:26:43 IST DEV tps rkB/s wkB/s areq-sz aqu-sz await svctm %util
05:26:44 loop0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Expand All @@ -39,7 +39,7 @@ var respMap map[string]*MetricFakeResp = map[string]*MetricFakeResp{
05:26:44 loop9 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
05:26:44 loop10 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00`, nil},
}
var expctdMetricList []string = []string{"IOPS", "ReadThroughput", "WriteThroughput", "ResponseTime", "ServiceTime", "UtilizationPercentage"}
var expctdMetricList []string = []string{"iops", "read_throughput", "write_throughput", "response_time", "service_time", "utilization_prcnt"}

func TestMetricDriverSetup(t *testing.T) {
var d = &MetricDriver{}
Expand Down Expand Up @@ -104,9 +104,9 @@ func TestCollectMetrics(t *testing.T) {
metric := &model.MetricSpec{
InstanceID: "b902e771-8e02-4099-b601-a6b3881f8",
InstanceName: "opensds--volumes--default-volume--b902e771--8e02--4099--b601--a6b3881f8",
Job: "OpenSDS",
Job: "lvm",
Labels: expctdLabels,
Component: "Volume",
Component: "volume",
Name: element,
Unit: metricToUnitMap[element],
AggrType: "",
Expand Down Expand Up @@ -144,9 +144,9 @@ func TestCollectMetrics(t *testing.T) {

func printMetricSpec(m []*model.MetricSpec) {
for _, p := range m {
fmt.Errorf("%+v\n", p)
fmt.Printf("%+v\n", p)
for _, v := range p.MetricValues {
fmt.Errorf("%+v\n", v)
fmt.Printf("%+v\n", v)
}
}

Expand Down
35 changes: 18 additions & 17 deletions contrib/drivers/lvm/metrics_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func isSarEnabled(out string) bool {
// metricMap -> metric to command output column mapping
// out -> command output
// returnMap -> metric to value map to be returned
func (c *MetricCli) parseCommandOutput(metricList []string, returnMap map[string]string, instanceID string, metricMap map[string]int, out string) {
func (c *MetricCli) parseCommandOutput(metricList []string, returnMap map[string]string, labelMap map[string]string, instanceID string, metricMap map[string]int, out string) {

tableRows := strings.Split(string(out), "\n")

Expand All @@ -85,7 +85,7 @@ func (c *MetricCli) parseCommandOutput(metricList []string, returnMap map[string
val := columns[metricMap[metric]]
returnMap[metric] = val
returnMap["InstanceName"] = columns[metricMap["InstanceID"]]

labelMap["device"] = columns[metricMap["InstanceID"]]
}
}

Expand All @@ -96,9 +96,10 @@ func (c *MetricCli) parseCommandOutput(metricList []string, returnMap map[string
// metricList -> metrics to be collected
// instanceID -> for which instance to be collected
// returnMap -> metrics to value map
func (cli *MetricCli) CollectMetrics(metricList []string, instanceID string) (map[string]string, error) {
func (cli *MetricCli) CollectMetrics(metricList []string, instanceID string) ( /*returnMAp*/ map[string]string /*labelMap*/, map[string]string, error) {

returnMap := make(map[string]string)
labelMap := make(map[string]string)
var err error

cmd := []string{"env", "LC_ALL=C", "sar", "-dp", "1", "1"}
Expand All @@ -115,34 +116,34 @@ func (cli *MetricCli) CollectMetrics(metricList []string, instanceID string) (ma
// sar command output mapping
metricMap := make(map[string]int)
metricMap["InstanceID"] = 1
metricMap["IOPS"] = 2
metricMap["ReadThroughput"] = 3
metricMap["WriteThroughput"] = 4
metricMap["ResponseTime"] = 7
metricMap["ServiceTime"] = 8
metricMap["UtilizationPercentage"] = 9
metricMap["iops"] = 2
metricMap["read_throughput"] = 3
metricMap["write_throughput"] = 4
metricMap["response_time"] = 7
metricMap["service_time"] = 8
metricMap["utilization_prcnt"] = 9
//call parser
cli.parseCommandOutput(metricList, returnMap, instanceID, metricMap, out)
cli.parseCommandOutput(metricList, returnMap, labelMap, instanceID, metricMap, out)
} else {
cmd := []string{"env", "LC_ALL=C", "iostat", "-N"}

out, err := cli.execute(cmd...)

if strings.Contains(string(out), cmdNotFound) {

log.Errorf("iostat is not vaoilable: cmd.Run() failed with %s\n", err)
log.Errorf("iostat is not available: cmd.Run() failed with %s\n", err)
err = nil
} else if err != nil {
log.Errorf("cmd.Run() failed with %s\n", err)
return nil, err
return nil, nil, err
}
metricMap := make(map[string]int)
// iostat command output mapping
metricMap["IOPS"] = 1
metricMap["ReadThroughput"] = 2
metricMap["WriteThroughput"] = 3
cli.parseCommandOutput(metricList, returnMap, instanceID, metricMap, out)
metricMap["iops"] = 1
metricMap["read_throughput"] = 2
metricMap["write_throughput"] = 3
cli.parseCommandOutput(metricList, returnMap, labelMap, instanceID, metricMap, out)

}
return returnMap, err
return returnMap, labelMap, err
}
Loading

0 comments on commit 4c9bbbf

Please sign in to comment.