forked from DavidLeeUX/memcached_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
564 lines (528 loc) · 20.4 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
package main
import (
"fmt"
"io/ioutil"
"math"
"net/http"
"strconv"
"strings"
"sync"
"time"
"github.com/grobie/gomemcache/memcache"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"
"gopkg.in/alecthomas/kingpin.v2"
)
const (
namespace = "memcached"
)
// Exporter collects metrics from a memcached server.
var memcachedLabelNames = []string{
"server",
}
type Exporter struct {
address []string
timeout time.Duration
up *prometheus.Desc
uptime *prometheus.Desc
version *prometheus.Desc
bytesRead *prometheus.Desc
bytesWritten *prometheus.Desc
currentConnections *prometheus.Desc
maxConnections *prometheus.Desc
connectionsTotal *prometheus.Desc
connsYieldedTotal *prometheus.Desc
listenerDisabledTotal *prometheus.Desc
currentBytes *prometheus.Desc
limitBytes *prometheus.Desc
commands *prometheus.Desc
items *prometheus.Desc
itemsTotal *prometheus.Desc
evictions *prometheus.Desc
reclaimed *prometheus.Desc
malloced *prometheus.Desc
itemsNumber *prometheus.Desc
itemsAge *prometheus.Desc
itemsCrawlerReclaimed *prometheus.Desc
itemsEvicted *prometheus.Desc
itemsEvictedNonzero *prometheus.Desc
itemsEvictedTime *prometheus.Desc
itemsEvictedUnfetched *prometheus.Desc
itemsExpiredUnfetched *prometheus.Desc
itemsOutofmemory *prometheus.Desc
itemsReclaimed *prometheus.Desc
itemsTailrepairs *prometheus.Desc
slabsChunkSize *prometheus.Desc
slabsChunksPerPage *prometheus.Desc
slabsCurrentPages *prometheus.Desc
slabsCurrentChunks *prometheus.Desc
slabsChunksUsed *prometheus.Desc
slabsChunksFree *prometheus.Desc
slabsChunksFreeEnd *prometheus.Desc
slabsMemRequested *prometheus.Desc
slabsCommands *prometheus.Desc
}
// NewExporter returns an initialized exporter.
func NewExporter(server string, timeout time.Duration) *Exporter {
serverList := strings.Split(server, ",")
return &Exporter{
address: serverList,
timeout: timeout,
up: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "up"),
"Could the memcached server be reached.",
memcachedLabelNames,
nil,
),
uptime: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "uptime_seconds"),
"Number of seconds since the server started.",
memcachedLabelNames,
nil,
),
version: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "version"),
"The version of this memcached server.",
[]string{"version", "server"},
nil,
),
bytesRead: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "read_bytes_total"),
"Total number of bytes read by this server from network.",
memcachedLabelNames,
nil,
),
bytesWritten: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "written_bytes_total"),
"Total number of bytes sent by this server to network.",
memcachedLabelNames,
nil,
),
currentConnections: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "current_connections"),
"Current number of open connections.",
memcachedLabelNames,
nil,
),
maxConnections: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "max_connections"),
"Maximum number of clients allowed.",
memcachedLabelNames,
nil,
),
connectionsTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "connections_total"),
"Total number of connections opened since the server started running.",
memcachedLabelNames,
nil,
),
connsYieldedTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "connections_yielded_total"),
"Total number of connections yielded running due to hitting the memcached's -R limit.",
memcachedLabelNames,
nil,
),
listenerDisabledTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "connections_listener_disabled_total"),
"Number of times that memcached has hit its connections limit and disabled its listener.",
memcachedLabelNames,
nil,
),
currentBytes: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "current_bytes"),
"Current number of bytes used to store items.",
memcachedLabelNames,
nil,
),
limitBytes: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "limit_bytes"),
"Number of bytes this server is allowed to use for storage.",
memcachedLabelNames,
nil,
),
commands: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "commands_total"),
"Total number of all requests broken down by command (get, set, etc.) and status.",
[]string{"command", "status", "server"},
nil,
),
items: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "current_items"),
"Current number of items stored by this instance.",
memcachedLabelNames,
nil,
),
itemsTotal: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "items_total"),
"Total number of items stored during the life of this instance.",
memcachedLabelNames,
nil,
),
evictions: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "items_evicted_total"),
"Total number of valid items removed from cache to free memory for new items.",
memcachedLabelNames,
nil,
),
reclaimed: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "items_reclaimed_total"),
"Total number of times an entry was stored using memory from an expired entry.",
memcachedLabelNames,
nil,
),
malloced: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "malloced_bytes"),
"Number of bytes of memory allocated to slab pages.",
memcachedLabelNames,
nil,
),
itemsNumber: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "current_items"),
"Number of items currently stored in this slab class.",
[]string{"slab", "server"},
nil,
),
itemsAge: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_age_seconds"),
"Number of seconds the oldest item has been in the slab class.",
[]string{"slab", "server"},
nil,
),
itemsCrawlerReclaimed: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_crawler_reclaimed_total"),
"Total number of items freed by the LRU Crawler.",
[]string{"slab", "server"},
nil,
),
itemsEvicted: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_evicted_total"),
"Total number of times an item had to be evicted from the LRU before it expired.",
[]string{"slab", "server"},
nil,
),
itemsEvictedNonzero: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_evicted_nonzero_total"),
"Total number of times an item which had an explicit expire time set had to be evicted from the LRU before it expired.",
[]string{"slab", "server"},
nil,
),
itemsEvictedTime: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_evicted_time_seconds"),
"Seconds since the last access for the most recent item evicted from this class.",
[]string{"slab", "server"},
nil,
),
itemsEvictedUnfetched: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_evicted_unfetched_total"),
"Total nmber of items evicted and never fetched.",
[]string{"slab", "server"},
nil,
),
itemsExpiredUnfetched: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_expired_unfetched_total"),
"Total number of valid items evicted from the LRU which were never touched after being set.",
[]string{"slab", "server"},
nil,
),
itemsOutofmemory: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_outofmemory_total"),
"Total number of items for this slab class that have triggered an out of memory error.",
[]string{"slab", "server"},
nil,
),
itemsReclaimed: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_reclaimed_total"),
"Total number of items reclaimed.",
[]string{"slab", "server"},
nil,
),
itemsTailrepairs: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "items_tailrepairs_total"),
"Total number of times the entries for a particular ID need repairing.",
[]string{"slab", "server"},
nil,
),
slabsChunkSize: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "chunk_size_bytes"),
"Number of bytes allocated to each chunk within this slab class.",
[]string{"slab", "server"},
nil,
),
slabsChunksPerPage: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "chunks_per_page"),
"Number of chunks within a single page for this slab class.",
[]string{"slab", "server"},
nil,
),
slabsCurrentPages: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "current_pages"),
"Number of pages allocated to this slab class.",
[]string{"slab", "server"},
nil,
),
slabsCurrentChunks: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "current_chunks"),
"Number of chunks allocated to this slab class.",
[]string{"slab", "server"},
nil,
),
slabsChunksUsed: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "chunks_used"),
"Number of chunks allocated to an item.",
[]string{"slab", "server"},
nil,
),
slabsChunksFree: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "chunks_free"),
"Number of chunks not yet allocated items.",
[]string{"slab", "server"},
nil,
),
slabsChunksFreeEnd: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "chunks_free_end"),
"Number of free chunks at the end of the last allocated page.",
[]string{"slab", "server"},
nil,
),
slabsMemRequested: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "mem_requested_bytes"),
"Number of bytes of memory actual items take up within a slab.",
[]string{"slab", "server"},
nil,
),
slabsCommands: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slab", "commands_total"),
"Total number of all requests broken down by command (get, set, etc.) and status per slab.",
[]string{"slab", "command", "status", "server"},
nil,
),
}
}
// Describe describes all the metrics exported by the memcached exporter. It
// implements prometheus.Collector.
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
ch <- e.up
ch <- e.uptime
ch <- e.version
ch <- e.bytesRead
ch <- e.bytesWritten
ch <- e.currentConnections
ch <- e.maxConnections
ch <- e.connectionsTotal
ch <- e.connsYieldedTotal
ch <- e.listenerDisabledTotal
ch <- e.currentBytes
ch <- e.limitBytes
ch <- e.commands
ch <- e.items
ch <- e.itemsTotal
ch <- e.evictions
ch <- e.reclaimed
ch <- e.malloced
ch <- e.itemsNumber
ch <- e.itemsAge
ch <- e.itemsCrawlerReclaimed
ch <- e.itemsEvicted
ch <- e.itemsEvictedNonzero
ch <- e.itemsEvictedTime
ch <- e.itemsEvictedUnfetched
ch <- e.itemsExpiredUnfetched
ch <- e.itemsOutofmemory
ch <- e.itemsReclaimed
ch <- e.itemsTailrepairs
ch <- e.itemsExpiredUnfetched
ch <- e.slabsChunkSize
ch <- e.slabsChunksPerPage
ch <- e.slabsCurrentPages
ch <- e.slabsCurrentChunks
ch <- e.slabsChunksUsed
ch <- e.slabsChunksFree
ch <- e.slabsChunksFreeEnd
ch <- e.slabsMemRequested
ch <- e.slabsCommands
}
// Collect fetches the statistics from the configured memcached server, and
// delivers them as Prometheus metrics. It implements prometheus.Collector.
func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
var wg sync.WaitGroup
for _, v := range e.address {
wg.Add(1)
go e.RunCollect(v, ch, &wg)
}
wg.Wait()
}
func (e *Exporter) RunCollect(address string, ch chan<- prometheus.Metric, wg *sync.WaitGroup) {
defer wg.Done()
c, err := memcache.New(address)
if err != nil {
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0, address)
log.Errorf("Failed to connect to memcached: %s", err)
return
}
c.Timeout = e.timeout
stats, err := c.Stats()
if err != nil {
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0, address)
log.Errorf("Failed to collect stats from memcached: %s", err)
return
}
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 1, address)
// TODO(ts): Clean up and consolidate metric mappings.
itemsMetrics := map[string]*prometheus.Desc{
"crawler_reclaimed": e.itemsCrawlerReclaimed,
"evicted": e.itemsEvicted,
"evicted_nonzero": e.itemsEvictedNonzero,
"evicted_time": e.itemsEvictedTime,
"evicted_unfetched": e.itemsEvictedUnfetched,
"expired_unfetched": e.itemsExpiredUnfetched,
"outofmemory": e.itemsOutofmemory,
"reclaimed": e.itemsReclaimed,
"tailrepairs": e.itemsTailrepairs,
}
for _, t := range stats {
s := t.Stats
ch <- prometheus.MustNewConstMetric(e.uptime, prometheus.CounterValue, parse(s, "uptime"), address)
ch <- prometheus.MustNewConstMetric(e.version, prometheus.GaugeValue, 1, s["version"], address)
for _, op := range []string{"get", "delete", "incr", "decr", "cas", "touch"} {
ch <- prometheus.MustNewConstMetric(e.commands, prometheus.CounterValue, parse(s, op+"_hits"), op, "hit", address)
ch <- prometheus.MustNewConstMetric(e.commands, prometheus.CounterValue, parse(s, op+"_misses"), op, "miss", address)
}
ch <- prometheus.MustNewConstMetric(e.commands, prometheus.CounterValue, parse(s, "cas_badval"), "cas", "badval", address)
ch <- prometheus.MustNewConstMetric(e.commands, prometheus.CounterValue, parse(s, "cmd_flush"), "flush", "hit", address)
// memcached includes cas operations again in cmd_set.
set := math.NaN()
if setCmd, err := strconv.ParseFloat(s["cmd_set"], 64); err == nil {
if cas, casErr := sum(s, "cas_misses", "cas_hits", "cas_badval"); casErr == nil {
set = setCmd - cas
} else {
log.Errorf("Failed to parse cas: %s", casErr)
}
} else {
log.Errorf("Failed to parse set %q: %s", s["cmd_set"], err)
}
ch <- prometheus.MustNewConstMetric(e.commands, prometheus.CounterValue, set, "set", "hit", address)
ch <- prometheus.MustNewConstMetric(e.currentBytes, prometheus.GaugeValue, parse(s, "bytes"), address)
ch <- prometheus.MustNewConstMetric(e.limitBytes, prometheus.GaugeValue, parse(s, "limit_maxbytes"), address)
ch <- prometheus.MustNewConstMetric(e.items, prometheus.GaugeValue, parse(s, "curr_items"), address)
ch <- prometheus.MustNewConstMetric(e.itemsTotal, prometheus.CounterValue, parse(s, "total_items"), address)
ch <- prometheus.MustNewConstMetric(e.bytesRead, prometheus.CounterValue, parse(s, "bytes_read"), address)
ch <- prometheus.MustNewConstMetric(e.bytesWritten, prometheus.CounterValue, parse(s, "bytes_written"), address)
ch <- prometheus.MustNewConstMetric(e.currentConnections, prometheus.GaugeValue, parse(s, "curr_connections"), address)
ch <- prometheus.MustNewConstMetric(e.connectionsTotal, prometheus.CounterValue, parse(s, "total_connections"), address)
ch <- prometheus.MustNewConstMetric(e.connsYieldedTotal, prometheus.CounterValue, parse(s, "conn_yields"), address)
ch <- prometheus.MustNewConstMetric(e.listenerDisabledTotal, prometheus.CounterValue, parse(s, "listen_disabled_num"), address)
ch <- prometheus.MustNewConstMetric(e.evictions, prometheus.CounterValue, parse(s, "evictions"), address)
ch <- prometheus.MustNewConstMetric(e.reclaimed, prometheus.CounterValue, parse(s, "reclaimed"), address)
ch <- prometheus.MustNewConstMetric(e.malloced, prometheus.GaugeValue, parse(s, "total_malloced"), address)
for slab, u := range t.Items {
slab := strconv.Itoa(slab)
ch <- prometheus.MustNewConstMetric(e.itemsNumber, prometheus.GaugeValue, parse(u, "number"), slab, address)
ch <- prometheus.MustNewConstMetric(e.itemsAge, prometheus.GaugeValue, parse(u, "age"), slab, address)
for m, d := range itemsMetrics {
if _, ok := u[m]; !ok {
continue
}
ch <- prometheus.MustNewConstMetric(d, prometheus.CounterValue, parse(u, m), slab, address)
}
}
for slab, v := range t.Slabs {
slab := strconv.Itoa(slab)
for _, op := range []string{"get", "delete", "incr", "decr", "cas", "touch"} {
ch <- prometheus.MustNewConstMetric(e.slabsCommands, prometheus.CounterValue, parse(v, op+"_hits"), slab, op, "hit", address)
}
ch <- prometheus.MustNewConstMetric(e.slabsCommands, prometheus.CounterValue, parse(v, "cas_badval"), slab, "cas", "badval", address)
slabSet := math.NaN()
if slabSetCmd, err := strconv.ParseFloat(v["cmd_set"], 64); err == nil {
if slabCas, slabCasErr := sum(v, "cas_hits", "cas_badval"); slabCasErr == nil {
slabSet = slabSetCmd - slabCas
} else {
log.Errorf("Failed to parse cas: %s", slabCasErr)
}
} else {
log.Errorf("Failed to parse set %q: %s", v["cmd_set"], err)
}
ch <- prometheus.MustNewConstMetric(e.slabsCommands, prometheus.CounterValue, slabSet, slab, "set", "hit", address)
ch <- prometheus.MustNewConstMetric(e.slabsChunkSize, prometheus.GaugeValue, parse(v, "chunk_size"), slab, address)
ch <- prometheus.MustNewConstMetric(e.slabsChunksPerPage, prometheus.GaugeValue, parse(v, "chunks_per_page"), slab, address)
ch <- prometheus.MustNewConstMetric(e.slabsCurrentPages, prometheus.GaugeValue, parse(v, "total_pages"), slab, address)
ch <- prometheus.MustNewConstMetric(e.slabsCurrentChunks, prometheus.GaugeValue, parse(v, "total_chunks"), slab, address)
ch <- prometheus.MustNewConstMetric(e.slabsChunksUsed, prometheus.GaugeValue, parse(v, "used_chunks"), slab, address)
ch <- prometheus.MustNewConstMetric(e.slabsChunksFree, prometheus.GaugeValue, parse(v, "free_chunks"), slab, address)
ch <- prometheus.MustNewConstMetric(e.slabsChunksFreeEnd, prometheus.GaugeValue, parse(v, "free_chunks_end"), slab, address)
ch <- prometheus.MustNewConstMetric(e.slabsMemRequested, prometheus.GaugeValue, parse(v, "mem_requested"), slab, address)
}
}
statsSettings, err := c.StatsSettings()
if err != nil {
log.Errorf("Could not query stats settings: %s", err)
}
for _, settings := range statsSettings {
ch <- prometheus.MustNewConstMetric(e.maxConnections, prometheus.GaugeValue, parse(settings, "maxconns"), address)
}
}
func parse(stats map[string]string, key string) float64 {
v, err := strconv.ParseFloat(stats[key], 64)
if err != nil {
log.Errorf("Failed to parse %s %q: %s", key, stats[key], err)
v = math.NaN()
}
return v
}
func sum(stats map[string]string, keys ...string) (float64, error) {
s := 0.
for _, key := range keys {
v, err := strconv.ParseFloat(stats[key], 64)
if err != nil {
return math.NaN(), err
}
s += v
}
return s, nil
}
func main() {
var (
address = kingpin.Flag("memcached.address", "Memcached server address.").Default("localhost:11211").String()
timeout = kingpin.Flag("memcached.timeout", "memcached connect timeout.").Default("1s").Duration()
pidFile = kingpin.Flag("memcached.pid-file", "Optional path to a file containing the memcached PID for additional metrics.").Default("").String()
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9150").String()
metricsPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").String()
)
log.AddFlags(kingpin.CommandLine)
kingpin.Version(version.Print("memcached_exporter"))
kingpin.HelpFlag.Short('h')
kingpin.Parse()
log.Infoln("Starting memcached_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
prometheus.MustRegister(NewExporter(*address, *timeout))
if *pidFile != "" {
procExporter := prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{
PidFn: func() (int, error) {
content, err := ioutil.ReadFile(*pidFile)
if err != nil {
return 0, fmt.Errorf("can't read pid file %q: %s", *pidFile, err)
}
value, err := strconv.Atoi(strings.TrimSpace(string(content)))
if err != nil {
return 0, fmt.Errorf("can't parse pid file %q: %s", *pidFile, err)
}
return value, nil
},
Namespace: namespace,
})
prometheus.MustRegister(procExporter)
}
http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`<html>
<head><title>Memcached Exporter</title></head>
<body>
<h1>Memcached Exporter</h1>
<p><a href='` + *metricsPath + `'>Metrics</a></p>
</body>
</html>`))
})
log.Infoln("Starting HTTP server on", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
}