Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion exporter/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 14 additions & 1 deletion exporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -103,6 +115,7 @@ func CreateMetricsList(c config.Config) ([]JSONMetric, error) {
KeyJSONPath: metric.Path,
ValueJSONPath: valuePath,
LabelsJSONPaths: variableLabelsValues,
ValueType: valueType,
}
metrics = append(metrics, jsonMetric)
}
Expand Down