Skip to content

Commit

Permalink
add datastore capacity and free
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Seidenstricker committed Sep 1, 2017
1 parent d62d5bf commit ce1d720
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
28 changes: 27 additions & 1 deletion vsphere-influxdb.go
Expand Up @@ -221,6 +221,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
}
objectTypes = append(objectTypes, "ClusterComputeResource")
objectTypes = append(objectTypes, "ResourcePool")
objectTypes = append(objectTypes, "Datastore")

// Loop trought datacenters and create the intersting object reference list
mors := []types.ManagedObjectReference{}
Expand Down Expand Up @@ -250,6 +251,7 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
hostRefs := []types.ManagedObjectReference{}
clusterRefs := []types.ManagedObjectReference{}
respoolRefs := []types.ManagedObjectReference{}
datastoreRefs := []types.ManagedObjectReference{}

newMors := []types.ManagedObjectReference{}

Expand All @@ -268,7 +270,9 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
clusterRefs = append(clusterRefs, mor)
} else if mor.Type == "ResourcePool" {
respoolRefs = append(respoolRefs, mor)
}
} else if mor.Type == "Datastore" {
datastoreRefs = append(datastoreRefs, mor)
}
}

// Copy the mors without the clusters
Expand Down Expand Up @@ -307,6 +311,14 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
return
}

// Retrieve summary property for all datastores
var dss []mo.Datastore
err = pc.Retrieve(ctx, datastoreRefs, []string{"summary"}, &dss)
if err != nil {
log.Fatal(err)
return
}

// Initialize the map that will hold the VM MOR to ResourcePool reference
vmToPool := make(map[types.ManagedObjectReference]string)

Expand Down Expand Up @@ -640,6 +652,20 @@ func (vcenter *VCenter) Query(config Configuration, InfluxDBClient influxclient.
bp.AddPoint(pt3)
}

for _, datastore := range dss {
datastoreFields := map[string]interface{}{
"capacity": datastore.Summary.Capacity,
"free_space": datastore.Summary.FreeSpace,
}
datastoreTags := map[string]string{"ds_name": datastore.Summary.Name}
pt4, err := influxclient.NewPoint("datastore", datastoreTags, datastoreFields, time.Now())
if err != nil {
errlog.Println(err)
continue
}
bp.AddPoint(pt4)
}

}

//InfluxDB send
Expand Down
11 changes: 9 additions & 2 deletions vsphere-influxdb.json.sample
Expand Up @@ -64,6 +64,13 @@
{ "Metric": "disk.numberWriteAveraged.average", "Instances": "*" },
{ "Metric": "net.throughput.contention.summation", "Instances": "*" }
]
}
},
{
"ObjectType": [ "Datastore" ],
"Definition": [
{ "Metric": "disk.capacity.latest", "Instances": "*" },
{ "Metric": "disk.used.latest", "Instances": "*" }
]
}
]
}
}

0 comments on commit ce1d720

Please sign in to comment.