diff --git a/internal/application/parser.go b/internal/application/parser.go index c2ab3af..f964735 100644 --- a/internal/application/parser.go +++ b/internal/application/parser.go @@ -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 } diff --git a/internal/models/metric.go b/internal/models/metric.go index 42d45f9..5e2f3c6 100644 --- a/internal/models/metric.go +++ b/internal/models/metric.go @@ -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,