Skip to content

Commit

Permalink
Rework the goal metrics (remove info and rename)
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroPower committed Sep 23, 2020
1 parent 4d791fa commit 1c4d31b
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions collector/goal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,25 @@ package collector
import (
"io"
"net/url"
"strconv"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)

const (
subsystem = "goal"
endpoint = "goals"
)

const (
goalCollectorName = "goal"
goalSubsystem = "goal"
goalEndpoint = "goals"
)

type goalCollector struct {
goalSeconds *prometheus.Desc
goalProgress *prometheus.Desc
goalInfo *prometheus.Desc
uri url.URL
fetchStat func(url.URL, string, url.Values) (io.ReadCloser, error)
logger log.Logger
goalThreshold *prometheus.Desc
goalProgress *prometheus.Desc
uri url.URL
fetchStat func(url.URL, string, url.Values) (io.ReadCloser, error)
logger log.Logger
}

func init() {
Expand All @@ -51,20 +46,23 @@ func init() {
// NewGoalCollector returns a new Collector exposing all-time stats.
func NewGoalCollector(in CommonInputs, logger log.Logger) (Collector, error) {
return &goalCollector{
goalSeconds: prometheus.NewDesc(
prometheus.BuildFQName(namespace, goalSubsystem, "seconds"),
"The Goal.",
[]string{"name", "id", "type", "delta"}, nil,
goalThreshold: prometheus.NewDesc(
prometheus.BuildFQName(namespace, goalSubsystem, "threshold_seconds"),
"The goal as set through the wakatime interface.",
[]string{
"name", "id", "type", "delta", "enabled",
"ignore_zero_days", "inverse", "snoozed", "tweeting",
},
nil,
),
goalProgress: prometheus.NewDesc(
prometheus.BuildFQName(namespace, goalSubsystem, "progress"),
prometheus.BuildFQName(namespace, goalSubsystem, "progress_seconds"),
"Progress towards the goal.",
[]string{"name", "id", "type", "delta"}, nil,
),
goalInfo: prometheus.NewDesc(
prometheus.BuildFQName(namespace, goalSubsystem, "info"),
"Information about the goal.",
[]string{"name", "id", "ignore_zero_days", "is_enabled", "is_inverse", "is_snoozed", "is_tweeting"}, nil,
[]string{
"name", "id", "type", "delta", "enabled",
"ignore_zero_days", "inverse", "snoozed", "tweeting",
},
nil,
),
uri: in.URI,
fetchStat: FetchHTTP(in.Token, in.SSLVerify, in.Timeout, logger),
Expand Down Expand Up @@ -106,29 +104,33 @@ func (c *goalCollector) Update(ch chan<- prometheus.Metric) error {
)

ch <- prometheus.MustNewConstMetric(
c.goalSeconds,
c.goalThreshold,
prometheus.GaugeValue,
float64(currentChartData.GoalSeconds),
data.Title, data.ID, data.Type, data.Delta,
data.Title,
data.ID,
data.Type,
data.Delta,
strconv.FormatBool(data.IsEnabled),
strconv.FormatBool(data.IgnoreZeroDays),
strconv.FormatBool(data.IsInverse),
strconv.FormatBool(data.IsSnoozed),
strconv.FormatBool(data.IsTweeting),
)

ch <- prometheus.MustNewConstMetric(
c.goalProgress,
prometheus.CounterValue,
currentChartData.ActualSeconds,
data.Title, data.ID, data.Type, data.Delta,
)

ch <- prometheus.MustNewConstMetric(
c.goalInfo,
prometheus.GaugeValue,
float64(1),
data.Title, data.ID,
BoolToBinary(data.IgnoreZeroDays),
BoolToBinary(data.IsEnabled),
BoolToBinary(data.IsInverse),
BoolToBinary(data.IsSnoozed),
BoolToBinary(data.IsTweeting),
data.Title,
data.ID,
data.Type,
data.Delta,
strconv.FormatBool(data.IsEnabled),
strconv.FormatBool(data.IgnoreZeroDays),
strconv.FormatBool(data.IsInverse),
strconv.FormatBool(data.IsSnoozed),
strconv.FormatBool(data.IsTweeting),
)
}

Expand Down

0 comments on commit 1c4d31b

Please sign in to comment.