Skip to content

Commit 436cf2a

Browse files
committed
add cost query last update timestamp
fixes #152 Signed-off-by: Markus Blaschke <[email protected]>
1 parent 643788c commit 436cf2a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ This exporter needs `Reader` permissions on subscription level.
7777
| `azurerm_costs_budget_limit` | Costs | Limit of CostManagemnet budget |
7878
| `azurerm_costs_budget_usage` | Costs | Percentage of usage of CostManagemnet budget |
7979
| `azurerm_costs_{queryName}` | Costs | Costs query result (see `example.yaml`) |
80+
| `azurerm_costs_metric_timestamp_seconds` | Costs | Timestamp of last update per cost query |
8081
| `azurerm_subscription_info` | General | Azure Subscription details (ID, name, ...) |
8182
| `azurerm_resource_health` | Health | Azure Resource health information |
8283
| `azurerm_iam_roleassignment_info` | IAM | Azure IAM RoleAssignment information |
@@ -103,7 +104,7 @@ This exporter needs `Reader` permissions on subscription level.
103104
| `azurerm_publicip_info` | Portscan | Azure PublicIP information |
104105
| `azurerm_publicip_portscan_status` | Portscan | Status of scanned ports (finished scan, elapsed time, updated timestamp) |
105106
| `azurerm_publicip_portscan_port` | Portscan | List of opened ports per IP |
106-
| `azurerm_advisor_recommendation` | Advisor | Azure Advisor recommendation |
107+
| `azurerm_advisor_recommendation` | Advisor | Azure Advisor recommendation |
107108

108109
### ResourceTags handling
109110

metrics_azurerm_costs.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const (
3030
type (
3131
MetricsCollectorAzureRmCosts struct {
3232
collector.Processor
33+
34+
prometheus struct {
35+
lastUpdate *prometheus.GaugeVec
36+
}
3337
}
3438

3539
MetricsCollectorAzureRmCostsQuery struct {
@@ -56,6 +60,19 @@ type (
5660
func (m *MetricsCollectorAzureRmCosts) Setup(collector *collector.Collector) {
5761
m.Processor.Setup(collector)
5862

63+
// ----------------------------------------------------
64+
// Last update
65+
m.prometheus.lastUpdate = prometheus.NewGaugeVec(
66+
prometheus.GaugeOpts{
67+
Name: "azurerm_costs_metric_timestamp_seconds",
68+
Help: "Azure ResourceManager cost query last update timestamp budget info",
69+
},
70+
[]string{
71+
"metric",
72+
},
73+
)
74+
m.Collector.RegisterMetricList("lastUpdate", m.prometheus.lastUpdate, true)
75+
5976
// ----------------------------------------------------
6077
// Costs (by Query)
6178

@@ -159,13 +176,14 @@ func (m *MetricsCollectorAzureRmCosts) collectRunCostQuery(query *config.Collect
159176
timeframe,
160177
subscription,
161178
)
162-
163179
})
164180
if err != nil {
165181
panic(err)
166182
}
167183
}
168184
}
185+
186+
m.Collector.GetMetricList("lastUpdate").AddTime(prometheus.Labels{"metric": query.GetMetricName()}, time.Now())
169187
}
170188

171189
func (m *MetricsCollectorAzureRmCosts) collectCostManagementMetrics(logger *slog.Logger, metricList *collector.MetricList, scope string, exportType armcostmanagement.ExportType, query *config.CollectorCostsQuery, timeframe string, subscription *armsubscriptions.Subscription) {

0 commit comments

Comments
 (0)