parent
d11c418102
commit
3ef153b00c
@ -0,0 +1,170 @@ |
|||||||
|
// Copyright 2022 The Prometheus 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.
|
||||||
|
|
||||||
|
package vultr |
||||||
|
|
||||||
|
import ( |
||||||
|
"fmt" |
||||||
|
"net/http" |
||||||
|
"net/http/httptest" |
||||||
|
"testing" |
||||||
|
) |
||||||
|
|
||||||
|
// SDMock is the interface for the Vultr mock
|
||||||
|
type SDMock struct { |
||||||
|
t *testing.T |
||||||
|
Server *httptest.Server |
||||||
|
Mux *http.ServeMux |
||||||
|
} |
||||||
|
|
||||||
|
// NewSDMock returns a new SDMock.
|
||||||
|
func NewSDMock(t *testing.T) *SDMock { |
||||||
|
return &SDMock{ |
||||||
|
t: t, |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
// Endpoint returns the URI to the mock server
|
||||||
|
func (m *SDMock) Endpoint() string { |
||||||
|
return m.Server.URL + "/" |
||||||
|
} |
||||||
|
|
||||||
|
// Setup creates the mock server
|
||||||
|
func (m *SDMock) Setup() { |
||||||
|
m.Mux = http.NewServeMux() |
||||||
|
m.Server = httptest.NewServer(m.Mux) |
||||||
|
} |
||||||
|
|
||||||
|
// ShutdownServer creates the mock server
|
||||||
|
func (m *SDMock) ShutdownServer() { |
||||||
|
m.Server.Close() |
||||||
|
} |
||||||
|
|
||||||
|
const APIKey = "ABCBTDG35OTGH2UKCC3S6CNMDUPCN3ZWSGFQ" |
||||||
|
|
||||||
|
// HandleInstanceList mocks vultr instances list.
|
||||||
|
func (m *SDMock) HandleInstanceList() { |
||||||
|
m.Mux.HandleFunc("/v2/instances", func(w http.ResponseWriter, r *http.Request) { |
||||||
|
if r.Header.Get("Authorization") != fmt.Sprintf("Bearer %s", APIKey) { |
||||||
|
w.WriteHeader(http.StatusForbidden) |
||||||
|
return |
||||||
|
} |
||||||
|
|
||||||
|
w.Header().Add("content-type", "application/json; charset=utf-8") |
||||||
|
w.WriteHeader(http.StatusOK) |
||||||
|
|
||||||
|
fmt.Fprint(w, ` |
||||||
|
{ |
||||||
|
"instances": [ |
||||||
|
{ |
||||||
|
"id": "dbdbd38c-9884-4c92-95fe-899e50dee717", |
||||||
|
"os": "Marketplace", |
||||||
|
"ram": 4096, |
||||||
|
"disk": 128, |
||||||
|
"main_ip": "149.28.234.27", |
||||||
|
"vcpu_count": 2, |
||||||
|
"region": "ewr", |
||||||
|
"plan": "vhf-2c-4gb", |
||||||
|
"date_created": "2022-03-10T02:25:30+00:00", |
||||||
|
"status": "active", |
||||||
|
"allowed_bandwidth": 3000, |
||||||
|
"netmask_v4": "255.255.254.0", |
||||||
|
"gateway_v4": "149.28.234.1", |
||||||
|
"power_status": "running", |
||||||
|
"server_status": "ok", |
||||||
|
"v6_network": "", |
||||||
|
"v6_main_ip": "", |
||||||
|
"v6_network_size": 0, |
||||||
|
"label": "np-2-eae38a19b0f3", |
||||||
|
"internal_ip": "10.1.96.5", |
||||||
|
"kvm": "https://my.vultr.com/subs/vps/novnc/api.php?data=djJ8Q2k2NlVpNUlZNE5kM3NZMWdBNzFKUkVadDBDU3ItTEJ8-yNWBdMn1AWPqX-EnpTVbA1qBeP0txBZbahSOh3UtHIL2p0fZKEdFJwFNjWtvBKC9BGvJkoJdWBoo7hF-6RzavdUKPD3KIU5xD_T6keV8X-PPukPgXMuSUaAqurAuJvwAWXcTcodBjaIH961xgbvfkFyqVl0ZgHf3ErZQE-EmpZ0Jc3uF1DO2McJ4UL8KUvHLwa-ZDUZ_AtWJjQWsjNkxjvOiA", |
||||||
|
"hostname": "np-2-eae38a19b0f3", |
||||||
|
"os_id": 426, |
||||||
|
"app_id": 0, |
||||||
|
"image_id": "vke-worker", |
||||||
|
"firewall_group_id": "", |
||||||
|
"features": ["backups"], |
||||||
|
"tags": ["tag1", "tag2", "tag3"] |
||||||
|
}, |
||||||
|
{ |
||||||
|
"id": "fccb117c-62f7-4b17-995d-a8e56dd30b33", |
||||||
|
"os": "Marketplace", |
||||||
|
"ram": 4096, |
||||||
|
"disk": 128, |
||||||
|
"main_ip": "45.63.1.222", |
||||||
|
"vcpu_count": 2, |
||||||
|
"region": "ewr", |
||||||
|
"plan": "vhf-2c-4gb", |
||||||
|
"date_created": "2022-03-10T02:25:32+00:00", |
||||||
|
"status": "active", |
||||||
|
"allowed_bandwidth": 3000, |
||||||
|
"netmask_v4": "255.255.254.0", |
||||||
|
"gateway_v4": "45.63.0.1", |
||||||
|
"power_status": "running", |
||||||
|
"server_status": "ok", |
||||||
|
"v6_network": "", |
||||||
|
"v6_main_ip": "", |
||||||
|
"v6_network_size": 0, |
||||||
|
"label": "np-2-fd0714b5fe42", |
||||||
|
"internal_ip": "10.1.96.6", |
||||||
|
"kvm": "https://my.vultr.com/subs/vps/novnc/api.php?data=djJ8R0tzbmI0VWVfSDR6VE51Q0FGUTBCamwyTFNzZDNkVTF8Zwm93t6L2BLTYSNmM0g0Ppf43r71aIbqLiJCx6_1NuCugUqIKz8POshH91vi6XXDorpb3hYTk8RrJWQbaFMak7XbbfMObzsrFxKAQUVGfbjTBIHCKftxNIXeQOp1fEIDa3p-vkfSxEpx6ZX8nChGYYSVuOjS1twV6oI_IKtHXKdFJiVFz0Unay_K3HuXW_H2wrYSjmAChloR-eA1jSmBXLccJQ", |
||||||
|
"hostname": "np-2-fd0714b5fe42", |
||||||
|
"os_id": 426, |
||||||
|
"app_id": 0, |
||||||
|
"image_id": "vke-worker", |
||||||
|
"firewall_group_id": "", |
||||||
|
"features": [], |
||||||
|
"tags": [] |
||||||
|
}, |
||||||
|
{ |
||||||
|
"id": "c4e58767-f61b-4c5e-9bce-43761cc04868", |
||||||
|
"os": "Marketplace", |
||||||
|
"ram": 4096, |
||||||
|
"disk": 128, |
||||||
|
"main_ip": "149.28.237.151", |
||||||
|
"vcpu_count": 2, |
||||||
|
"region": "ewr", |
||||||
|
"plan": "vhf-2c-4gb", |
||||||
|
"date_created": "2022-03-10T02:25:33+00:00", |
||||||
|
"status": "active", |
||||||
|
"allowed_bandwidth": 3000, |
||||||
|
"netmask_v4": "255.255.254.0", |
||||||
|
"gateway_v4": "149.28.236.1", |
||||||
|
"power_status": "running", |
||||||
|
"server_status": "ok", |
||||||
|
"v6_network": "", |
||||||
|
"v6_main_ip": "", |
||||||
|
"v6_network_size": 0, |
||||||
|
"label": "np-2-d04e7829fa43", |
||||||
|
"internal_ip": "10.1.96.7", |
||||||
|
"kvm": "https://my.vultr.com/subs/vps/novnc/api.php?data=djJ8NFEzbFZmV2hOUWNrc2R4bndnckhFQTJ3ME1yWmxVeW98P-p-KeyNtP73wzVvuWZSOrV5PvQDiBmYyB3cp99btIy5nczmvX8DOGSChbEldk3idKNdFLQMIieWnpR5xU5K-dMYlL6n6oYv2u-rh8zxS6-8hQsSbL2OsoywNPoLpQ3xPkT9Rb-yPrZX4fDLbt8yPVKDHqHO0GB-TxVPemueovfkkUZMXSraAXgHtl1YgK2uLMQf1WBFVzgwnQ7MYcfMGGYFQw", |
||||||
|
"hostname": "np-2-d04e7829fa43", |
||||||
|
"os_id": 426, |
||||||
|
"app_id": 0, |
||||||
|
"image_id": "vke-worker", |
||||||
|
"firewall_group_id": "", |
||||||
|
"features": [], |
||||||
|
"tags": [] |
||||||
|
} |
||||||
|
], |
||||||
|
"meta": { |
||||||
|
"total": 3, |
||||||
|
"links": { |
||||||
|
"next": "", |
||||||
|
"prev": "" |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
`) |
||||||
|
}) |
||||||
|
} |
@ -0,0 +1,212 @@ |
|||||||
|
// Copyright 2022 The Prometheus 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.
|
||||||
|
|
||||||
|
package vultr |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"fmt" |
||||||
|
"net" |
||||||
|
"net/http" |
||||||
|
"strconv" |
||||||
|
"strings" |
||||||
|
"time" |
||||||
|
|
||||||
|
"github.com/go-kit/log" |
||||||
|
"github.com/prometheus/common/config" |
||||||
|
"github.com/prometheus/common/model" |
||||||
|
"github.com/prometheus/common/version" |
||||||
|
"github.com/vultr/govultr/v2" |
||||||
|
|
||||||
|
"github.com/prometheus/prometheus/discovery" |
||||||
|
"github.com/prometheus/prometheus/discovery/refresh" |
||||||
|
"github.com/prometheus/prometheus/discovery/targetgroup" |
||||||
|
) |
||||||
|
|
||||||
|
const ( |
||||||
|
vultrInstanceLabel = model.MetaLabelPrefix + "vultr_instance_" |
||||||
|
vultrInstanceLabelID = vultrInstanceLabel + "id" |
||||||
|
vultrInstanceLabelLabel = vultrInstanceLabel + "label" |
||||||
|
vultrInstanceLabelOS = vultrInstanceLabel + "os" |
||||||
|
vultrInstanceLabelOSID = vultrInstanceLabel + "os_id" |
||||||
|
vultrInstanceLabelRegion = vultrInstanceLabel + "region" |
||||||
|
vultrInstanceLabelPlan = vultrInstanceLabel + "plan" |
||||||
|
vultrInstanceLabelMainIP = vultrInstanceLabel + "main_ip" |
||||||
|
vultrInstanceLabelMainIPV6 = vultrInstanceLabel + "main_ipv6" |
||||||
|
vultrInstanceLabelInternalIP = vultrInstanceLabel + "internal_ip" |
||||||
|
vultrInstanceLabelFeatures = vultrInstanceLabel + "features" |
||||||
|
vultrInstanceLabelTags = vultrInstanceLabel + "tags" |
||||||
|
vultrInstanceLabelHostname = vultrInstanceLabel + "hostname" |
||||||
|
vultrInstanceLabelServerStatus = vultrInstanceLabel + "server_status" |
||||||
|
vultrInstanceLabelVCPU = vultrInstanceLabel + "vcpu_count" |
||||||
|
vultrInstanceLabelMemory = vultrInstanceLabel + "ram_bytes" |
||||||
|
vultrInstanceLabelBandwidth = vultrInstanceLabel + "allowed_bandwidth_gb" |
||||||
|
vultrInstanceLabelDisk = vultrInstanceLabel + "disk_gb" |
||||||
|
separator = "," |
||||||
|
) |
||||||
|
|
||||||
|
// DefaultSDConfig is the default Vultr SD configuration.
|
||||||
|
var DefaultSDConfig = SDConfig{ |
||||||
|
Port: 80, |
||||||
|
RefreshInterval: model.Duration(60 * time.Second), |
||||||
|
HTTPClientConfig: config.DefaultHTTPClientConfig, |
||||||
|
} |
||||||
|
|
||||||
|
func init() { |
||||||
|
discovery.RegisterConfig(&SDConfig{}) |
||||||
|
} |
||||||
|
|
||||||
|
type SDConfig struct { |
||||||
|
HTTPClientConfig config.HTTPClientConfig `yaml:",inline"` |
||||||
|
|
||||||
|
RefreshInterval model.Duration `yaml:"refresh_interval"` |
||||||
|
Port int `yaml:"port"` |
||||||
|
} |
||||||
|
|
||||||
|
// Name returns the name of the Config.
|
||||||
|
func (*SDConfig) Name() string { return "vultr" } |
||||||
|
|
||||||
|
// NewDiscoverer returns a Discoverer for the Config.
|
||||||
|
func (c *SDConfig) NewDiscoverer(opts discovery.DiscovererOptions) (discovery.Discoverer, error) { |
||||||
|
return NewDiscovery(c, opts.Logger) |
||||||
|
} |
||||||
|
|
||||||
|
// SetDirectory joins any relative file paths with dir.
|
||||||
|
func (c *SDConfig) SetDirectory(dir string) { |
||||||
|
c.HTTPClientConfig.SetDirectory(dir) |
||||||
|
} |
||||||
|
|
||||||
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
||||||
|
func (c *SDConfig) UnmarshalYAML(unmarshal func(interface{}) error) error { |
||||||
|
*c = DefaultSDConfig |
||||||
|
type plain SDConfig |
||||||
|
if err := unmarshal((*plain)(c)); err != nil { |
||||||
|
return err |
||||||
|
} |
||||||
|
|
||||||
|
return c.HTTPClientConfig.Validate() |
||||||
|
} |
||||||
|
|
||||||
|
// Discovery periodically performs Vultr requests. It implements
|
||||||
|
// the Discoverer interface.
|
||||||
|
type Discovery struct { |
||||||
|
*refresh.Discovery |
||||||
|
client *govultr.Client |
||||||
|
port int |
||||||
|
} |
||||||
|
|
||||||
|
// NewDiscovery returns a new Discovery which periodically refreshes its targets.
|
||||||
|
func NewDiscovery(conf *SDConfig, logger log.Logger) (*Discovery, error) { |
||||||
|
d := &Discovery{ |
||||||
|
port: conf.Port, |
||||||
|
} |
||||||
|
|
||||||
|
rt, err := config.NewRoundTripperFromConfig(conf.HTTPClientConfig, "vultr_sd") |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
d.client = govultr.NewClient(&http.Client{ |
||||||
|
Transport: rt, |
||||||
|
Timeout: time.Duration(conf.RefreshInterval), |
||||||
|
}) |
||||||
|
|
||||||
|
d.client.SetUserAgent(fmt.Sprintf("Prometheus/%s", version.Version)) |
||||||
|
|
||||||
|
if err != nil { |
||||||
|
return nil, fmt.Errorf("error setting up vultr agent: %w", err) |
||||||
|
} |
||||||
|
|
||||||
|
d.Discovery = refresh.NewDiscovery( |
||||||
|
logger, |
||||||
|
"vultr", |
||||||
|
time.Duration(conf.RefreshInterval), |
||||||
|
d.refresh, |
||||||
|
) |
||||||
|
return d, nil |
||||||
|
} |
||||||
|
|
||||||
|
func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) { |
||||||
|
tg := &targetgroup.Group{ |
||||||
|
Source: "Vultr", |
||||||
|
} |
||||||
|
|
||||||
|
instances, err := d.listInstances(ctx) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
|
||||||
|
for _, instance := range instances { |
||||||
|
labels := model.LabelSet{ |
||||||
|
vultrInstanceLabelID: model.LabelValue(instance.ID), |
||||||
|
vultrInstanceLabelLabel: model.LabelValue(instance.Label), |
||||||
|
vultrInstanceLabelOS: model.LabelValue(instance.Os), |
||||||
|
vultrInstanceLabelOSID: model.LabelValue(strconv.Itoa(instance.OsID)), |
||||||
|
vultrInstanceLabelRegion: model.LabelValue(instance.Region), |
||||||
|
vultrInstanceLabelPlan: model.LabelValue(instance.Plan), |
||||||
|
vultrInstanceLabelVCPU: model.LabelValue(strconv.Itoa(instance.VCPUCount)), |
||||||
|
vultrInstanceLabelMemory: model.LabelValue(strconv.Itoa(instance.RAM)), |
||||||
|
vultrInstanceLabelBandwidth: model.LabelValue(strconv.Itoa(instance.AllowedBandwidth)), |
||||||
|
vultrInstanceLabelDisk: model.LabelValue(strconv.Itoa(instance.Disk)), |
||||||
|
vultrInstanceLabelMainIP: model.LabelValue(instance.MainIP), |
||||||
|
vultrInstanceLabelMainIPV6: model.LabelValue(instance.V6MainIP), |
||||||
|
vultrInstanceLabelInternalIP: model.LabelValue(instance.InternalIP), |
||||||
|
vultrInstanceLabelHostname: model.LabelValue(instance.Hostname), |
||||||
|
vultrInstanceLabelServerStatus: model.LabelValue(instance.ServerStatus), |
||||||
|
} |
||||||
|
|
||||||
|
addr := net.JoinHostPort(instance.MainIP, strconv.FormatUint(uint64(d.port), 10)) |
||||||
|
labels[model.AddressLabel] = model.LabelValue(addr) |
||||||
|
|
||||||
|
// We surround the separated list with the separator as well. This way regular expressions
|
||||||
|
// in relabeling rules don't have to consider feature positions.
|
||||||
|
if len(instance.Features) > 0 { |
||||||
|
features := separator + strings.Join(instance.Features, separator) + separator |
||||||
|
labels[vultrInstanceLabelFeatures] = model.LabelValue(features) |
||||||
|
} |
||||||
|
|
||||||
|
if len(instance.Tags) > 0 { |
||||||
|
tags := separator + strings.Join(instance.Tags, separator) + separator |
||||||
|
labels[vultrInstanceLabelTags] = model.LabelValue(tags) |
||||||
|
} |
||||||
|
|
||||||
|
tg.Targets = append(tg.Targets, labels) |
||||||
|
} |
||||||
|
|
||||||
|
return []*targetgroup.Group{tg}, nil |
||||||
|
} |
||||||
|
|
||||||
|
func (d *Discovery) listInstances(ctx context.Context) ([]govultr.Instance, error) { |
||||||
|
var instances []govultr.Instance |
||||||
|
|
||||||
|
listOptions := &govultr.ListOptions{ |
||||||
|
PerPage: 100, |
||||||
|
} |
||||||
|
|
||||||
|
for { |
||||||
|
pagedInstances, meta, err := d.client.Instance.List(ctx, listOptions) |
||||||
|
if err != nil { |
||||||
|
return nil, err |
||||||
|
} |
||||||
|
instances = append(instances, pagedInstances...) |
||||||
|
|
||||||
|
if meta.Links.Next == "" { |
||||||
|
break |
||||||
|
} else { |
||||||
|
listOptions.Cursor = meta.Links.Next |
||||||
|
continue |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return instances, nil |
||||||
|
} |
@ -0,0 +1,128 @@ |
|||||||
|
// Copyright 2022 The Prometheus 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.
|
||||||
|
|
||||||
|
package vultr |
||||||
|
|
||||||
|
import ( |
||||||
|
"context" |
||||||
|
"fmt" |
||||||
|
"net/url" |
||||||
|
"testing" |
||||||
|
|
||||||
|
"github.com/go-kit/log" |
||||||
|
"github.com/prometheus/common/model" |
||||||
|
"github.com/stretchr/testify/require" |
||||||
|
) |
||||||
|
|
||||||
|
type VultrSDTestSuite struct { |
||||||
|
Mock *SDMock |
||||||
|
} |
||||||
|
|
||||||
|
func (s *VultrSDTestSuite) TearDownSuite() { |
||||||
|
s.Mock.ShutdownServer() |
||||||
|
} |
||||||
|
|
||||||
|
func (s *VultrSDTestSuite) SetupTest(t *testing.T) { |
||||||
|
s.Mock = NewSDMock(t) |
||||||
|
s.Mock.Setup() |
||||||
|
|
||||||
|
s.Mock.HandleInstanceList() |
||||||
|
} |
||||||
|
|
||||||
|
func TestVultrSDRefresh(t *testing.T) { |
||||||
|
sdMock := &VultrSDTestSuite{} |
||||||
|
sdMock.SetupTest(t) |
||||||
|
t.Cleanup(sdMock.TearDownSuite) |
||||||
|
|
||||||
|
cfg := DefaultSDConfig |
||||||
|
cfg.HTTPClientConfig.BearerToken = APIKey |
||||||
|
d, err := NewDiscovery(&cfg, log.NewNopLogger()) |
||||||
|
require.NoError(t, err) |
||||||
|
endpoint, err := url.Parse(sdMock.Mock.Endpoint()) |
||||||
|
require.NoError(t, err) |
||||||
|
d.client.BaseURL = endpoint |
||||||
|
|
||||||
|
ctx := context.Background() |
||||||
|
tgs, err := d.refresh(ctx) |
||||||
|
require.NoError(t, err) |
||||||
|
|
||||||
|
require.Equal(t, 1, len(tgs)) |
||||||
|
|
||||||
|
tg := tgs[0] |
||||||
|
require.NotNil(t, tg) |
||||||
|
require.NotNil(t, tg.Targets) |
||||||
|
require.Equal(t, 3, len(tg.Targets)) |
||||||
|
|
||||||
|
for i, k := range []model.LabelSet{ |
||||||
|
{ |
||||||
|
"__address__": model.LabelValue("149.28.234.27:80"), |
||||||
|
"__meta_vultr_instance_id": model.LabelValue("dbdbd38c-9884-4c92-95fe-899e50dee717"), |
||||||
|
"__meta_vultr_instance_label": model.LabelValue("np-2-eae38a19b0f3"), |
||||||
|
"__meta_vultr_instance_os": model.LabelValue("Marketplace"), |
||||||
|
"__meta_vultr_instance_os_id": model.LabelValue("426"), |
||||||
|
"__meta_vultr_instance_region": model.LabelValue("ewr"), |
||||||
|
"__meta_vultr_instance_plan": model.LabelValue("vhf-2c-4gb"), |
||||||
|
"__meta_vultr_instance_main_ip": model.LabelValue("149.28.234.27"), |
||||||
|
"__meta_vultr_instance_internal_ip": model.LabelValue("10.1.96.5"), |
||||||
|
"__meta_vultr_instance_main_ipv6": model.LabelValue(""), |
||||||
|
"__meta_vultr_instance_features": model.LabelValue(",backups,"), |
||||||
|
"__meta_vultr_instance_tags": model.LabelValue(",tag1,tag2,tag3,"), |
||||||
|
"__meta_vultr_instance_hostname": model.LabelValue("np-2-eae38a19b0f3"), |
||||||
|
"__meta_vultr_instance_server_status": model.LabelValue("ok"), |
||||||
|
"__meta_vultr_instance_vcpu_count": model.LabelValue("2"), |
||||||
|
"__meta_vultr_instance_ram_bytes": model.LabelValue("4096"), |
||||||
|
"__meta_vultr_instance_disk_gb": model.LabelValue("128"), |
||||||
|
"__meta_vultr_instance_allowed_bandwidth_gb": model.LabelValue("3000"), |
||||||
|
}, |
||||||
|
{ |
||||||
|
"__address__": model.LabelValue("45.63.1.222:80"), |
||||||
|
"__meta_vultr_instance_id": model.LabelValue("fccb117c-62f7-4b17-995d-a8e56dd30b33"), |
||||||
|
"__meta_vultr_instance_label": model.LabelValue("np-2-fd0714b5fe42"), |
||||||
|
"__meta_vultr_instance_os": model.LabelValue("Marketplace"), |
||||||
|
"__meta_vultr_instance_os_id": model.LabelValue("426"), |
||||||
|
"__meta_vultr_instance_region": model.LabelValue("ewr"), |
||||||
|
"__meta_vultr_instance_plan": model.LabelValue("vhf-2c-4gb"), |
||||||
|
"__meta_vultr_instance_main_ip": model.LabelValue("45.63.1.222"), |
||||||
|
"__meta_vultr_instance_internal_ip": model.LabelValue("10.1.96.6"), |
||||||
|
"__meta_vultr_instance_main_ipv6": model.LabelValue(""), |
||||||
|
"__meta_vultr_instance_hostname": model.LabelValue("np-2-fd0714b5fe42"), |
||||||
|
"__meta_vultr_instance_server_status": model.LabelValue("ok"), |
||||||
|
"__meta_vultr_instance_vcpu_count": model.LabelValue("2"), |
||||||
|
"__meta_vultr_instance_ram_bytes": model.LabelValue("4096"), |
||||||
|
"__meta_vultr_instance_disk_gb": model.LabelValue("128"), |
||||||
|
"__meta_vultr_instance_allowed_bandwidth_gb": model.LabelValue("3000"), |
||||||
|
}, |
||||||
|
{ |
||||||
|
"__address__": model.LabelValue("149.28.237.151:80"), |
||||||
|
"__meta_vultr_instance_id": model.LabelValue("c4e58767-f61b-4c5e-9bce-43761cc04868"), |
||||||
|
"__meta_vultr_instance_label": model.LabelValue("np-2-d04e7829fa43"), |
||||||
|
"__meta_vultr_instance_os": model.LabelValue("Marketplace"), |
||||||
|
"__meta_vultr_instance_os_id": model.LabelValue("426"), |
||||||
|
"__meta_vultr_instance_region": model.LabelValue("ewr"), |
||||||
|
"__meta_vultr_instance_plan": model.LabelValue("vhf-2c-4gb"), |
||||||
|
"__meta_vultr_instance_main_ip": model.LabelValue("149.28.237.151"), |
||||||
|
"__meta_vultr_instance_internal_ip": model.LabelValue("10.1.96.7"), |
||||||
|
"__meta_vultr_instance_main_ipv6": model.LabelValue(""), |
||||||
|
"__meta_vultr_instance_hostname": model.LabelValue("np-2-d04e7829fa43"), |
||||||
|
"__meta_vultr_instance_server_status": model.LabelValue("ok"), |
||||||
|
"__meta_vultr_instance_vcpu_count": model.LabelValue("2"), |
||||||
|
"__meta_vultr_instance_ram_bytes": model.LabelValue("4096"), |
||||||
|
"__meta_vultr_instance_disk_gb": model.LabelValue("128"), |
||||||
|
"__meta_vultr_instance_allowed_bandwidth_gb": model.LabelValue("3000"), |
||||||
|
}, |
||||||
|
} { |
||||||
|
t.Run(fmt.Sprintf("item %d", i), func(t *testing.T) { |
||||||
|
require.Equal(t, k, tg.Targets[i]) |
||||||
|
}) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,24 @@ |
|||||||
|
# An example scrape configuration for running Prometheus with |
||||||
|
# Vultr. |
||||||
|
|
||||||
|
scrape_configs: |
||||||
|
# Make Prometheus scrape itself for metrics. |
||||||
|
- job_name: "prometheus" |
||||||
|
static_configs: |
||||||
|
- targets: ["localhost:9090"] |
||||||
|
|
||||||
|
# Discover Node Exporter instances to scrape. |
||||||
|
- job_name: "node" |
||||||
|
vultr_sd_configs: |
||||||
|
- authorization: |
||||||
|
credentials: "<replace with a Personal Access Token>" |
||||||
|
relabel_configs: |
||||||
|
# Only scrape targets that have a tag 'monitoring'. |
||||||
|
- source_labels: [__meta_vultr_instance_tags] |
||||||
|
regex: ".*,monitoring,.*" |
||||||
|
action: keep |
||||||
|
|
||||||
|
# Use the public IPv6 address and port 9100 to scrape the target. |
||||||
|
- source_labels: [__meta_vultr_instance_main_ipv6] |
||||||
|
target_label: __address__ |
||||||
|
replacement: "[$1]:9100" |
Loading…
Reference in new issue