Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add log usage metrics for containers #2

Merged
merged 1 commit into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ Here's an example scrape config. This assumes that the exporter is available at

## Metrics

| Metric | Description | Labels |
| --------------------------------------------- | ----------------------------------------------------- | -------------------- |
| kube_summary_container_rootfs_inodes_free | Number of available Inodes | pod, namespace, name |
| kube_summary_container_rootfs_inodes | Number of Inodes | pod, namespace, name |
| kube_summary_container_rootfs_inodes_used | Number of used Inodes | pod, namespace, name |
| kube_summary_container_rootfs_available_bytes | Number of bytes that aren't consumed by the container | pod, namespace, name |
| kube_summary_container_rootfs_capacity_bytes | Number of bytes that can be consumed by the container | pod, namespace, name |
| kube_summary_container_rootfs_used_bytes | Number of bytes that are consumed by the container | pod, namespace, name |
| Metric | Description | Labels |
| --------------------------------------------- | ---------------------------------------------------------- | -------------------- |
| kube_summary_container_logs_inodes_free | Number of available Inodes for logs | pod, namespace, name |
| kube_summary_container_logs_inodes | Number of Inodes for logs | pod, namespace, name |
| kube_summary_container_logs_inodes_used | Number of used Inodes for logs | pod, namespace, name |
| kube_summary_container_logs_available_bytes | Number of bytes that aren't consumed by the container logs | pod, namespace, name |
| kube_summary_container_logs_capacity_bytes | Number of bytes that can be consumed by the container logs | pod, namespace, name |
| kube_summary_container_logs_used_bytes | Number of bytes that are consumed by the container logs | pod, namespace, name |
| kube_summary_container_rootfs_inodes_free | Number of available Inodes | pod, namespace, name |
| kube_summary_container_rootfs_inodes | Number of Inodes | pod, namespace, name |
| kube_summary_container_rootfs_inodes_used | Number of used Inodes | pod, namespace, name |
| kube_summary_container_rootfs_available_bytes | Number of bytes that aren't consumed by the container | pod, namespace, name |
| kube_summary_container_rootfs_capacity_bytes | Number of bytes that can be consumed by the container | pod, namespace, name |
| kube_summary_container_rootfs_used_bytes | Number of bytes that are consumed by the container | pod, namespace, name |
92 changes: 92 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,72 @@ var metricsNamespace = "kube_summary"
// collectSummaryMetrics collects metrics from a /stats/summary response
func collectSummaryMetrics(summary *stats.Summary, registry *prometheus.Registry) {
var (
containerLogsInodesFree = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "container_logs_inodes_free",
Help: "Number of available Inodes for logs",
},
[]string{
"pod",
"namespace",
"name",
},
)
containerLogsInodes = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "container_logs_inodes",
Help: "Number of Inodes for logs",
},
[]string{
"pod",
"namespace",
"name",
},
)
containerLogsInodesUsed = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "container_logs_inodes_used",
Help: "Number of used Inodes for logs",
},
[]string{
"pod",
"namespace",
"name",
},
)
containerLogsAvailableBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "container_logs_available_bytes",
Help: "Number of bytes that aren't consumed by the container logs",
},
[]string{
"pod",
"namespace",
"name",
},
)
containerLogsCapacityBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "container_logs_capacity_bytes",
Help: "Number of bytes that can be consumed by the container logs",
},
[]string{
"pod",
"namespace",
"name",
},
)
containerLogsUsedBytes = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "container_logs_used_bytes",
Help: "Number of bytes that are consumed by the container logs",
},
[]string{
"pod",
"namespace",
"name",
},
)
containerRootFsInodesFree = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Name: "container_rootfs_inodes_free",
Expand Down Expand Up @@ -94,6 +160,12 @@ func collectSummaryMetrics(summary *stats.Summary, registry *prometheus.Registry
)
)
registry.MustRegister(
containerLogsInodesFree,
containerLogsInodes,
containerLogsInodesUsed,
containerLogsAvailableBytes,
containerLogsCapacityBytes,
containerLogsUsedBytes,
containerRootFsInodesFree,
containerRootFsInodes,
containerRootFsInodesUsed,
Expand All @@ -104,6 +176,26 @@ func collectSummaryMetrics(summary *stats.Summary, registry *prometheus.Registry

for _, pod := range summary.Pods {
for _, container := range pod.Containers {
if logs := container.Logs; logs != nil {
if inodesFree := logs.InodesFree; inodesFree != nil {
containerLogsInodesFree.WithLabelValues(pod.PodRef.Name, pod.PodRef.Namespace, container.Name).Set(float64(*inodesFree))
}
if inodes := logs.Inodes; inodes != nil {
containerLogsInodes.WithLabelValues(pod.PodRef.Name, pod.PodRef.Namespace, container.Name).Set(float64(*inodes))
}
if inodesUsed := logs.InodesUsed; inodesUsed != nil {
containerLogsInodesUsed.WithLabelValues(pod.PodRef.Name, pod.PodRef.Namespace, container.Name).Set(float64(*inodesUsed))
}
if availableBytes := logs.AvailableBytes; availableBytes != nil {
containerLogsAvailableBytes.WithLabelValues(pod.PodRef.Name, pod.PodRef.Namespace, container.Name).Set(float64(*availableBytes))
}
if capacityBytes := logs.CapacityBytes; capacityBytes != nil {
containerLogsCapacityBytes.WithLabelValues(pod.PodRef.Name, pod.PodRef.Namespace, container.Name).Set(float64(*capacityBytes))
}
if usedBytes := logs.UsedBytes; usedBytes != nil {
containerLogsUsedBytes.WithLabelValues(pod.PodRef.Name, pod.PodRef.Namespace, container.Name).Set(float64(*usedBytes))
}
}
if rootfs := container.Rootfs; rootfs != nil {
if inodesFree := rootfs.InodesFree; inodesFree != nil {
containerRootFsInodesFree.WithLabelValues(pod.PodRef.Name, pod.PodRef.Namespace, container.Name).Set(float64(*inodesFree))
Expand Down