How do I create a custom metric for my Elastic Beanstalk environment in C#?
I have a numerical metric seconds.
I use the following code:
double seconds = ts.Seconds + (Convert.ToDouble(ts.Milliseconds / 10) / 100);
using (AmazonCloudWatchClient cloudwatch = new AmazonCloudWatchClient(accessKey, secretKey))
{
PutMetricDataRequest mdr = new PutMetricDataRequest();
mdr.Namespace = "Performance";
MetricDatum dataPoint = new MetricDatum();
dataPoint.MetricName = "UploadSpeedInSeconds";
dataPoint.Unit = "Seconds";
dataPoint.Value = seconds;
}
I have no idea were to continue on. I want the custom metric to mesuare the uploads in seconds of files. I already have the metric value, and I want to update a custom metric so I can keep track of it (BTW: can I view the custom metric in the console?).
Don't forget to actually send it off to AWS:
mdr.MetricData = new List<MetricDatum>();
mdr.MetricData.Add(dataPoint);
PutMetricDataResponse resp = cloudwatch.PutMetricData(mdr);
Debug.Assert(resp.HttpStatusCode == System.Net.HttpStatusCode.OK);
Related
I am using c# with mvc.
I used this code to generate token and generated successfully. but after generate token when join channel using .join() it return DYNAMIC_KEY_EXPIRED.
I Used "AgoraRTCSDK-3.1.0.js"
I used https://github.com/AgoraIO/Tools/blob/master/DynamicKey/AgoraDynamicKey/csharp to generate dynamic token
If any one has experience on Agora.io, please help me.
Sample code is..
AccessToken token = new AccessToken(apiKey, appCertificate, channelName, "0");
token.addPrivilege(Privileges.kJoinChannel, _expiredTs);
token.addPrivilege(Privileges.kPublishAudioStream, _expiredTs);
token.addPrivilege(Privileges.kPublishVideoStream, _expiredTs);
string strToken = token.build();
public string build()
{
this._messageRawContent = Utils.pack(this.message);
this._signature = generateSignature(_appCertificate
, _appId
, _channelName
, _uid
, _messageRawContent);
this._crcChannelName = Crc32CAlgorithm.Compute(this._channelName.GetByteArray());
this._crcUid = Crc32CAlgorithm.Compute(this._uid.GetByteArray());
PackContent packContent = new PackContent(_signature, _crcChannelName, _crcUid, this._messageRawContent);
byte[] content = Utils.pack(packContent);
return getVersion() + this._appId + Utils.base64Encode(content);
}
Whenever you generate a token for Agora applications, you need to keep in mind that the expiration time is calculated as a timestamp (time since 1970) so you need to ensure the the expiration time is set to the currentTime + expirationTimeInSeconds.
In the above example you are passing the expiration time as 0 which generates a token that is already considered expired.
consider using:
// set a expiration time of 1 hour in seconds
let expireTime = 3600;
// calculate current time in seconds
const currentTime = Math.floor(Date.now() / 1000);
// calculate privilege expire time
const privilegeExpireTime = currentTime + expireTime;
I am trying to upgrade my code for multi-label classification from version 3.0.2. to 3.3.0. I did the upgrade, but it seems that classification results were much worse now - algorithm is not able to classify many more instances than before. Can you please tell me if there is any issue in my new code. How to use estimated parameters for gauss kernel as I did before?
Old code:
var gauss = Gaussian.Estimate(inputs, Convert.ToInt32(inputs.GetLength(0) * 0.8));
// Create the machine.
this.machine = new MultilabelSupportVectorMachine(inputs[0].Length, gauss, outputs[0].Length);
// Train the model.
var teacher = new MultilabelSupportVectorLearning(this.machine, inputs, outputs);
teacher.Algorithm = (svm, classInputs, classOutputs, i, j) => new SequentialMinimalOptimization(svm, classInputs, classOutputs) { UseComplexityHeuristic = true, CacheSize = 1000 };
teacher.SubproblemFinished += SubproblemFinished;
var error = teacher.Run(true);
// Save the model.
this.machine.Save(modelPath);
New code:
var gauss = Gaussian.Estimate(inputs, Convert.ToInt32(inputs.GetLength(0) * 0.8));
// Create the machine.
this.machine = new MultilabelSupportVectorMachine<Gaussian>(inputs[0].Length, gauss, outputs[0].Length);
// Create the multi-class learning algorithm for the machine
var teacher = new MultilabelSupportVectorLearning<Gaussian>(this.machine)
{
// Configure the learning algorithm to use SMO to train the
// underlying SVMs in each of the binary class subproblems.
Learner = (param) => new SequentialMinimalOptimization<Gaussian>()
{
// Estimate a suitable guess for the Gaussian kernel's parameters.
// This estimate can serve as a starting point for a grid search.
UseKernelEstimation = true,
UseComplexityHeuristic = true,
CacheSize = 1000
}
};
teacher.ParallelOptions.MaxDegreeOfParallelism = 1;
// Learn a machine
machine = teacher.Learn(inputs, outputs);
Serializer.Save(machine, modelPath);
Thanks in advance!
Using the ExchangeRateServiceClient every time I try to use client.create for currency a currency code pair I get an exception
Cannot create a record in Exchange rate currency pair (ExchangeRateCurrencyPair). From currency: USD, EUR. The record already exists.
System.Exception {System.ServiceModel.FaultException}
I am brand new to the AX API...I am using C#
AXDev09.ExchangeRateServiceCreateRequest request =
new AXDev09.ExchangeRateServiceCreateRequest();
AXDev09.ExchangeRateServiceClient client = new AXDev09.ExchangeRateServiceClient();
request.CallContext = new AXDev09.CallContext();
request.CallContext.Language = "en-us";
request.CallContext.Company = "T51";
request.CallContext.MessageId = Guid.NewGuid().ToString();
AXDev09.AxdEntity_CurrencyPair[] myPair = new AXDev09.AxdEntity_CurrencyPair[1];
myPair[0] = new AXDev09.AxdEntity_CurrencyPair();
myPair[0].ToCurrencyCode = "EUR";
myPair[0].FromCurrencyCode = "USD";
AXDev09.AxdEntity_ExchangeRate[] myExchange = new AXDev09.AxdEntity_ExchangeRate[1];
myExchange[0] = new AXDev09.AxdEntity_ExchangeRate();
myExchange[0].ExchangeRate = Convert.ToDecimal("0.708");
myExchange[0].ExchangeRateSpecified = true;
myPair[0].ExchangeRate = myExchange;
myPair[0].ExchangeRateDisplayFactor = AXDev09.AxdEnum_ExchangeRateDisplayFactor.One;
myPair[0].ExchangeRateType = "Average";
AxdType_DateTime myFromDate = new AxdType_DateTime();
myFromDate.localDateTime = DateTime.Now.ToUniversalTime();
myFromDate.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;
myFromDate.Value = myFromDate.localDateTime;
AxdType_DateTime myToDate = new AxdType_DateTime();
myToDate.localDateTime = DateTime.Now.ToUniversalTime();
myToDate.timezone = AxdEnum_Timezone.GMTMINUS0600CENTRALTIME;
myToDate.Value = myToDate.localDateTime;
request.LedgerExchangeRate = new AXDev09.AxdLedgerExchangeRate();
request.LedgerExchangeRate.CurrencyPair = myPair;
request.LedgerExchangeRate.ValidFromDateTime = myFromDate;
request.LedgerExchangeRate.ValidToDateTime = myToDate;
client.Open();
client.create(request.CallContext, request.LedgerExchangeRate);
client.Close();
The ExchangeRateServiceClient does appear to be a standard API.
The standards web service is called LedgerExchangeRateService.
If you provide two currencies, then try to reverse them.
if the error message is to be believed, seems like the issue is when it tries to create the ExchangeRateCurrencyPair
there is a no-duplicates index on:
fromCurrency
toCurrency
ExchangeRateType
"I am trying to add a new currency rate...with a new set from from-to but I keep getting "The record already exists" error eventhough I'm setting new FROM-TO dates."
it seems to be objecting to ExchangeRateCurrencyPair(not to the date effective bits) maybe try selecting the pair instead of attempting to create it every time--or maybe try debugging through a successful new pair to see if a tweak may be needed in the standard service
I want to manage the booking policy of a room, maximum duration of a meeting for example. Do someone has idea how do you do that via Managed API?
The managed API cannot police max duration but what you need todo is validate the entry before you submit a reservation...
public override bool IsNoOverTimeLimit(Reservation reservation)
{
return reservation.End.Subtract(reservation.Start).TotalMinutes <= 120;
}
if(!IsNoOverTimeLimit)
{
var errorMsg = new Label();
var fontSize = FontUnit.Point(10);
errorMsg.Font.Size = fontSize;
errorMsg.Text = "Reservation time is limited to " + ((float)30 / 60).ToString(CultureInfo.InvariantCulture) + " hours at a time.<br /> ";
placeHolder.Controls.Add(errorMsg);
}
My version is way more complicated than this but you get the point. Just simply check the reservation before you submit and if over time limit, return to page with some pretty warning..
how to get available ram and cpu usage via AWS API?
You will need AmazonCloudWatch API for gathering this statistics. Unfortunately, it does not provide ram usage information. One of solutions could be creating your own "RAMUsage" metric and implementing ram usage monitoring service, which will run on all EC2 instances and add this information to CloudWatch.
Here is a sample of receiving "CPUUtilization" metric for last 5 minutes using AWS API.
var client = AWSClientFactory.CreateAmazonCloudWatchClient(
<AWSAccessKey>,
<AWSSecretKey>);
var dimension = new Dimension
{
Name = "InstanceId",
Value = <InstanceId>,
};
var request = new GetMetricStatisticsRequest();
request.Dimensions.Add(dimension);
var currentTime = DateTime.UtcNow;
var startTime = currentTime.AddMinutes(-5);
request.StartTime = startTime.ToString(
AWSSDKUtils.ISO8601DateFormat,
CultureInfo.InvariantCulture.DateTimeFormat);
request.EndTime = currentTime.ToString(
AWSSDKUtils.ISO8601DateFormat,
CultureInfo.InvariantCulture.DateTimeFormat);
request.Namespace = "AWS/EC2";
request.Statistics.Add("Maximum");
request.Statistics.Add("Average");
request.MeasureName = "CPUUtilization";
request.Period = 300;
var response = client.GetMetricStatistics(request);
if (response.IsSetGetMetricStatisticsResult() &&
response.GetMetricStatisticsResult.Datapoints.Count > 0)
{
var dataPoint = response.GetMetricStatisticsResult.Datapoints[0];
Console.WriteLine(
"Instance: {0} CPU Average load: {1} CPU Max load: {2}",
instanceID,
dataPoint.Average,
dataPoint.Maximum);
}