Azure Data Explorer Metrics - azure-java-sdk

how can i get the "CacheUtilization" metric from "Azure Data Explorer" using java. Are there any JAVA SDKs that help fetch the metrics from "Azure Data Explorer" service?

Regarding the issue, please refer to the following code
Maven
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-resources</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.azure.resourcemanager</groupId>
<artifactId>azure-resourcemanager-monitor</artifactId>
<version>2.2.0</version>
</dependency>
code
String clientId="";
String clientSecret="";
String tenant="";
String subId="";
AzureProfile profile = new AzureProfile(tenant,subId,AzureEnvironment.AZURE);
TokenCredential credential = new ClientSecretCredentialBuilder()
.authorityHost(profile.getEnvironment().getActiveDirectoryEndpoint())
.tenantId(tenant)
.clientId(clientId)
.clientSecret(clientSecret)
.build();
MonitorManager manager = MonitorManager
.configure()
.withLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)
.authenticate(credential,profile);
OffsetDateTime recordDateTime = OffsetDateTime.now();
for (MetricDefinition metricDefinition : manager.metricDefinitions().listByResource("<the resource id of data exploer>")
) {
if(metricDefinition.name().localizedValue().equalsIgnoreCase("Cache utilization")){
MetricCollection metricCollection = metricDefinition.defineQuery()
.startingFrom(recordDateTime.minusDays(7))
.endsBefore(recordDateTime)
.withAggregation("Average")
.withInterval(Duration.ofMinutes(5))
.filterByNamespace("microsoft.kusto/clusters")
.execute();
System.out.println("Metrics for '" + "" + "':");
System.out.println("Namespacse: " + metricCollection.namespace());
System.out.println("Query time: " + metricCollection.timespan());
System.out.println("Time Grain: " + metricCollection.interval());
System.out.println("Cost: " + metricCollection.cost());
for (Metric metric : metricCollection.metrics()) {
System.out.println("\tMetric: " + metric.name().localizedValue());
System.out.println("\tType: " + metric.type());
System.out.println("\tUnit: " + metric.unit());
System.out.println("\tTime Series: ");
for (TimeSeriesElement timeElement : metric.timeseries()) {
System.out.println("\t\tMetadata: ");
for (MetadataValueInner metadata : timeElement.metadatavalues()) {
System.out.println("\t\t\t" + metadata.name().localizedValue() + ": " + metadata.value());
}
System.out.println("\t\tData: ");
for (MetricValue data : timeElement.data()) {
System.out.println("\t\t\t" + data.timestamp()
+ " : (Min) " + data.minimum()
+ " : (Max) " + data.maximum()
+ " : (Avg) " + data.average()
+ " : (Total) " + data.total()
+ " : (Count) " + data.count());
}
}
}
break;
}
}

Related

Selecting sql data with multiple rows and exporting as xml file

I have this JavaScript in my transformer
var dbConn;
try {
dbConn = DatabaseConnectionFactory.createDatabaseConnection($gc('DataWarehouseXMLDataConfig').sqlDriver,
$gc('DataWarehouseXMLDataConfig').sqlConnString,
$gc('DataWarehouseXMLDataConfig').sqlUsername,
$gc('DataWarehouseXMLDataConfig').sqlPassword);
var data = dbConn.executeCachedQuery('EXEC [dbo].[GetDataWarehouseData]');
var xml = "";
var xml2 = "";
var row = "";
while(data.next()) {
row = '<referral>' + '\n' +
'<careid>' + data.getString('careid') + '</careid>' + '\n' +
'<patientid>' + data.getString('patientid') + '</patientid>' + '\n' +
'<dateofreceipt>' + data.getString('dateofreceipt') + '</dateofreceipt>' + '\n' +
'<datefirstseen>' + data.getString('datefirstseen') + '</datefirstseen>' + '\n' +
'<nhsnumber>' + data.getString('nhsnumber') + '</nhsnumber>' + '\n' +
'<hospitalnumber>' + data.getString('hospitalnumber') + '</hospitalnumber>' + '\n' +
'<surname>' + data.getString('surname') + '</surname>' + '\n' +
'<forename>' + data.getString('forename') + '</forename>' + '\n' +
'<dateofbirth>' + data.getString('dateofbirth') + '</dateofbirth>' + '\n' +
'</referral>';
xml = xml + row;
xml2 = '<?xml version="1.0" encoding="utf-8"?>' + '\n' + '<results>' + xml + '</results>';
}
channelMap.put('xml2', xml2);
} finally {
if (dbConn) {
dbConn.close();
}
}
I'm using this outbound message template
<referral>
<careid></careid>
<patientid></patientid>
<dateofreceipt></dateofreceipt>
<datefirstseen></datefirstseen>
<nhsnumber></nhsnumber>
<hospitalnumber></hospitalnumber>
<surname></surname>
<forename></forename>
<dateofbirth></dateofbirth>
</referral>
I have a File Writer destination and the File Name has a .xml extension.
My template in the File Writer is ${XmlUtil.prettyPrint(${message.encodedData})}.
The SQL data is being retrieved ok.
I don't think I'm a million miles away but I'm doing something fundamentally wrong.
What do I need to do to send the required xml file please?
I fixed this by adding a mapping step to the source transformer and using JavaScript, like
tmp['referral']['dateofbirth'] = msg['dateofbirth'].toString();

twilio API issues when submitting whastapp query

I'm using HttpURLConnection to post to https://api.twilio.com/2010-04-01/Accounts/****/Messages.json
this works for SMS - but when the txtTo and txtFrom are changed to To=whatsapp:+12345567&From=whatsapp:+123456778&Body=sacsacsac
it stops working ..... any ideas?
String message = "To=" + txtTo + "&From=" + txtFrom + "&Body=" + txtBody;
byte[] postData = message.getBytes( StandardCharsets.UTF_8 );
String message = "From=" + URLEncoder.encode("whatsapp:" + txtFrom, "UTF-8") +"&Body=" + URLEncoder.encode(txtBody, "UTF-8") + "&To=" + URLEncoder.encode("whatsapp:" + txtTo, "UTF-8");

Getting Object tag value in AWS S3

I am using scala to get information about my objects that are in S3 I am intersted in getting each object I have inside S3 Bucket his tag value so far I have accomplished this code to get me information about my objects but did not succeeded in getting its tagging value: I used this code in scala:
def retrieveObjectTags(keyName: String): Unit ={
try {
println("Listing objects")
val req: ListObjectsV2Request =
new ListObjectsV2Request().withBucketName(bucketName).withMaxKeys(2)
var result: ListObjectsV2Result = null
do {
result = client.listObjectsV2(req)
for (objectSummary <- result.getObjectSummaries) {
println(
" - " + objectSummary.getKey + " " + "(size = " + objectSummary.getSize +
")")
println(objectSummary.getETag)
}
println("Next Continuation Token : " + result.getNextContinuationToken)
req.setContinuationToken(result.getNextContinuationToken)
} while (result.isTruncated == true);
}catch {
case ase: AmazonServiceException => {
println(
"Caught an AmazonServiceException, " + "which means your request made it " +
"to Amazon S3, but was rejected with an error response " +
"for some reason.")
println("Error Message: " + ase.getMessage)
println("HTTP Status Code: " + ase.getStatusCode)
println("AWS Error Code: " + ase.getErrorCode)
println("Error Type: " + ase.getErrorType)
println("Request ID: " + ase.getRequestId)
}
case ace: AmazonClientException => {
println(
"Caught an AmazonClientException, " + "which means the client encountered " +
"an internal error while trying to communicate" +
" with S3, " +
"such as not being able to access the network.")
println("Error Message: " + ace.getMessage)
}
}
// val getTaggingRequest = new GetObjectTaggingRequest(bucketName,keyName)
// var getTagResult = client.getObjectTagging(getTaggingRequest)
//println(getTaggingRequest)
var tag: Tag = new Tag()
println("tag name:" + tag.getValue)
}
as for the remarked lines I have encounter a problem with it, what other way I can use to solve this problem?

How do you list out all output / generate files from a Gradle Build?

Currently I am using the following to generate list of output files which I want for another plugin which does Github releases.
[
"${buildDir}/libs/${project.name}-${project.version}.jar",
"${buildDir}/libs/${project.name}-${project.version}-javadoc.jar",
"${buildDir}/libs/${project.name}-${project.version}-sources.jar"
]
I am not very satisfied with this as I am manually specifying each type of file (doc, source, class). I am looking to make this more generic where I can reuse without any modification for any project which might have more or less outputs and also may not be in the default location and some outputs may not even be Java outputs. I.e. changing output location, the tasks to run or plugging elsewhere in the script should not break this part of the script and should be reusable without editing. The question is how do you get a list of all the outputs as a List of String like above.
More detailed code snippet:
...
plugins {
id 'co.riiid.gradle' version '0.4.2'
}
...
ext {
org = 'MicroTrader'
repo = org + '/' + project.name
releaseNotesFile = 'RELEASE_NOTES.md'
host = 'github.com'
hostUrl = 'https://' + host + '/'
orgUrl = hostUrl + org
websiteUrl = hostUrl + repo
vcsUrl = websiteUrl + '.git'
scmUrl = 'scm:git#' + host + ':' + repo + '.git'
issueTrackerUrl = websiteUrl + '/issues'
ossrhUsername = ((project.hasProperty('ossrhUsername') ? ossrhUsername : System.getenv('OSSRH_USER')) ?: System.getProperty('ossrh.user')) ?: ' '
ossrhPassword = ((project.hasProperty('ossrhPassword') ? ossrhPassword : System.getenv('OSSRH_PASSWORD')) ?: System.getProperty('ossrh.password')) ?: ' '
bintray_user = ((project.hasProperty('bintray_user') ? bintray_user : System.getenv('BINTRAY_USER')) ?: System.getProperty('bintray.user')) ?: ' '
bintray_api_key = ((project.hasProperty('bintray_api_key') ? bintray_api_key : System.getenv('BINTRAY_KEY')) ?: System.getProperty('bintray.apikey')) ?: ' '
artifactory_user = ((project.hasProperty('artifactory_user') ? artifactory_user : System.getenv('ARTIFACTORY_USER')) ?: System.getProperty('artifactory.user')) ?: ' '
artifactory_password = ((project.hasProperty('artifactory_password') ? artifactory_password : System.getenv('ARTIFACTORY_PASSWORD')) ?: System.getProperty('artifactory.password')) ?: ' '
github_api_key = ((project.hasProperty('github_api_key') ? github_api_key : System.getenv('GITHUB_KEY')) ?: System.getProperty('github.apikey')) ?: ' '
}
...
github {
owner = project.org
repo = project.name
token = project.github_api_key
tagName = project.version
targetCommitish = 'master'
name = 'v' + project.version
body = Files.exists(Paths.get('' + projectDir + '/' + releaseNotesFile)) ?
new File('' + projectDir + '/' + releaseNotesFile).text :
(Files.exists(Paths.get('' + baseDir + '/' + releaseNotesFile)) ?
new File('' + baseDir + '/' + releaseNotesFile).text : '')
assets = [
"${buildDir}/libs/${project.name}-${project.version}.jar",
"${buildDir}/libs/${project.name}-${project.version}-javadoc.jar",
"${buildDir}/libs/${project.name}-${project.version}-sources.jar"
]
}
...
Try reading the outputs property on all of the tasks in your build used to generate the artifacts:
project(':my-sub-project').jar.outputs
Another option is to use the archives configuration from all of your sub-projects:
project(':my-sub-project').configurations.archives.allArtifacts

Error C#.NET 3.0: The best overloaded method match for 'CreatePageSection(ref string, ref string, ref object)' has some invalid arguments

I have got the following problem. I encountered an error regarding the default parameters. I added a simple piece of code for an overload. Now I get in the new code (line 3: CreatePageSection(sItemID, "", null);) gives the error mentioned in the title.
I looked for the answer in the other topics, but I can't find the problem. Can someone help me?
The code is found here:
public void CreatePageSection(ref string sItemID)
{
CreatePageSection(sItemID, "", null);
}
public void CreatePageSection(ref string sItemID, ref string sFrameUrl, ref object vOnReadyState)
{
if (Strings.InStr(msPresentPageSections, "|" + sItemID + "|", 0) > 0) {
return;
}
msPresentPageSections = msPresentPageSections + sItemID + "|";
string writeHtml = "<div class=" + MConstants.QUOTE + "PageSection" + MConstants.QUOTE + " id=" + MConstants.QUOTE + "Section" + sItemID + "Div" + MConstants.QUOTE + " style=" + MConstants.QUOTE + "display: none;" + MConstants.QUOTE + ">";
this.WriteLine_Renamed(ref writeHtml);
//UPGRADE_WARNING: Couldn't resolve default property of object vOnReadyState. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
//UPGRADE_NOTE: IsMissing() was changed to IsNothing_Renamed(). Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="8AE1CB93-37AB-439A-A4FF-BE3B6760BB23"'
writeHtml = " <iframe id=" + MConstants.QUOTE + sItemID + "Frame" + MConstants.QUOTE + " name=" + MConstants.QUOTE + sItemID + "Frame" + MConstants.QUOTE + " frameborder=" + MConstants.QUOTE + "0" + MConstants.QUOTE + (!string.IsNullOrEmpty(sFrameUrl) ? " src=" + MConstants.QUOTE + sFrameUrl + MConstants.QUOTE : "") + ((vOnReadyState == null) ? "" : " onreadystatechange=" + MConstants.QUOTE + Convert.ToString(vOnReadyState) + MConstants.QUOTE) + ">";
this.WriteLine_Renamed(ref writeHtml);
writeHtml = " </iframe>";
this.WriteLine_Renamed(ref writeHtml);
writeHtml = "</div>";
this.WriteLine_Renamed(ref writeHtml);
}
you must pass params by reference
public void CreatePageSection(ref string sItemID)
{
var missingString = String.Empty;
object missingObject = null;
CreatePageSection(ref sItemID, ref missingString, ref missingObject);
}
Since your are not manipulating sFrameUrl and vOnReadyState, remove the ref keyword from those parameters.
See: http://msdn.microsoft.com/en-us/library/14akc2c7(v=vs.71).aspx
hth
Mario