-
Notifications
You must be signed in to change notification settings - Fork 1
/
mcelog.go
63 lines (51 loc) · 1.11 KB
/
mcelog.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
// Copyright (c) 2017 mgIT GmbH. All rights reserved.
// Distributed under the Apache License. See LICENSE for details.
package main
import (
"log"
"os"
"github.com/prometheus/client_golang/prometheus"
)
type MCELogOptions struct {
Path string `json:"path"`
}
type MCELogChecker struct {
opts MCELogOptions
promMCELogSize *prometheus.Desc
}
func NewMCELogChecker(opts MCELogOptions) *MCELogChecker {
if opts.Path == "" {
opts.Path = "/var/log/mcelog"
}
return &MCELogChecker{
opts: opts,
promMCELogSize: prometheus.NewDesc(
"mcelog_size_bytes",
"size of the machine exception log",
[]string{"file"},
nil),
}
}
func (c *MCELogChecker) Describe(ch chan<- *prometheus.Desc) {
ch <- c.promMCELogSize
}
func (c *MCELogChecker) Collect(ch chan<- prometheus.Metric) {
var size int64
info, err := os.Stat(c.opts.Path)
if err != nil {
if os.IsNotExist(err) {
size = 0
} else {
log.Println("failed to get mcelog size:", err)
return
}
} else {
size = info.Size()
}
ch <- prometheus.MustNewConstMetric(
c.promMCELogSize,
prometheus.GaugeValue,
float64(size),
c.opts.Path,
)
}