This repository has been archived by the owner on Nov 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SDI-1394 a metric can be changed from static to dynamic
- Loading branch information
1 parent
93f40c3
commit e58015d
Showing
4 changed files
with
153 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
|
||
# Snap Static and Dynamic Metrics | ||
|
||
Snap Framework supports two types of metrics. They are static and dynamic metrics. A Snap metric consists of a namespace and value pair. | ||
|
||
### Static Metrics | ||
A namespace having no wildcard and only string literals separated by slashes is a static metric. | ||
|
||
String representation examples: | ||
``` | ||
/intel/cassandra/node/zeus/type/Cache/scope/KeyCache/name/Requests/OneMinuteRate | ||
/intel/cassandra/node/zeus/type/ClientRequest/scope/CASRead/name/Unavailables/FiveMinuteRate | ||
/intel/cassandra/node/apollo/type/Cache/scope/RowCache/name/Hits/OneMinuteRate | ||
/intel/cassandra/node/apollo/type/ClientRequest/scope/RangeSlice/name/Latency/OneMinuteRate | ||
``` | ||
### Dynamic Metrics | ||
A namespace including at least one wildcard is a dynamic metric. | ||
|
||
String representation examples: | ||
``` | ||
/intel/cassandra/node/*/type/*/scope/*/name/*/OneMinuteRate | ||
/intel/cassandra/node/*/type/*/scope/*/name/*/FiveMinuteRate | ||
/intel/cassandra/node/*/type/*/keyspace/*/name/*/OneMinuteRate | ||
/intel/cassandra/node/*/type/*/keyspace/*/name/*/FiveMinuteRate | ||
``` | ||
### Namespace Element | ||
Namespace element in Snap is defined as a struct. Both static and dynamic elements share the same definition. | ||
``` | ||
type NamespaceElement struct { | ||
Value string | ||
Description string | ||
Name string | ||
} | ||
``` | ||
The _`NamespaceElement`_ forms each cell of a namespace and those cells are separated by slashes. | ||
|
||
Create a dynamic element: | ||
``` | ||
ns := core.NewNamespace("intel", "cassandra", "node") | ||
.AddDynamicElement("node name", "description") | ||
``` | ||
|
||
Create multiple dynamic elements: | ||
``` | ||
ns := core.NewNamespace("intel", "cassandra", "node") | ||
.AddDynamicElement("node name", "description") | ||
.AddStaticElement("type") | ||
.AddDynamicElement("type value", "description") | ||
.AddStaticElement("scope") | ||
.AddDynamicElement("scope value", "description") | ||
.AddStaticElement("name") | ||
.AddDynamicElement("name value", "description") | ||
.AddStaticElement("50thPercentile") | ||
``` | ||
>The key takeaway is that the _`named element`_ is a _`dynamic element`_. A static element has an _`empty Name`_ field. | ||
### Collector Plugins | ||
Building a Snap collector plugin involves two primary tasks. One is to create a collector metric catalog. Another is to collect metric data. | ||
|
||
##### Create Metric Catalog | ||
Creating a collector having dynamic metric catalog by utilizing the following Snap methods from the _`core`_ package, Snap CLI(snapctl) verbose output could display the definition and the description of a wildcard. | ||
|
||
Methods: | ||
``` | ||
(n Namespace) AddStaticElement(value string) Namespace | ||
(n Namespace) AddDynamicElement(name, description string) Namespace | ||
(n Namespace) AddStaticElements(values ...string) Namespace | ||
``` | ||
|
||
Create Metric Catalog: | ||
``` | ||
metricType := plugin.MetricType{ | ||
Namespace_: ns, | ||
Unit_: <namesapce measurement type>, | ||
} | ||
``` | ||
If the `Unit` is defined, Snap CLI verbose output can show the metric data type too. | ||
|
||
Snap CLI verbose output: | ||
``` | ||
$ $SNAP_PATH/bin/snapctl metric list --verbose | ||
/intel/cassandra/node/[node name]/type/[type value]/scope/[scope value]/name/[name value]/OneMinuteRate float64 | ||
/intel/cassandra/node/[node name]/type/[type value]/scope/[scope value]/name/[name value]/FiveMinuteRate float64 | ||
/intel/cassandra/node/[node name]/type/[type value]/keyspace/[scope value]/name/[name value]/OneMinuteRate float64 | ||
/intel/cassandra/node/[node name]/type/[type value]/keyspace/[scope value]/name/[name value]/FiveMinuteRate float64 | ||
``` | ||
##### Collecting metric data | ||
Snap provides the `IsDynamic() bool` method in its control package to determine an element of the namespace is dynamic or static. For _`IsDynamic`_ to function correctly, collectors need to define the `Name` field for every collected _`dynamic`_ element. | ||
|
||
>Do not use the _`(n Namespace) AddDynamicElement(value string) Namespace`_ method to build dynamic namespace elements for metric data. A metric needs the actual value. Set the dynamic element name using dot notation. | ||
### Publisher Plugins | ||
Snap publisher plugins may leverage the _`IsDynamic() bool`_ method from Snap control package to determine if an element is dynamic or static _`if and only if`_ a collector correctly defined the _`Name`_ field | ||
for every dynamic element. For instance, publisher plugins may base on `IsDynamic()` to strip off dynamic elements from a metric namespace to create searchable Snap metric tags. | ||
|
||
> Snap checks the Name field of a namespace element to determine if an item is static or dynamic. The _`Name`_ field should be empty as a static element while not empty as a dynamic element. | ||
Appropriately define your dynamic element to leverage Snap framework! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters