Skip to content

Commit 71944f7

Browse files
committed
add alarms metrics for server
Signed-off-by: yuzhiquanlong <yuzhiquanlong@gmail.com>
1 parent 5fab045 commit 71944f7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

server/etcdserver/apply/apply.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package apply
1616

1717
import (
1818
"context"
19-
2019
"github.com/coreos/go-semver/semver"
2120
pb "go.etcd.io/etcd/api/v3/etcdserverpb"
2221
"go.etcd.io/etcd/api/v3/membershippb"
@@ -34,8 +33,10 @@ import (
3433
serverstorage "go.etcd.io/etcd/server/v3/storage"
3534
"go.etcd.io/etcd/server/v3/storage/backend"
3635
"go.etcd.io/etcd/server/v3/storage/mvcc"
36+
"strconv"
3737

3838
"github.com/gogo/protobuf/proto"
39+
"github.com/prometheus/client_golang/prometheus"
3940
"go.uber.org/zap"
4041
)
4142

@@ -231,12 +232,14 @@ func (a *applierV3backend) Alarm(ar *pb.AlarmRequest) (*pb.AlarmResponse, error)
231232
break
232233
}
233234
resp.Alarms = append(resp.Alarms, m)
235+
alarms.With(prometheus.Labels{"server_id": strconv.FormatUint(uint64(types.ID(ar.MemberID)), 10)}).Inc()
234236
case pb.AlarmRequest_DEACTIVATE:
235237
m := a.alarmStore.Deactivate(types.ID(ar.MemberID), ar.Alarm)
236238
if m == nil {
237239
break
238240
}
239241
resp.Alarms = append(resp.Alarms, m)
242+
alarms.With(prometheus.Labels{"server_id": strconv.FormatUint(uint64(types.ID(ar.MemberID)), 10)}).Dec()
240243
default:
241244
return nil, nil
242245
}

server/etcdserver/apply/metrics.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2022 The etcd Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package apply
16+
17+
import "github.com/prometheus/client_golang/prometheus"
18+
19+
var (
20+
alarms = prometheus.NewGaugeVec(prometheus.GaugeOpts{
21+
Namespace: "etcd_debugging",
22+
Subsystem: "server",
23+
Name: "alarms",
24+
Help: "Alarms of every member in cluster.1 for 'server_id' label with current ID.",
25+
},
26+
[]string{"server_id"})
27+
)
28+
29+
func init() {
30+
prometheus.MustRegister(alarms)
31+
}

0 commit comments

Comments
 (0)