diff --git a/config/config.go b/config/config.go index 5d320a6..2bb4208 100644 --- a/config/config.go +++ b/config/config.go @@ -22,19 +22,28 @@ import ( // Metric contains values that define a metric type Metric struct { - Name string - Path string - Labels map[string]string - Type MetricType - Help string - Values map[string]string + Name string + Path string + Labels map[string]string + Type ScrapeType + ValueType ValueType + Help string + Values map[string]string } -type MetricType string +type ScrapeType string const ( - ValueScrape MetricType = "value" // default - ObjectScrape MetricType = "object" + ValueScrape ScrapeType = "value" // default + ObjectScrape ScrapeType = "object" +) + +type ValueType string + +const ( + ValueTypeGauge ValueType = "gauge" + ValueTypeCounter ValueType = "counter" + ValueTypeUntyped ValueType = "untyped" ) // Config contains metrics and headers defining a configuration @@ -69,6 +78,9 @@ func LoadConfig(configPath string) (Config, error) { if config.Metrics[i].Help == "" { config.Metrics[i].Help = config.Metrics[i].Name } + if config.Metrics[i].ValueType == "" { + config.Metrics[i].ValueType = ValueTypeUntyped + } } return config, nil diff --git a/exporter/collector.go b/exporter/collector.go index 868a1f9..0e588f5 100644 --- a/exporter/collector.go +++ b/exporter/collector.go @@ -32,10 +32,11 @@ type JSONMetricCollector struct { type JSONMetric struct { Desc *prometheus.Desc - Type config.MetricType + Type config.ScrapeType KeyJSONPath string ValueJSONPath string LabelsJSONPaths []string + ValueType prometheus.ValueType } func (mc JSONMetricCollector) Describe(ch chan<- *prometheus.Desc) { diff --git a/exporter/util.go b/exporter/util.go index 4d6966a..76d6769 100644 --- a/exporter/util.go +++ b/exporter/util.go @@ -63,8 +63,19 @@ func SanitizeValue(s string) (float64, error) { } func CreateMetricsList(c config.Config) ([]JSONMetric, error) { - var metrics []JSONMetric + var ( + metrics []JSONMetric + valueType prometheus.ValueType + ) for _, metric := range c.Metrics { + switch metric.ValueType { + case config.ValueTypeGauge: + valueType = prometheus.GaugeValue + case config.ValueTypeCounter: + valueType = prometheus.CounterValue + default: + valueType = prometheus.UntypedValue + } switch metric.Type { case config.ValueScrape: var variableLabels, variableLabelsValues []string @@ -82,6 +93,7 @@ func CreateMetricsList(c config.Config) ([]JSONMetric, error) { ), KeyJSONPath: metric.Path, LabelsJSONPaths: variableLabelsValues, + ValueType: valueType, } metrics = append(metrics, jsonMetric) case config.ObjectScrape: @@ -103,6 +115,7 @@ func CreateMetricsList(c config.Config) ([]JSONMetric, error) { KeyJSONPath: metric.Path, ValueJSONPath: valuePath, LabelsJSONPaths: variableLabelsValues, + ValueType: valueType, } metrics = append(metrics, jsonMetric) }