@@ -2,6 +2,7 @@ package chunk
2
2
3
3
import (
4
4
"net/url"
5
+ "strings"
5
6
"sync"
6
7
"time"
7
8
@@ -18,8 +19,11 @@ const (
18
19
19
20
type dynamoWatcher struct {
20
21
accountMaxCapacity * prometheus.GaugeVec
22
+ tableCapacity * prometheus.GaugeVec
23
+
24
+ dynamoDB * dynamodb.DynamoDB
25
+ tableName string
21
26
22
- dynamoDB * dynamodb.DynamoDB
23
27
updateInterval time.Duration
24
28
quit chan struct {}
25
29
wait sync.WaitGroup
@@ -43,15 +47,20 @@ func WatchDynamo(dynamoDBURL string, interval time.Duration) (Watcher, error) {
43
47
}
44
48
client := dynamodb .New (session .New (dynamoDBConfig ))
45
49
46
- // TODO: Report on table capacity.
47
- // tableName := strings.TrimPrefix(dynamoURL.Path, "/")
50
+ tableName := strings .TrimPrefix (url .Path , "/" )
48
51
w := & dynamoWatcher {
49
52
accountMaxCapacity : prometheus .NewGaugeVec (prometheus.GaugeOpts {
50
53
Namespace : "cortex" ,
51
54
Name : "dynamo_account_max_capacity_units" ,
52
55
Help : "Account-wide DynamoDB capacity, measured in DynamoDB capacity units." ,
53
56
}, []string {"op" }),
57
+ tableCapacity : prometheus .NewGaugeVec (prometheus.GaugeOpts {
58
+ Namespace : "cortex" ,
59
+ Name : "dynamo_table_capacity_units" ,
60
+ Help : "Per-table DynamoDB capacity, measured in DynamoDB capacity units." ,
61
+ }, []string {"op" , "table" }),
54
62
dynamoDB : client ,
63
+ tableName : tableName ,
55
64
updateInterval : interval ,
56
65
quit : make (chan struct {}),
57
66
}
@@ -92,12 +101,25 @@ func (w *dynamoWatcher) updateAccountLimits() error {
92
101
return nil
93
102
}
94
103
104
+ func (w * dynamoWatcher ) updateTableLimits () error {
105
+ output , err := w .dynamoDB .DescribeTable (& dynamodb.DescribeTableInput {})
106
+ if err != nil {
107
+ return err
108
+ }
109
+ throughput := output .Table .ProvisionedThroughput
110
+ w .tableCapacity .WithLabelValues (readLabel , w .tableName ).Set (float64 (* throughput .ReadCapacityUnits ))
111
+ w .tableCapacity .WithLabelValues (writeLabel , w .tableName ).Set (float64 (* throughput .WriteCapacityUnits ))
112
+ return nil
113
+ }
114
+
95
115
// Describe implements prometheus.Collector.
96
116
func (w * dynamoWatcher ) Describe (ch chan <- * prometheus.Desc ) {
97
117
w .accountMaxCapacity .Describe (ch )
118
+ w .tableCapacity .Describe (ch )
98
119
}
99
120
100
121
// Collect implements prometheus.Collector.
101
122
func (w * dynamoWatcher ) Collect (ch chan <- prometheus.Metric ) {
102
123
w .accountMaxCapacity .Collect (ch )
124
+ w .tableCapacity .Collect (ch )
103
125
}
0 commit comments