Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
e3af23e6
Commit
e3af23e6
authored
Feb 25, 2015
by
Vish Kannan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4792 from vmarmol/mon-containers-per-pod
Add Kubelet metrics for pod and container counts.
parents
7547f70a
95464349
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
20 deletions
+68
-20
kubelet.go
pkg/kubelet/kubelet.go
+2
-0
metrics.go
pkg/kubelet/metrics/metrics.go
+66
-20
No files found.
pkg/kubelet/kubelet.go
View file @
e3af23e6
...
@@ -135,6 +135,8 @@ func NewMainKubelet(
...
@@ -135,6 +135,8 @@ func NewMainKubelet(
}
}
klet
.
dockerCache
=
dockerCache
klet
.
dockerCache
=
dockerCache
metrics
.
Register
(
dockerCache
)
if
err
=
klet
.
setupDataDirs
();
err
!=
nil
{
if
err
=
klet
.
setupDataDirs
();
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
pkg/kubelet/metrics/metrics.go
View file @
e3af23e6
...
@@ -17,6 +17,11 @@ limitations under the License.
...
@@ -17,6 +17,11 @@ limitations under the License.
package
metrics
package
metrics
import
(
import
(
"sync"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus"
)
)
...
@@ -30,30 +35,71 @@ var (
...
@@ -30,30 +35,71 @@ var (
Help
:
"Image pull latency in microseconds."
,
Help
:
"Image pull latency in microseconds."
,
},
},
)
)
// TODO(vmarmol): Implement.
// TODO(vmarmol): Split by source?
PodCount
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Subsystem
:
kubeletSubsystem
,
Name
:
"pod_count"
,
Help
:
"Number of pods currently running."
,
},
)
// TODO(vmarmol): Implement.
// TODO(vmarmol): Split by source?
ContainerCount
=
prometheus
.
NewGauge
(
prometheus
.
GaugeOpts
{
Subsystem
:
kubeletSubsystem
,
Name
:
"container_count"
,
Help
:
"Number of containers currently running."
,
},
)
// TODO(vmarmol): Containers per pod
// TODO(vmarmol): Containers per pod
// TODO(vmarmol): Latency of pod startup
// TODO(vmarmol): Latency of pod startup
// TODO(vmarmol): Latency of SyncPods
// TODO(vmarmol): Latency of SyncPods
)
)
func
init
()
{
var
registerMetrics
sync
.
Once
// Register all metrics.
func
Register
(
containerCache
dockertools
.
DockerCache
)
{
// Register the metrics.
// Register the metrics.
prometheus
.
MustRegister
(
ImagePullLatency
)
registerMetrics
.
Do
(
func
()
{
prometheus
.
MustRegister
(
ImagePullLatency
)
prometheus
.
MustRegister
(
newPodAndContainerCollector
(
containerCache
))
})
}
func
newPodAndContainerCollector
(
containerCache
dockertools
.
DockerCache
)
*
podAndContainerCollector
{
return
&
podAndContainerCollector
{
containerCache
:
containerCache
,
}
}
// Custom collector for current pod and container counts.
type
podAndContainerCollector
struct
{
// Cache for accessing information about running containers.
containerCache
dockertools
.
DockerCache
}
// TODO(vmarmol): Split by source?
var
(
runningPodCountDesc
=
prometheus
.
NewDesc
(
prometheus
.
BuildFQName
(
""
,
kubeletSubsystem
,
"running_pod_count"
),
"Number of pods currently running"
,
nil
,
nil
)
runningContainerCountDesc
=
prometheus
.
NewDesc
(
prometheus
.
BuildFQName
(
""
,
kubeletSubsystem
,
"running_container_count"
),
"Number of containers currently running"
,
nil
,
nil
)
)
func
(
self
*
podAndContainerCollector
)
Describe
(
ch
chan
<-
*
prometheus
.
Desc
)
{
ch
<-
runningPodCountDesc
ch
<-
runningContainerCountDesc
}
func
(
self
*
podAndContainerCollector
)
Collect
(
ch
chan
<-
prometheus
.
Metric
)
{
runningContainers
,
err
:=
self
.
containerCache
.
RunningContainers
()
if
err
!=
nil
{
glog
.
Warning
(
"Failed to get running container information while collecting metrics: %v"
,
err
)
return
}
// Get a mapping of pod to number of containers in that pod.
podToContainerCount
:=
make
(
map
[
types
.
UID
]
struct
{})
for
_
,
cont
:=
range
runningContainers
{
_
,
uid
,
_
,
_
:=
dockertools
.
ParseDockerName
(
cont
.
Names
[
0
])
podToContainerCount
[
uid
]
=
struct
{}{}
}
ch
<-
prometheus
.
MustNewConstMetric
(
runningPodCountDesc
,
prometheus
.
GaugeValue
,
float64
(
len
(
podToContainerCount
)))
ch
<-
prometheus
.
MustNewConstMetric
(
runningContainerCountDesc
,
prometheus
.
GaugeValue
,
float64
(
len
(
runningContainers
)))
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment