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

Report k8s pct metrics from enrichment process #7677

Merged
merged 5 commits into from
Jul 23, 2018
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ https://github.com/elastic/beats/compare/v6.2.3...master[Check the HEAD diff]
- Fix Jolokia attribute mapping when using wildcards and MBean names with multiple properties. {pull}7321[7321]
- Do not report Metricbeat container host as hostname in Kubernetes deployment. {issue}7199[7199]
- Ensure metadata updates don't replace existing pod metrics. {pull}7573[7573]
- Fix kubernetes pct fields reporting. {pull}7677[7677]

*Packetbeat*

Expand Down
88 changes: 88 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,49 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--------------------------------------------------------------------
Dependency: github.com/gogo/protobuf
Revision: 636bf0302bc95575d69441b25a2603156ffdddf1
License type (autodetected): BSD-3-Clause
./metricbeat/vendor/github.com/gogo/protobuf/LICENSE:
--------------------------------------------------------------------
Protocol Buffers for Go with Gadgets

Copyright (c) 2013, The GoGo Authors. All rights reserved.
http://github.com/gogo/protobuf

Go support for Protocol Buffers - Google's data interchange format

Copyright 2010 The Go Authors. All rights reserved.
https://github.com/golang/protobuf

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


--------------------------------------------------------------------
Dependency: github.com/golang/protobuf
Revision: 2bba0603135d7d7f5cb73b2125beeda19c09f4ef
Expand Down Expand Up @@ -1380,6 +1423,16 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------
Dependency: github.com/kubernetes/apimachinery
Version: kubernetes-1.11.1
Revision: 103fd098999dc9c0c88536f5c9ad2e5da39373ae
License type (autodetected): Apache-2.0
./metricbeat/vendor/github.com/kubernetes/apimachinery/LICENSE:
--------------------------------------------------------------------
Apache License 2.0


--------------------------------------------------------------------
Dependency: github.com/lib/pq
Revision: 2704adc878c21e1329f46f6e56a1c387d788ff94
Expand Down Expand Up @@ -2693,6 +2746,41 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------
Dependency: gopkg.in/inf.v0
Revision: d2d2541c53f18d2a059457998ce2876cc8e67cbf
License type (autodetected): BSD-3-Clause
./metricbeat/vendor/gopkg.in/inf.v0/LICENSE:
--------------------------------------------------------------------
Copyright (c) 2012 Péter Surányi. Portions Copyright (c) 2009 The Go
Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------
Dependency: gopkg.in/mgo.v2
Revision: 3f83fa5005286a7fe593b055f0d7771a7dce4655
Expand Down
2 changes: 0 additions & 2 deletions metricbeat/module/kubernetes/_meta/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
# - container
# - volume
period: 10s
hosts: ["localhost:10255"]

hosts: ["localhost:10250"]
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
ssl.certificate_authorities:
Expand Down
38 changes: 36 additions & 2 deletions metricbeat/module/kubernetes/util/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"sync"
"time"

"github.com/kubernetes/apimachinery/pkg/api/resource"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/kubernetes"
"github.com/elastic/beats/libbeat/logp"
Expand Down Expand Up @@ -95,10 +97,10 @@ func GetWatcher(base mb.BaseMetricSet, resource kubernetes.Resource, nodeScope b
// NewResourceMetadataEnricher returns an Enricher configured for kubernetes resource events
func NewResourceMetadataEnricher(
base mb.BaseMetricSet,
resource kubernetes.Resource,
res kubernetes.Resource,
nodeScope bool) Enricher {

watcher, err := GetWatcher(base, resource, nodeScope)
watcher, err := GetWatcher(base, res, nodeScope)
if err != nil {
logp.Err("Error initializing Kubernetes metadata enricher: %s", err)
return &nilEnricher{}
Expand All @@ -123,6 +125,23 @@ func NewResourceMetadataEnricher(
switch r := r.(type) {
case *kubernetes.Pod:
m[id] = metaGen.PodMetadata(r)

case *kubernetes.Node:
// Report node allocatable resources to PerfMetrics cache
name := r.GetMetadata().GetName()
if cpu, ok := r.GetStatus().GetCapacity()["cpu"]; ok {
if q, err := resource.ParseQuantity(cpu.GetString_()); err == nil {
PerfMetrics.NodeCoresAllocatable.Set(name, float64(q.MilliValue())/1000)
}
}
if memory, ok := r.GetStatus().GetCapacity()["memory"]; ok {
if q, err := resource.ParseQuantity(memory.GetString_()); err == nil {
PerfMetrics.NodeMemAllocatable.Set(name, float64(q.Value()))
}
}

m[id] = metaGen.ResourceMetadata(r)

default:
m[id] = metaGen.ResourceMetadata(r)
}
Expand Down Expand Up @@ -169,7 +188,22 @@ func NewContainerMetadataEnricher(
func(m map[string]common.MapStr, r kubernetes.Resource) {
pod := r.(*kubernetes.Pod)
meta := metaGen.PodMetadata(pod)

for _, container := range append(pod.GetSpec().GetContainers(), pod.GetSpec().GetInitContainers()...) {
cuid := ContainerUID(pod.GetMetadata().GetNamespace(), r.GetMetadata().GetName(), container.GetName())

// Report container limits to PerfMetrics cache
if cpu, ok := container.GetResources().GetLimits()["cpu"]; ok {
if q, err := resource.ParseQuantity(cpu.GetString_()); err == nil {
PerfMetrics.ContainerCoresLimit.Set(cuid, float64(q.MilliValue())/1000)
}
}
if memory, ok := container.GetResources().GetLimits()["memory"]; ok {
if q, err := resource.ParseQuantity(memory.GetString_()); err == nil {
PerfMetrics.ContainerMemLimit.Set(cuid, float64(q.Value()))
}
}

id := join(r.GetMetadata().GetNamespace(), r.GetMetadata().GetName(), container.GetName())
m[id] = meta
}
Expand Down
2 changes: 0 additions & 2 deletions metricbeat/modules.d/kubernetes.yml.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# - container
# - volume
period: 10s
hosts: ["localhost:10255"]

hosts: ["localhost:10250"]
bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
ssl.certificate_authorities:
Expand Down
36 changes: 36 additions & 0 deletions metricbeat/vendor/github.com/gogo/protobuf/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions metricbeat/vendor/github.com/gogo/protobuf/proto/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading