Add more debug output and fixed metrics name composing.

This commit is contained in:
Stanislav Nikitin 2020-12-23 22:12:25 +05:00
parent cdfa948b7d
commit 9410522dd5
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
2 changed files with 11 additions and 0 deletions

View File

@ -29,12 +29,17 @@ func (a *Application) parse(body string) map[string]models.Metric {
a.logger.Debugln("Analyzing line:", line)
name = a.getMetricName(line)
a.logger.Debugln("Got metric name:", name)
metric, found := data[name]
if !found {
a.logger.Debugln("Metric wasn't yet created, creating new structure")
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
// or type. It should be handled in special way - these metric will became
// "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.
if strings.Contains(line, "{") {
newMetric := metric
newMetric.Name = newMetric.BaseName
params = a.getParametersForPrometheusMetric(line)
for _, param := range params {
newMetric.Name += "/" + param
}
newMetric.Params = params
metric = newMetric
data[metric.Name] = metric
}

View File

@ -2,6 +2,8 @@ package models
// Metric is a generic metric structure.
type Metric struct {
// BaseName is a metric's base name, used for constructing name.
BaseName string
// Name is a metric name.
Name string
// Description is a metric description from HELP line.
@ -17,6 +19,7 @@ type Metric struct {
// NewMetric creates new structure for storing single metric data.
func NewMetric(name, mType, description string, params []string) Metric {
m := Metric{
BaseName: name,
Name: name,
Description: description,
Type: mType,