mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-12 06:17:27 -08:00
Merge pull request #9112 from darshanime/add_computer_name
Add computer name to azure sd
This commit is contained in:
commit
24165adadc
|
@ -46,6 +46,7 @@ const (
|
|||
azureLabelMachineID = azureLabel + "machine_id"
|
||||
azureLabelMachineResourceGroup = azureLabel + "machine_resource_group"
|
||||
azureLabelMachineName = azureLabel + "machine_name"
|
||||
azureLabelMachineComputerName = azureLabel + "machine_computer_name"
|
||||
azureLabelMachineOSType = azureLabel + "machine_os_type"
|
||||
azureLabelMachineLocation = azureLabel + "machine_location"
|
||||
azureLabelMachinePrivateIP = azureLabel + "machine_private_ip"
|
||||
|
@ -226,6 +227,7 @@ type azureResource struct {
|
|||
type virtualMachine struct {
|
||||
ID string
|
||||
Name string
|
||||
ComputerName string
|
||||
Type string
|
||||
Location string
|
||||
OsType string
|
||||
|
@ -306,6 +308,7 @@ func (d *Discovery) refresh(ctx context.Context) ([]*targetgroup.Group, error) {
|
|||
azureLabelTenantID: model.LabelValue(d.cfg.TenantID),
|
||||
azureLabelMachineID: model.LabelValue(vm.ID),
|
||||
azureLabelMachineName: model.LabelValue(vm.Name),
|
||||
azureLabelMachineComputerName: model.LabelValue(vm.ComputerName),
|
||||
azureLabelMachineOSType: model.LabelValue(vm.OsType),
|
||||
azureLabelMachineLocation: model.LabelValue(vm.Location),
|
||||
azureLabelMachineResourceGroup: model.LabelValue(r.ResourceGroup),
|
||||
|
@ -449,6 +452,7 @@ func mapFromVM(vm compute.VirtualMachine) virtualMachine {
|
|||
osType := string(vm.StorageProfile.OsDisk.OsType)
|
||||
tags := map[string]*string{}
|
||||
networkInterfaces := []string{}
|
||||
var computerName string
|
||||
|
||||
if vm.Tags != nil {
|
||||
tags = vm.Tags
|
||||
|
@ -460,9 +464,14 @@ func mapFromVM(vm compute.VirtualMachine) virtualMachine {
|
|||
}
|
||||
}
|
||||
|
||||
if vm.VirtualMachineProperties != nil && vm.VirtualMachineProperties.OsProfile != nil {
|
||||
computerName = *(vm.VirtualMachineProperties.OsProfile.ComputerName)
|
||||
}
|
||||
|
||||
return virtualMachine{
|
||||
ID: *(vm.ID),
|
||||
Name: *(vm.Name),
|
||||
ComputerName: computerName,
|
||||
Type: *(vm.Type),
|
||||
Location: *(vm.Location),
|
||||
OsType: osType,
|
||||
|
@ -476,6 +485,7 @@ func mapFromVMScaleSetVM(vm compute.VirtualMachineScaleSetVM, scaleSetName strin
|
|||
osType := string(vm.StorageProfile.OsDisk.OsType)
|
||||
tags := map[string]*string{}
|
||||
networkInterfaces := []string{}
|
||||
var computerName string
|
||||
|
||||
if vm.Tags != nil {
|
||||
tags = vm.Tags
|
||||
|
@ -487,9 +497,14 @@ func mapFromVMScaleSetVM(vm compute.VirtualMachineScaleSetVM, scaleSetName strin
|
|||
}
|
||||
}
|
||||
|
||||
if vm.VirtualMachineScaleSetVMProperties != nil && vm.VirtualMachineScaleSetVMProperties.OsProfile != nil {
|
||||
computerName = *(vm.VirtualMachineScaleSetVMProperties.OsProfile.ComputerName)
|
||||
}
|
||||
|
||||
return virtualMachine{
|
||||
ID: *(vm.ID),
|
||||
Name: *(vm.Name),
|
||||
ComputerName: computerName,
|
||||
Type: *(vm.Type),
|
||||
Location: *(vm.Location),
|
||||
OsType: osType,
|
||||
|
|
|
@ -30,10 +30,14 @@ func TestMapFromVMWithEmptyTags(t *testing.T) {
|
|||
name := "name"
|
||||
vmType := "type"
|
||||
location := "westeurope"
|
||||
computerName := "computer_name"
|
||||
networkProfile := compute.NetworkProfile{
|
||||
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
|
||||
}
|
||||
properties := &compute.VirtualMachineProperties{
|
||||
OsProfile: &compute.OSProfile{
|
||||
ComputerName: &computerName,
|
||||
},
|
||||
StorageProfile: &compute.StorageProfile{
|
||||
OsDisk: &compute.OSDisk{
|
||||
OsType: "Linux",
|
||||
|
@ -54,6 +58,7 @@ func TestMapFromVMWithEmptyTags(t *testing.T) {
|
|||
expectedVM := virtualMachine{
|
||||
ID: id,
|
||||
Name: name,
|
||||
ComputerName: computerName,
|
||||
Type: vmType,
|
||||
Location: location,
|
||||
OsType: "Linux",
|
||||
|
@ -71,6 +76,7 @@ func TestMapFromVMWithTags(t *testing.T) {
|
|||
name := "name"
|
||||
vmType := "type"
|
||||
location := "westeurope"
|
||||
computerName := "computer_name"
|
||||
tags := map[string]*string{
|
||||
"prometheus": new(string),
|
||||
}
|
||||
|
@ -78,6 +84,9 @@ func TestMapFromVMWithTags(t *testing.T) {
|
|||
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
|
||||
}
|
||||
properties := &compute.VirtualMachineProperties{
|
||||
OsProfile: &compute.OSProfile{
|
||||
ComputerName: &computerName,
|
||||
},
|
||||
StorageProfile: &compute.StorageProfile{
|
||||
OsDisk: &compute.OSDisk{
|
||||
OsType: "Linux",
|
||||
|
@ -98,6 +107,7 @@ func TestMapFromVMWithTags(t *testing.T) {
|
|||
expectedVM := virtualMachine{
|
||||
ID: id,
|
||||
Name: name,
|
||||
ComputerName: computerName,
|
||||
Type: vmType,
|
||||
Location: location,
|
||||
OsType: "Linux",
|
||||
|
@ -115,10 +125,14 @@ func TestMapFromVMScaleSetVMWithEmptyTags(t *testing.T) {
|
|||
name := "name"
|
||||
vmType := "type"
|
||||
location := "westeurope"
|
||||
computerName := "computer_name"
|
||||
networkProfile := compute.NetworkProfile{
|
||||
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
|
||||
}
|
||||
properties := &compute.VirtualMachineScaleSetVMProperties{
|
||||
OsProfile: &compute.OSProfile{
|
||||
ComputerName: &computerName,
|
||||
},
|
||||
StorageProfile: &compute.StorageProfile{
|
||||
OsDisk: &compute.OSDisk{
|
||||
OsType: "Linux",
|
||||
|
@ -140,6 +154,7 @@ func TestMapFromVMScaleSetVMWithEmptyTags(t *testing.T) {
|
|||
expectedVM := virtualMachine{
|
||||
ID: id,
|
||||
Name: name,
|
||||
ComputerName: computerName,
|
||||
Type: vmType,
|
||||
Location: location,
|
||||
OsType: "Linux",
|
||||
|
@ -158,6 +173,7 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
|
|||
name := "name"
|
||||
vmType := "type"
|
||||
location := "westeurope"
|
||||
computerName := "computer_name"
|
||||
tags := map[string]*string{
|
||||
"prometheus": new(string),
|
||||
}
|
||||
|
@ -165,6 +181,9 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
|
|||
NetworkInterfaces: &[]compute.NetworkInterfaceReference{},
|
||||
}
|
||||
properties := &compute.VirtualMachineScaleSetVMProperties{
|
||||
OsProfile: &compute.OSProfile{
|
||||
ComputerName: &computerName,
|
||||
},
|
||||
StorageProfile: &compute.StorageProfile{
|
||||
OsDisk: &compute.OSDisk{
|
||||
OsType: "Linux",
|
||||
|
@ -186,6 +205,7 @@ func TestMapFromVMScaleSetVMWithTags(t *testing.T) {
|
|||
expectedVM := virtualMachine{
|
||||
ID: id,
|
||||
Name: name,
|
||||
ComputerName: computerName,
|
||||
Type: vmType,
|
||||
Location: location,
|
||||
OsType: "Linux",
|
||||
|
|
|
@ -386,6 +386,7 @@ The following meta labels are available on targets during [relabeling](#relabel_
|
|||
* `__meta_azure_machine_id`: the machine ID
|
||||
* `__meta_azure_machine_location`: the location the machine runs in
|
||||
* `__meta_azure_machine_name`: the machine name
|
||||
* `__meta_azure_machine_computer_name`: the machine computer name
|
||||
* `__meta_azure_machine_os_type`: the machine operating system
|
||||
* `__meta_azure_machine_private_ip`: the machine's private IP
|
||||
* `__meta_azure_machine_public_ip`: the machine's public IP if it exists
|
||||
|
|
Loading…
Reference in a new issue