Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
5d09e453
Unverified
Commit
5d09e453
authored
Jul 20, 2020
by
Ryan McKinley
Committed by
GitHub
Jul 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Azure: convert azure units to grafana units (#26429)
parent
c208c7ca
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
16 deletions
+38
-16
pkg/tsdb/azuremonitor/azuremonitor-datasource.go
+23
-1
pkg/tsdb/azuremonitor/azuremonitor-datasource_test.go
+15
-15
No files found.
pkg/tsdb/azuremonitor/azuremonitor-datasource.go
View file @
5d09e453
...
...
@@ -294,7 +294,7 @@ func (e *AzureMonitorDatasource) parseResponse(queryRes *tsdb.QueryResult, amr A
dataField
.
Name
=
amr
.
Value
[
0
]
.
Name
.
LocalizedValue
dataField
.
Labels
=
labels
dataField
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
amr
.
Value
[
0
]
.
Unit
,
Unit
:
toGrafanaUnit
(
amr
.
Value
[
0
]
.
Unit
)
,
})
if
query
.
Alias
!=
""
{
dataField
.
Config
.
DisplayName
=
formatAzureMonitorLegendKey
(
query
.
Alias
,
query
.
UrlComponents
[
"resourceName"
],
...
...
@@ -386,3 +386,25 @@ func formatAzureMonitorLegendKey(alias string, resourceName string, metricName s
return
string
(
result
)
}
// Map values from:
// https://docs.microsoft.com/en-us/azure/azure-monitor/platform/metrics-supported#microsoftanalysisservicesservers
// to
// https://github.com/grafana/grafana/blob/master/packages/grafana-data/src/valueFormats/categories.ts#L24
func
toGrafanaUnit
(
unit
string
)
string
{
switch
unit
{
case
"Percent"
:
return
"percent"
case
"Count"
:
return
"short"
// this is used for integers
case
"Bytes"
:
return
"decbytes"
// or ICE
case
"BytesPerSecond"
:
return
"Bps"
case
"CountPerSecond"
:
return
"cps"
case
"Milliseconds"
:
return
"ms"
}
return
unit
// this will become a suffix in the display
}
pkg/tsdb/azuremonitor/azuremonitor-datasource_test.go
View file @
5d09e453
...
...
@@ -201,7 +201,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
makeDates
(
time
.
Date
(
2019
,
2
,
8
,
10
,
13
,
0
,
0
,
time
.
UTC
),
5
,
time
.
Minute
)),
data
.
NewField
(
"Percentage CPU"
,
nil
,
[]
float64
{
2.0875
,
2.1525
,
2.155
,
3.6925
,
2.44
,
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
P
ercent"
})),
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
p
ercent"
})),
},
},
{
...
...
@@ -221,7 +221,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
13
,
29
,
0
,
0
,
time
.
UTC
),
5
,
time
.
Minute
)),
data
.
NewField
(
"Percentage CPU"
,
nil
,
[]
float64
{
8.26
,
8.7
,
14.82
,
10.07
,
8.52
,
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
P
ercent"
})),
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
p
ercent"
})),
},
},
{
...
...
@@ -241,7 +241,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
14
,
26
,
0
,
0
,
time
.
UTC
),
5
,
time
.
Minute
)),
data
.
NewField
(
"Percentage CPU"
,
nil
,
[]
float64
{
3.07
,
2.92
,
2.87
,
2.27
,
2.52
,
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
P
ercent"
})),
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
p
ercent"
})),
},
},
{
...
...
@@ -261,7 +261,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
14
,
43
,
0
,
0
,
time
.
UTC
),
5
,
time
.
Minute
)),
data
.
NewField
(
"Percentage CPU"
,
nil
,
[]
float64
{
1.51
,
2.38
,
1.69
,
2.27
,
1.96
,
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
P
ercent"
})),
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
p
ercent"
})),
},
},
{
...
...
@@ -281,7 +281,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
14
,
44
,
0
,
0
,
time
.
UTC
),
5
,
time
.
Minute
)),
data
.
NewField
(
"Percentage CPU"
,
nil
,
[]
float64
{
4
,
4
,
4
,
4
,
4
,
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
P
ercent"
})),
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
p
ercent"
})),
},
},
{
...
...
@@ -300,19 +300,19 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data
.
NewField
(
""
,
nil
,
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
15
,
21
,
0
,
0
,
time
.
UTC
),
6
,
time
.
Hour
)),
data
.
NewField
(
"Blob Count"
,
data
.
Labels
{
"blobtype"
:
"PageBlob"
},
[]
float64
{
3
,
3
,
3
,
3
,
3
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
Coun
t"
})),
[]
float64
{
3
,
3
,
3
,
3
,
3
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
shor
t"
})),
data
.
NewFrame
(
""
,
data
.
NewField
(
""
,
nil
,
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
15
,
21
,
0
,
0
,
time
.
UTC
),
6
,
time
.
Hour
)),
data
.
NewField
(
"Blob Count"
,
data
.
Labels
{
"blobtype"
:
"BlockBlob"
},
[]
float64
{
1
,
1
,
1
,
1
,
1
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
Coun
t"
})),
[]
float64
{
1
,
1
,
1
,
1
,
1
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
shor
t"
})),
data
.
NewFrame
(
""
,
data
.
NewField
(
""
,
nil
,
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
15
,
21
,
0
,
0
,
time
.
UTC
),
6
,
time
.
Hour
)),
data
.
NewField
(
"Blob Count"
,
data
.
Labels
{
"blobtype"
:
"Azure Data Lake Storage"
},
[]
float64
{
0
,
0
,
0
,
0
,
0
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
Coun
t"
})),
[]
float64
{
0
,
0
,
0
,
0
,
0
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
shor
t"
})),
},
},
{
...
...
@@ -333,7 +333,7 @@ func TestAzureMonitorParseResponse(t *testing.T) {
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
13
,
29
,
0
,
0
,
time
.
UTC
),
5
,
time
.
Minute
)),
data
.
NewField
(
"Percentage CPU"
,
nil
,
[]
float64
{
8.26
,
8.7
,
14.82
,
10.07
,
8.52
,
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
P
ercent"
,
DisplayName
:
"custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU"
})),
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
p
ercent"
,
DisplayName
:
"custom grafanastaging Microsoft.Compute/virtualMachines grafana Percentage CPU"
})),
},
},
{
...
...
@@ -353,21 +353,21 @@ func TestAzureMonitorParseResponse(t *testing.T) {
data
.
NewField
(
""
,
nil
,
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
15
,
21
,
0
,
0
,
time
.
UTC
),
6
,
time
.
Hour
)),
data
.
NewField
(
"Blob Count"
,
data
.
Labels
{
"blobtype"
:
"PageBlob"
},
[]
float64
{
3
,
3
,
3
,
3
,
3
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
Coun
t"
,
DisplayName
:
"blobtype=PageBlob"
})),
[]
float64
{
3
,
3
,
3
,
3
,
3
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
shor
t"
,
DisplayName
:
"blobtype=PageBlob"
})),
data
.
NewFrame
(
""
,
data
.
NewField
(
""
,
nil
,
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
15
,
21
,
0
,
0
,
time
.
UTC
),
6
,
time
.
Hour
)),
data
.
NewField
(
"Blob Count"
,
data
.
Labels
{
"blobtype"
:
"BlockBlob"
},
[]
float64
{
1
,
1
,
1
,
1
,
1
,
0
,
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
Coun
t"
,
DisplayName
:
"blobtype=BlockBlob"
})),
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
shor
t"
,
DisplayName
:
"blobtype=BlockBlob"
})),
data
.
NewFrame
(
""
,
data
.
NewField
(
""
,
nil
,
makeDates
(
time
.
Date
(
2019
,
2
,
9
,
15
,
21
,
0
,
0
,
time
.
UTC
),
6
,
time
.
Hour
)),
data
.
NewField
(
"Blob Count"
,
data
.
Labels
{
"blobtype"
:
"Azure Data Lake Storage"
},
[]
float64
{
0
,
0
,
0
,
0
,
0
,
0
,
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
Coun
t"
,
DisplayName
:
"blobtype=Azure Data Lake Storage"
})),
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
shor
t"
,
DisplayName
:
"blobtype=Azure Data Lake Storage"
})),
},
},
{
...
...
@@ -388,21 +388,21 @@ func TestAzureMonitorParseResponse(t *testing.T) {
makeDates
(
time
.
Date
(
2020
,
06
,
30
,
9
,
58
,
0
,
0
,
time
.
UTC
),
3
,
time
.
Hour
)),
data
.
NewField
(
"Blob Capacity"
,
data
.
Labels
{
"blobtype"
:
"PageBlob"
,
"tier"
:
"Standard"
},
[]
float64
{
675530
,
675530
,
675530
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
B
ytes"
,
DisplayName
:
"danieltest {Blob Type=PageBlob, Tier=Standard}"
})),
&
data
.
FieldConfig
{
Unit
:
"
decb
ytes"
,
DisplayName
:
"danieltest {Blob Type=PageBlob, Tier=Standard}"
})),
data
.
NewFrame
(
""
,
data
.
NewField
(
""
,
nil
,
makeDates
(
time
.
Date
(
2020
,
06
,
30
,
9
,
58
,
0
,
0
,
time
.
UTC
),
3
,
time
.
Hour
)),
data
.
NewField
(
"Blob Capacity"
,
data
.
Labels
{
"blobtype"
:
"BlockBlob"
,
"tier"
:
"Hot"
},
[]
float64
{
0
,
0
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
B
ytes"
,
DisplayName
:
"danieltest {Blob Type=BlockBlob, Tier=Hot}"
})),
&
data
.
FieldConfig
{
Unit
:
"
decb
ytes"
,
DisplayName
:
"danieltest {Blob Type=BlockBlob, Tier=Hot}"
})),
data
.
NewFrame
(
""
,
data
.
NewField
(
""
,
nil
,
makeDates
(
time
.
Date
(
2020
,
06
,
30
,
9
,
58
,
0
,
0
,
time
.
UTC
),
3
,
time
.
Hour
)),
data
.
NewField
(
"Blob Capacity"
,
data
.
Labels
{
"blobtype"
:
"Azure Data Lake Storage"
,
"tier"
:
"Cool"
},
[]
float64
{
0
,
0
,
0
})
.
SetConfig
(
&
data
.
FieldConfig
{
Unit
:
"
B
ytes"
,
DisplayName
:
"danieltest {Blob Type=Azure Data Lake Storage, Tier=Cool}"
})),
&
data
.
FieldConfig
{
Unit
:
"
decb
ytes"
,
DisplayName
:
"danieltest {Blob Type=Azure Data Lake Storage, Tier=Cool}"
})),
},
},
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment