@@ -37,7 +37,6 @@ type Exporter struct {
37
37
db * sql.DB
38
38
scrapers []Scraper
39
39
stats * Stats
40
- error prometheus.Gauge
41
40
mysqldUp prometheus.Gauge
42
41
}
43
42
@@ -47,12 +46,6 @@ func New(db *sql.DB, scrapers []Scraper, stats *Stats) *Exporter {
47
46
db : db ,
48
47
scrapers : scrapers ,
49
48
stats : stats ,
50
- error : prometheus .NewGauge (prometheus.GaugeOpts {
51
- Namespace : namespace ,
52
- Subsystem : exporter ,
53
- Name : "last_scrape_error" ,
54
- Help : "Whether the last scrape of metrics from MySQL resulted in an error (1 for error, 0 for success)." ,
55
- }),
56
49
mysqldUp : prometheus .NewGauge (prometheus.GaugeOpts {
57
50
Namespace : namespace ,
58
51
Name : "up" ,
@@ -94,7 +87,7 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
94
87
e .scrape (ch )
95
88
96
89
ch <- e .stats .TotalScrapes
97
- ch <- e .error
90
+ ch <- e .stats . Error
98
91
e .stats .ScrapeErrors .Collect (ch )
99
92
ch <- e .mysqldUp
100
93
}
@@ -107,7 +100,7 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
107
100
if err = e .db .Ping (); err != nil {
108
101
log .Errorln ("Error pinging mysqld:" , err )
109
102
e .mysqldUp .Set (0 )
110
- e .error .Set (1 )
103
+ e .stats . Error .Set (1 )
111
104
return
112
105
}
113
106
e .mysqldUp .Set (1 )
@@ -128,7 +121,7 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
128
121
if err := scraper .Scrape (e .db , ch ); err != nil {
129
122
log .Errorln ("Error scraping for " + label + ":" , err )
130
123
e .stats .ScrapeErrors .WithLabelValues (label ).Inc ()
131
- e .error .Set (1 )
124
+ e .stats . Error .Set (1 )
132
125
}
133
126
ch <- prometheus .MustNewConstMetric (scrapeDurationDesc , prometheus .GaugeValue , time .Since (scrapeTime ).Seconds (), label )
134
127
}(scraper )
@@ -155,6 +148,7 @@ func getMySQLVersion(db *sql.DB) float64 {
155
148
type Stats struct {
156
149
TotalScrapes prometheus.Counter
157
150
ScrapeErrors * prometheus.CounterVec
151
+ Error prometheus.Gauge
158
152
}
159
153
160
154
func NewStats (resolution string ) * Stats {
@@ -175,5 +169,11 @@ func NewStats(resolution string) *Stats {
175
169
Name : "scrape_errors_total" ,
176
170
Help : "Total number of times an error occurred scraping a MySQL." ,
177
171
}, []string {"collector" }),
172
+ Error : prometheus .NewGauge (prometheus.GaugeOpts {
173
+ Namespace : namespace ,
174
+ Subsystem : subsystem ,
175
+ Name : "last_scrape_error" ,
176
+ Help : "Whether the last scrape of metrics from MySQL resulted in an error (1 for error, 0 for success)." ,
177
+ }),
178
178
}
179
179
}
0 commit comments