Skip to content

Commit

Permalink
専有サーバのIDをラベルに追加 (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamamoto-febc authored Aug 3, 2022
1 parent b905097 commit 2991b97
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ The exporter returns the following metrics:
#### Server

| Metric | Description | Labels |
| ------ | ----------- | ------ |
| sakuracloud_server_info | A metric with a constant '1' value labeled by server information | `id`, `name`, `zone`, `cpus`, `disks`, `nics`, `memories`, `host`, `tags`, `description` |
| ------ | ----------- |----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| sakuracloud_server_info | A metric with a constant '1' value labeled by server information | `id`, `name`, `zone`, `cpus`, `disks`, `nics`, `memories`, `host`, `tags`, `description`, `private_host_id` |
| sakuracloud_server_up | If 1 the server is up and running, 0 otherwise | `id`, `name`, `zone` |
| sakuracloud_server_cpus | Number of server's vCPU cores | `id`, `name`, `zone` |
| sakuracloud_server_cpu_time | Server's CPU time(unit: ms) | `id`, `name`, `zone` |
Expand Down
2 changes: 1 addition & 1 deletion collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func requireMetricsEqual(t *testing.T, m1, m2 []*collectedMetric) {
}
return labelToString(m2[i].metric.Label) < labelToString(m2[j].metric.Label)
})
require.Equal(t, m1, m2)
require.EqualValues(t, m1, m2)
}

func initLoggerAndErrors() {
Expand Down
3 changes: 2 additions & 1 deletion collector/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewServerCollector(ctx context.Context, logger log.Logger, errors *promethe
errors.WithLabelValues("server").Add(0)

serverLabels := []string{"id", "name", "zone"}
serverInfoLabels := append(serverLabels, "cpus", "disks", "nics", "memories", "host", "tags", "description")
serverInfoLabels := append(serverLabels, "cpus", "disks", "nics", "memories", "host", "tags", "description", "private_host_id")
diskLabels := append(serverLabels, "disk_id", "disk_name", "index")
diskInfoLabels := append(diskLabels, "plan", "interface", "size", "tags", "description", "storage_id", "storage_generation", "storage_class")
nicLabels := append(serverLabels, "interface_id", "index")
Expand Down Expand Up @@ -329,6 +329,7 @@ func (c *ServerCollector) serverInfoLabels(server *platform.Server) []string {
instanceHost,
flattenStringSlice(server.Tags),
server.Description,
server.PrivateHostID.String(),
)
}

Expand Down
69 changes: 37 additions & 32 deletions collector/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func TestServerCollector_Collect(t *testing.T) {
},
},
},
PrivateHostID: 3001,
PrivateHostName: "private-host-name",
Interfaces: []*iaas.InterfaceView{
{
ID: 301,
Expand Down Expand Up @@ -179,16 +181,17 @@ func TestServerCollector_Collect(t *testing.T) {
{
desc: c.ServerInfo,
metric: createGaugeMetric(1, map[string]string{
"id": "101",
"name": "server",
"zone": "is1a",
"cpus": "2",
"disks": "1",
"nics": "1",
"memories": "4",
"host": "sacXXX",
"tags": ",tag1,tag2,",
"description": "desc",
"id": "101",
"name": "server",
"zone": "is1a",
"cpus": "2",
"disks": "1",
"nics": "1",
"memories": "4",
"host": "sacXXX",
"tags": ",tag1,tag2,",
"description": "desc",
"private_host_id": "3001",
}),
},
{
Expand Down Expand Up @@ -236,7 +239,7 @@ func TestServerCollector_Collect(t *testing.T) {
// },
{
desc: c.NICBandwidth,
metric: createGaugeMetric(1000, map[string]string{
metric: createGaugeMetric(0, map[string]string{ // 専有ホストの場合は0
"id": "101",
"name": "server",
"zone": "is1a",
Expand Down Expand Up @@ -329,16 +332,17 @@ func TestServerCollector_Collect(t *testing.T) {
{
desc: c.ServerInfo,
metric: createGaugeMetric(1, map[string]string{
"id": "101",
"name": "server",
"zone": "is1a",
"cpus": "2",
"disks": "1",
"nics": "1",
"memories": "4",
"host": "sacXXX",
"tags": ",tag1,tag2,",
"description": "desc",
"id": "101",
"name": "server",
"zone": "is1a",
"cpus": "2",
"disks": "1",
"nics": "1",
"memories": "4",
"host": "sacXXX",
"tags": ",tag1,tag2,",
"description": "desc",
"private_host_id": "3001",
}),
},
{
Expand Down Expand Up @@ -386,7 +390,7 @@ func TestServerCollector_Collect(t *testing.T) {
// },
{
desc: c.NICBandwidth,
metric: createGaugeMetric(1000, map[string]string{
metric: createGaugeMetric(0, map[string]string{
"id": "101",
"name": "server",
"zone": "is1a",
Expand Down Expand Up @@ -453,16 +457,17 @@ func TestServerCollector_Collect(t *testing.T) {
{
desc: c.ServerInfo,
metric: createGaugeMetric(1, map[string]string{
"id": "101",
"name": "server",
"zone": "is1a",
"cpus": "2",
"disks": "0",
"nics": "0",
"memories": "4",
"host": "sacXXX",
"tags": "",
"description": "",
"id": "101",
"name": "server",
"zone": "is1a",
"cpus": "2",
"disks": "0",
"nics": "0",
"memories": "4",
"host": "sacXXX",
"tags": "",
"description": "",
"private_host_id": "",
}),
},
{
Expand Down
14 changes: 14 additions & 0 deletions e2e/minimum/e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2019-2022 The sacloud/sakuracloud_exporter Authors
//
// Licensed 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.

//go:build e2e
// +build e2e

Expand Down

0 comments on commit 2991b97

Please sign in to comment.