Skip to content
Snippets Groups Projects
Commit 8e441933 authored by Ruslan Islamgaliev's avatar Ruslan Islamgaliev
Browse files

Merge branch 'ton31337-Fix/use_NewConstMetric'

parents b8fb39e4 5b71e974
No related branches found
No related tags found
No related merge requests found
......@@ -30,11 +30,11 @@ type Exporter struct {
mutex sync.Mutex
client *http.Client
up prometheus.Gauge
up *prometheus.Desc
scrapeFailures prometheus.Counter
accessesTotal prometheus.Counter
kBytesTotal prometheus.Counter
uptime prometheus.Counter
accessesTotal *prometheus.Desc
kBytesTotal *prometheus.Desc
uptime *prometheus.Desc
workers *prometheus.GaugeVec
scoreboard *prometheus.GaugeVec
connections *prometheus.GaugeVec
......@@ -43,31 +43,31 @@ type Exporter struct {
func NewExporter(uri string) *Exporter {
return &Exporter{
URI: uri,
up: prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: namespace,
Name: "up",
Help: "Could the apache server be reached.",
}),
up: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "up"),
"Could the apache server be reached",
nil,
nil),
scrapeFailures: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "exporter_scrape_failures_total",
Help: "Number of errors while scraping apache.",
}),
accessesTotal: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "accesses_total",
Help: "Current total apache accesses",
}),
kBytesTotal: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "sent_kilobytes_total",
Help: "Current total kbytes sent",
}),
uptime: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: namespace,
Name: "uptime_seconds_total",
Help: "Current uptime in seconds",
}),
accessesTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "accesses_total"),
"Current total apache accesses",
nil,
nil),
kBytesTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "sent_kilobytes_total"),
"Current total kbytes sent",
nil,
nil),
uptime: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "uptime_seconds_total"),
"Current uptime in seconds",
nil,
nil),
workers: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: namespace,
Name: "workers",
......@@ -98,11 +98,11 @@ func NewExporter(uri string) *Exporter {
}
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
e.up.Describe(ch)
ch <- e.up
ch <- e.accessesTotal
ch <- e.kBytesTotal
ch <- e.uptime
e.scrapeFailures.Describe(ch)
e.accessesTotal.Describe(ch)
e.kBytesTotal.Describe(ch)
e.uptime.Describe(ch)
e.workers.Describe(ch)
e.scoreboard.Describe(ch)
e.connections.Describe(ch)
......@@ -158,12 +158,10 @@ func (e *Exporter) updateScoreboard(scoreboard string) {
func (e *Exporter) collect(ch chan<- prometheus.Metric) error {
resp, err := e.client.Get(e.URI)
if err != nil {
e.up.Set(0)
e.up.Collect(ch)
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0)
return fmt.Errorf("Error scraping apache: %v", err)
}
e.up.Set(1)
e.up.Collect(ch)
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 1)
data, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
......@@ -191,24 +189,21 @@ func (e *Exporter) collect(ch chan<- prometheus.Metric) error {
return err
}
e.accessesTotal.Set(val)
e.accessesTotal.Collect(ch)
ch <- prometheus.MustNewConstMetric(e.accessesTotal, prometheus.CounterValue, val)
case key == "Total kBytes":
val, err := strconv.ParseFloat(v, 64)
if err != nil {
return err
}
e.kBytesTotal.Set(val)
e.kBytesTotal.Collect(ch)
ch <- prometheus.MustNewConstMetric(e.kBytesTotal, prometheus.CounterValue, val)
case key == "Uptime":
val, err := strconv.ParseFloat(v, 64)
if err != nil {
return err
}
e.uptime.Set(val)
e.uptime.Collect(ch)
ch <- prometheus.MustNewConstMetric(e.uptime, prometheus.CounterValue, val)
case key == "BusyWorkers":
val, err := strconv.ParseFloat(v, 64)
if err != nil {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment