Add more debug output and fixed metrics name composing.
This commit is contained in:
parent
cdfa948b7d
commit
9410522dd5
@ -29,12 +29,17 @@ func (a *Application) parse(body string) map[string]models.Metric {
|
|||||||
a.logger.Debugln("Analyzing line:", line)
|
a.logger.Debugln("Analyzing line:", line)
|
||||||
|
|
||||||
name = a.getMetricName(line)
|
name = a.getMetricName(line)
|
||||||
|
a.logger.Debugln("Got metric name:", name)
|
||||||
|
|
||||||
metric, found := data[name]
|
metric, found := data[name]
|
||||||
if !found {
|
if !found {
|
||||||
|
a.logger.Debugln("Metric wasn't yet created, creating new structure")
|
||||||
|
|
||||||
metric = models.NewMetric(name, "", "", nil)
|
metric = models.NewMetric(name, "", "", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.logger.Debugf("Got metric to use: %+v\n", metric)
|
||||||
|
|
||||||
// If line is commented - then we have something about metric's description
|
// If line is commented - then we have something about metric's description
|
||||||
// or type. It should be handled in special way - these metric will became
|
// or type. It should be handled in special way - these metric will became
|
||||||
// "pseudometric" which will be used as template for next iterations. For
|
// "pseudometric" which will be used as template for next iterations. For
|
||||||
@ -65,12 +70,15 @@ func (a *Application) parse(body string) map[string]models.Metric {
|
|||||||
// structure copying.
|
// structure copying.
|
||||||
if strings.Contains(line, "{") {
|
if strings.Contains(line, "{") {
|
||||||
newMetric := metric
|
newMetric := metric
|
||||||
|
newMetric.Name = newMetric.BaseName
|
||||||
|
|
||||||
params = a.getParametersForPrometheusMetric(line)
|
params = a.getParametersForPrometheusMetric(line)
|
||||||
for _, param := range params {
|
for _, param := range params {
|
||||||
newMetric.Name += "/" + param
|
newMetric.Name += "/" + param
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newMetric.Params = params
|
||||||
|
|
||||||
metric = newMetric
|
metric = newMetric
|
||||||
data[metric.Name] = metric
|
data[metric.Name] = metric
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@ package models
|
|||||||
|
|
||||||
// Metric is a generic metric structure.
|
// Metric is a generic metric structure.
|
||||||
type Metric struct {
|
type Metric struct {
|
||||||
|
// BaseName is a metric's base name, used for constructing name.
|
||||||
|
BaseName string
|
||||||
// Name is a metric name.
|
// Name is a metric name.
|
||||||
Name string
|
Name string
|
||||||
// Description is a metric description from HELP line.
|
// Description is a metric description from HELP line.
|
||||||
@ -17,6 +19,7 @@ type Metric struct {
|
|||||||
// NewMetric creates new structure for storing single metric data.
|
// NewMetric creates new structure for storing single metric data.
|
||||||
func NewMetric(name, mType, description string, params []string) Metric {
|
func NewMetric(name, mType, description string, params []string) Metric {
|
||||||
m := Metric{
|
m := Metric{
|
||||||
|
BaseName: name,
|
||||||
Name: name,
|
Name: name,
|
||||||
Description: description,
|
Description: description,
|
||||||
Type: mType,
|
Type: mType,
|
||||||
|
Loading…
Reference in New Issue
Block a user