Skip to content

Commit

Permalink
Saving Work
Browse files Browse the repository at this point in the history
  • Loading branch information
drekle committed Dec 13, 2017
1 parent 963c904 commit 826d0ed
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions prometheus/metrics/docker/uptime.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
package docker

import (
"os"

"github.com/docker/docker/api/types"
"github.com/drekle/go/prometheus/metrics"
"github.com/drekle/go/prometheus/metrics/api"
"github.com/prometheus/client_golang/prometheus"
)

type uptime struct {
container *types.Container
gauge metrics.Metric
container types.Container
gauge prometheus.Gauge
}

func (metric uptime) Tick() {
if metric.container.Status == types.Healthy {
if metric.container.State == "running" {
metric.gauge.Set(1)
} else {
metric.gauge.Set(0)
}
}

func UptimeMetric(container *types.Container) metrics.TickMetric {
func (metric uptime) GetMetric() api.Metric {
return metric.gauge
}

func (metric uptime) GetUUID() string {
hostname, _ := os.Hostname()
id := hostname + "_" + metric.container.ID
return id
}

func UptimeMetric(container types.Container) api.TickMetric {
hostname, _ := os.Hostname()
name := hostname + "_" + container.Names[0][1:]
return &uptime{
container: container,
gauge: prometheus.NewGauge(
prometheus.GaugeOpts{
Name: container.ID,
Help: "Uptime for " + container.ID,
Name: name,
Help: "Uptime for " + name,
},
),
}
Expand Down

0 comments on commit 826d0ed

Please sign in to comment.