Skip to content
Merged
1 change: 1 addition & 0 deletions metricbeat/include/list_docker.go

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# HELP kube_persistentvolumeclaim_access_mode The access mode(s) specified by the persistent volume claim.
# HELP kube_persistentvolumeclaim_info Information about persistent volume claim.
# HELP kube_persistentvolumeclaim_labels Kubernetes labels converted to Prometheus labels.
# HELP kube_persistentvolumeclaim_resource_requests_storage_bytes The capacity of storage requested by the persistent volume claim.
# HELP kube_persistentvolumeclaim_status_phase The phase the persistent volume claim is currently in.
# TYPE kube_persistentvolumeclaim_access_mode gauge
# TYPE kube_persistentvolumeclaim_info gauge
# TYPE kube_persistentvolumeclaim_labels gauge
# TYPE kube_persistentvolumeclaim_resource_requests_storage_bytes gauge
# TYPE kube_persistentvolumeclaim_status_phase gauge
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="mysql-data",storageclass="rbd",volumename="pvc-mysql-data"} 1
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="mysql-data",phase="Bound"} 1
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="mysql-data",phase="Lost"} 0
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="mysql-data",phase="Pending"} 0
kube_persistentvolumeclaim_resource_requests_storage_bytes{namespace="default",persistentvolumeclaim="mysql-data"} 1.073741824e+09
kube_persistentvolumeclaim_labels{label_app="mysql-server",namespace="default",persistentvolumeclaim="mysql-data"} 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's interesting how they included labels here when it's normally not part of the info we get. Do you know why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not sure if I follow)
that labels pattern seems to be common to all main kube-state-metrics objects. Not seeing it anywhere else, nor for annotations, but it looks like the label_keyname="value" is here to stay.

kube_persistentvolumeclaim_access_mode{namespace="default",persistentvolumeclaim="mysql-data",access_mode="ReadWriteOnce"} 1
kube_persistentvolumeclaim_info{namespace="default",persistentvolumeclaim="prometheus-data",storageclass="rbd",volumename="pvc-prometheus-data"} 1
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="prometheus-data",phase="Bound"} 0
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="prometheus-data",phase="Lost"} 0
kube_persistentvolumeclaim_status_phase{namespace="default",persistentvolumeclaim="prometheus-data",phase="Pending"} 1
kube_persistentvolumeclaim_labels{namespace="default",persistentvolumeclaim="prometheus-data"} 1
kube_persistentvolumeclaim_access_mode{namespace="default",persistentvolumeclaim="prometheus-data",access_mode="ReadWriteOnce"} 1
kube_persistentvolumeclaim_info{namespace="",persistentvolumeclaim="mongo-data",storageclass="<none>",volumename=""} 1
kube_persistentvolumeclaim_status_phase{namespace="",persistentvolumeclaim="mongo-data",phase="Bound"} 0
kube_persistentvolumeclaim_status_phase{namespace="",persistentvolumeclaim="mongo-data",phase="Lost"} 1
kube_persistentvolumeclaim_status_phase{namespace="",persistentvolumeclaim="mongo-data",phase="Pending"} 0
kube_persistentvolumeclaim_labels{namespace="",persistentvolumeclaim="mongo-data"} 1
kube_persistentvolumeclaim_access_mode{namespace="",persistentvolumeclaim="mongo-data",access_mode="ReadWriteOnce"} 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[
{
"RootFields": {},
"ModuleFields": {
"namespace": "default"
},
"MetricSetFields": {
"access_mode": "ReadWriteOnce",
"labels": {
"label_app": "mysql-server"
},
"name": "mysql-data",
"phase": "Bound",
"request_storage": {
"bytes": 1073741824
},
"storage_class": "rbd",
"volume_name": "pvc-mysql-data"
},
"Index": "",
"ID": "",
"Namespace": "kubernetes.persistentvolumeclaim",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
},
{
"RootFields": {},
"ModuleFields": {
"namespace": "default"
},
"MetricSetFields": {
"access_mode": "ReadWriteOnce",
"name": "prometheus-data",
"phase": "Pending",
"storage_class": "rbd",
"volume_name": "pvc-prometheus-data"
},
"Index": "",
"ID": "",
"Namespace": "kubernetes.persistentvolumeclaim",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
},
{
"RootFields": {},
"ModuleFields": null,
"MetricSetFields": {
"access_mode": "ReadWriteOnce",
"name": "mongo-data",
"phase": "Lost",
"storage_class": "\u003cnone\u003e"
},
"Index": "",
"ID": "",
"Namespace": "kubernetes.persistentvolumeclaim",
"Timestamp": "0001-01-01T00:00:00Z",
"Error": null,
"Host": "",
"Service": "",
"Took": 0,
"Period": 0,
"DisableTimeSeries": false
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package state_persistentvolumeclaim
Comment thread
odacremolbap marked this conversation as resolved.

import (
p "github.com/elastic/beats/metricbeat/helper/prometheus"
"github.com/elastic/beats/metricbeat/mb"
)

func init() {
mb.Registry.MustAddMetricSet("kubernetes", "state_persistentvolumeclaim",
NewpersistentvolumeclaimMetricSet,
mb.WithHostParser(p.HostParser))
}

// persistentvolumeclaimMetricSet is a prometheus based MetricSet that looks for
// mb.ModuleDataKey prefixed fields and puts then at the module level
type persistentvolumeclaimMetricSet struct {
mb.BaseMetricSet
prometheus p.Prometheus
mapping *p.MetricsMapping
}

// NewpersistentvolumeclaimMetricSet returns a prometheus based metricset for Persistent Volumes
func NewpersistentvolumeclaimMetricSet(base mb.BaseMetricSet) (mb.MetricSet, error) {
prometheus, err := p.NewPrometheusClient(base)
if err != nil {
return nil, err
}

return &persistentvolumeclaimMetricSet{
BaseMetricSet: base,
prometheus: prometheus,
mapping: &p.MetricsMapping{
Metrics: map[string]p.MetricMap{

"kube_persistentvolumeclaim_access_mode": p.LabelMetric("access_mode", "access_mode"),
"kube_persistentvolumeclaim_info": p.InfoMetric(),
"kube_persistentvolumeclaim_labels": p.ExtendedInfoMetric(p.Configuration{StoreNonMappedLabels: true, NonMappedLabelsPlacement: "labels"}),
"kube_persistentvolumeclaim_resource_requests_storage_bytes": p.Metric("request_storage.bytes"),
"kube_persistentvolumeclaim_status_phase": p.LabelMetric("phase", "phase"),
},
Labels: map[string]p.LabelMap{
"namespace": p.KeyLabel(mb.ModuleDataKey + ".namespace"),
"persistentvolumeclaim": p.KeyLabel("name"),
"storageclass": p.Label("storage_class"),
"volumename": p.Label("volume_name"),
},
},
}, nil
}

// Fetch prometheus metrics and treats those prefixed by mb.ModuleDataKey as
// module rooted fields at the event that gets reported
func (m *persistentvolumeclaimMetricSet) Fetch(reporter mb.ReporterV2) {
events, err := m.prometheus.GetProcessedMetrics(m.mapping)
if err != nil {
m.Logger().Error(err)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can write the signature of the method like func (m *persistentvolumeclaimMetricSet) Fetch(reporter mb.ReporterV2) error and return err here directly. The under the hood implementation will do the m.Logger().Error(err) and the reporter.Error(err).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot @sayden
will use that func signature from now on.

reporter.Error(err)
return
}

for _, event := range events {
event[mb.NamespaceKey] = "persistentvolumeclaim"
reported := reporter.Event(mb.TransformMapStrToEvent("kubernetes", event, nil))
if !reported {
m.Logger().Debug("error trying to emit event")
return
}
}
return
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

// +build !integration

package state_persistentvolumeclaim
Comment thread
odacremolbap marked this conversation as resolved.

import (
"testing"

"github.com/elastic/beats/metricbeat/helper/prometheus/ptest"
)

func TestEventMapping(t *testing.T) {
ptest.TestMetricSet(t, "kubernetes", "state_persistentvolumeclaim",
ptest.TestCases{
{
MetricsFile: "./_meta/test/ksm-unit-1.8",
ExpectedFile: "./_meta/test/ksm-unit-1.8.expected",
},
},
)
}