@@ -59,7 +59,7 @@ Build succeeded.
59
59
If you are using an IDE other than Visual Studio you can install the Metrics Advisor client library for .NET with the following command:
60
60
61
61
``` console
62
- dotnet add package Azure.AI.MetricsAdvisor --version 1.0 .0
62
+ dotnet add package Azure.AI.MetricsAdvisor --version 1.1 .0
63
63
```
64
64
65
65
> [ !TIP]
@@ -151,64 +151,45 @@ Replace `connection_String` with your own SQL server connection string, and repl
151
151
string sqlServerConnectionString = " <connection_String>" ;
152
152
string sqlServerQuery = " <query>" ;
153
153
154
- var dataFeedName = " Sample data feed" ;
155
- var dataFeedSource = new SqlServerDataFeedSource (sqlServerConnectionString , sqlServerQuery );
156
- var dataFeedGranularity = new DataFeedGranularity (DataFeedGranularityType .Daily );
154
+ var dataFeed = new DataFeed ();
155
+ dataFeed .Name = " Sample data feed" ;
157
156
158
- var dataFeedMetrics = new List <DataFeedMetric >()
159
- {
160
- new DataFeedMetric (" cost" ),
161
- new DataFeedMetric (" revenue" )
162
- };
163
- var dataFeedDimensions = new List <DataFeedDimension >()
164
- {
165
- new DataFeedDimension (" category" ),
166
- new DataFeedDimension (" city" )
167
- };
168
- var dataFeedSchema = new DataFeedSchema (dataFeedMetrics )
169
- {
170
- DimensionColumns = dataFeedDimensions
171
- };
172
-
173
- var ingestionStartTime = DateTimeOffset .Parse (" 2020-01-01T00:00:00Z" );
174
- var dataFeedIngestionSettings = new DataFeedIngestionSettings (ingestionStartTime );
175
-
176
- var dataFeed = new DataFeed ()
177
- {
178
- Name = dataFeedName ,
179
- DataSource = dataFeedSource ,
180
- Granularity = dataFeedGranularity ,
181
- Schema = dataFeedSchema ,
182
- IngestionSettings = dataFeedIngestionSettings ,
183
- };
157
+ dataFeed .DataSource = new SqlServerDataFeedSource (sqlServerConnectionString , sqlServerQuery );
158
+ dataFeed .Granularity = new DataFeedGranularity (DataFeedGranularityType .Daily );
184
159
185
- Response < string > response = await adminClient .CreateDataFeedAsync (dataFeed );
160
+ dataFeed .Schema = new DataFeedSchema ();
161
+ dataFeed .Schema .MetricColumns .Add (new DataFeedMetric (" cost" ));
162
+ dataFeed .Schema .MetricColumns .Add (new DataFeedMetric (" revenue" ));
163
+ dataFeed .Schema .DimensionColumns .Add (new DataFeedDimension (" category" ));
164
+ dataFeed .Schema .DimensionColumns .Add (new DataFeedDimension (" city" ));
186
165
187
- string dataFeedId = response . Value ;
166
+ dataFeed . IngestionSettings = new DataFeedIngestionSettings ( DateTimeOffset . Parse ( " 2020-01-01T00:00:00Z " )) ;
188
167
189
- Console .WriteLine ($" Data feed ID: {dataFeedId }" );
190
168
191
- // Note that only the ID of the data feed is known at this point. You can perform another
192
- // service call to GetDataFeedAsync or GetDataFeed to get more information, such as status,
193
- // created time, the list of administrators, or the metric IDs.
169
+ Response < DataFeed > response = await adminClient .CreateDataFeedAsync (dataFeed );
194
170
195
- Response < DataFeed > response = await adminClient . GetDataFeedAsync ( dataFeedId ) ;
171
+ DataFeed createdDataFeed = response . Value ;
196
172
197
- DataFeed dataFeed = response .Value ;
198
-
199
- Console .WriteLine ($" Data feed status: {dataFeed .Status .Value }" );
200
- Console .WriteLine ($" Data feed created time: {dataFeed .CreatedTime .Value }" );
173
+ Console .WriteLine ($" Data feed ID: {createdDataFeed .Id }" );
174
+ Console .WriteLine ($" Data feed status: {createdDataFeed .Status .Value }" );
175
+ Console .WriteLine ($" Data feed created time: {createdDataFeed .CreatedOn .Value }" );
201
176
202
177
Console .WriteLine ($" Data feed administrators:" );
203
- foreach (string admin in dataFeed . AdministratorEmails )
178
+ foreach (string admin in createdDataFeed . Administrators )
204
179
{
205
180
Console .WriteLine ($" - {admin }" );
206
181
}
207
182
208
183
Console .WriteLine ($" Metric IDs:" );
209
- foreach (DataFeedMetric metric in dataFeed .Schema .MetricColumns )
184
+ foreach (DataFeedMetric metric in createdDataFeed .Schema .MetricColumns )
210
185
{
211
- Console .WriteLine ($" - {metric .MetricName }: {metric .MetricId }" );
186
+ Console .WriteLine ($" - {metric .Name }: {metric .Id }" );
187
+ }
188
+
189
+ Console .WriteLine ($" Dimensions:" );
190
+ foreach (DataFeedDimension dimension in createdDataFeed .Schema .DimensionColumns )
191
+ {
192
+ Console .WriteLine ($" - {dimension .Name }" );
212
193
}
213
194
```
214
195
@@ -254,29 +235,31 @@ Create an anomaly detection configuration to tell the service which data points
254
235
string metricId = " <metricId>" ;
255
236
string configurationName = " Sample anomaly detection configuration" ;
256
237
257
- var hardThresholdSuppressCondition = new SuppressCondition (1 , 100 );
258
- var hardThresholdCondition = new HardThresholdCondition (AnomalyDetectorDirection .Down , hardThresholdSuppressCondition )
238
+ var detectionConfiguration = new AnomalyDetectionConfiguration ()
259
239
{
260
- LowerBound = 5 . 0
240
+ MetricId = metricId ,
241
+ Name = configurationName ,
242
+ WholeSeriesDetectionConditions = new MetricWholeSeriesDetectionCondition ()
261
243
};
262
244
263
- var smartDetectionSuppressCondition = new SuppressCondition (4 , 50 );
264
- var smartDetectionCondition = new SmartDetectionCondition (10 . 0 , AnomalyDetectorDirection .Up , smartDetectionSuppressCondition );
245
+ var detectCondition = detectionConfiguration .WholeSeriesDetectionConditions ;
265
246
266
- var detectionCondition = new MetricWholeSeriesDetectionCondition ()
247
+ var hardSuppress = new SuppressCondition (1 , 100 );
248
+ detectCondition .HardThresholdCondition = new HardThresholdCondition (AnomalyDetectorDirection .Down , hardSuppress )
267
249
{
268
- HardThresholdCondition = hardThresholdCondition ,
269
- SmartDetectionCondition = smartDetectionCondition ,
270
- CrossConditionsOperator = DetectionConditionsOperator .Or
250
+ LowerBound = 5 . 0
271
251
};
272
252
273
- var detectionConfiguration = new AnomalyDetectionConfiguration (metricId , configurationName , detectionCondition );
253
+ var smartSuppress = new SuppressCondition (4 , 50 );
254
+ detectCondition .SmartDetectionCondition = new SmartDetectionCondition (10 . 0 , AnomalyDetectorDirection .Up , smartSuppress );
255
+
256
+ detectCondition .ConditionOperator = DetectionConditionOperator .Or ;
274
257
275
- Response < string > response = await adminClient .CreateDetectionConfigurationAsync (detectionConfiguration );
258
+ Response < AnomalyDetectionConfiguration > response = await adminClient .CreateDetectionConfigurationAsync (detectionConfiguration );
276
259
277
- string detectionConfigurationId = response .Value ;
260
+ AnomalyDetectionConfiguration createdDetectionConfiguration = response .Value ;
278
261
279
- Console .WriteLine ($" Anomaly detection configuration ID: {detectionConfigurationId }" );
262
+ Console .WriteLine ($" Anomaly detection configuration ID: {createdDetectionConfiguration . Id }" );
280
263
```
281
264
282
265
### Create a hook
@@ -285,19 +268,16 @@ Metrics Advisor supports the `EmailNotificationHook` and `WebNotificationHook` c
285
268
286
269
``` csharp
287
270
string hookName = " Sample hook" ;
288
- var emailsToAlert = new List <string >()
289
- {
290
-
291
-
292
- };
271
+ var emailHook = new EmailNotificationHook (hookName );
293
272
294
- var emailHook = new EmailNotificationHook (hookName , emailsToAlert );
273
+ emailHook .
EmailsToAlert .
Add (
" [email protected] " );
274
+ emailHook .
EmailsToAlert .
Add (
" [email protected] " );
295
275
296
- Response < string > response = await adminClient .CreateHookAsync (emailHook );
276
+ Response < NotificationHook > response = await adminClient .CreateHookAsync (emailHook );
297
277
298
- string hookId = response .Value ;
278
+ NotificationHook createdHook = response .Value ;
299
279
300
- Console .WriteLine ($" Hook ID: {hookId }" );
280
+ Console .WriteLine ($" Hook ID: {createdHook . Id }" );
301
281
```
302
282
303
283
## Create an alert configuration
0 commit comments