-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. add file log to survive pod restart 2. add klog metrics 3. mute some error log
- Loading branch information
Showing
11 changed files
with
88 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package util | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
"k8s.io/klog" | ||
"time" | ||
) | ||
|
||
var ( | ||
klogLinesGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Name: "klog_lines_total", | ||
Help: "Total number of klog messages.", | ||
}, []string{"level"}) | ||
klogBytesGaugeVec = prometheus.NewGaugeVec(prometheus.GaugeOpts{ | ||
Name: "klog_bytes_total", | ||
Help: "Total size of klog messages.", | ||
}, []string{"level"}) | ||
) | ||
|
||
func InitKlogMetrics() { | ||
registerKlogMetrics() | ||
go wait.Until(fetchKlogMetrics, 5*time.Second, nil) | ||
} | ||
|
||
func registerKlogMetrics() { | ||
prometheus.MustRegister(klogLinesGaugeVec) | ||
prometheus.MustRegister(klogBytesGaugeVec) | ||
} | ||
|
||
func fetchKlogMetrics() { | ||
klogLinesGaugeVec.WithLabelValues("INFO").Set(float64(klog.Stats.Info.Lines())) | ||
klogLinesGaugeVec.WithLabelValues("WARN").Set(float64(klog.Stats.Warning.Lines())) | ||
klogLinesGaugeVec.WithLabelValues("ERROR").Set(float64(klog.Stats.Error.Lines())) | ||
|
||
klogBytesGaugeVec.WithLabelValues("INFO").Set(float64(klog.Stats.Info.Bytes())) | ||
klogBytesGaugeVec.WithLabelValues("WARN").Set(float64(klog.Stats.Warning.Bytes())) | ||
klogBytesGaugeVec.WithLabelValues("ERROR").Set(float64(klog.Stats.Error.Bytes())) | ||
} |