Dynamic Languages (Node.JS, Python, PHP, C/C++, Webserver Agent)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create custom metrics in AppDynamics by C# program

Highlighted

How to create custom metrics in AppDynamics by C# program

Hi

 

I have installed the AppDynamics Extension Service for DotNet Agent which have the possibility to kick off custom scripts through its WIndowsScriptMonitor.

 

I was just wondering if it is possible to write the scripts in C#?

 

I tried yesterday, and it seemed to work, but trying again today, nothing works.

I am making trying something like this:

 

// This variant with hardcoded values seemed to work yesterday (but not today)

Console.WriteLine("metricA | metricReporter , value = 12345");

 

// Other approaches with different types of Integers, Float, Double hardcoded or through variables wont work
Console.WriteLine("metricB | metricReporter , value = " + 2);

Console.WriteLine("metricB | metricReporter , value = " + intVariable);

 

Controller doesnt seem to report anything other than zero values.

Anyone tried something similar who are able to help out?

 

How to create custom metrics in AppDynamics by C# program
2 REPLIES 2
Employee

Re: How to create custom metrics in AppDynamics by C# program

Hi Ronny, 

Thanks for trying .NET extension service. 

I am assuming you have created a standalone application in C# and calling that standalone appliication using cmd file. Basically you will still call scripit.cmd file, and in .cmd file you can call your exe. 

Let me know if this is not correct. 

 

This approach should work normally. You should be able to look into extension log file for any warning like, incorrect format received and it will try to print the line from cmd output. 

 

There could be couple of issues- 

- AppDynamics.Agent.Coordinator is not restarted after rerstarting AppDynamics.Agent.Extension service. 

- Format of line outtput is not same as expected. It is space sensitive (but case insensitive)

 

Apart from that, have you looked into using DLL based custom extension. You can create a class library project, using nuget package "AppDynamics.Agent.ExtensionSdk". Let me know if you need more details about this. 

 

Anurag 

Re: How to create custom metrics in AppDynamics by C# program

Hi Anurag

 

Thanks for the reply :)

 

Yes, i made a standalone application in C#.

First i made it just like the demo my-script.cmd which came with the download.

I just copypasted the string into my C# program changing to other numbers, and then writing it to stdout with Console.WriteLine, like this:

 

 

Console.WriteLine("metric1 | instance1, value = 123456789");
Console.WriteLine("metric2 | instance1, value = 54321");

 

 

I did not run my C# application through a cmd script, but i did receive those new numbers i changed to into my application in the controller (so it seemed to work).

 

The next day i tried again doing it with various primitives(numbers), both from variables and hardcoded, concatenated into the string, like this:

 

 

string datoStreng = datetime.ToString();

string[] splittedFullDate = datoStreng.Split(' ');
string dato = splittedFullDate[0];
string tid = splittedFullDate[1];

string[] strippedTime = tid.Split(':');

string klokka = String.Join("", strippedTime);
int tidToInt32 = System.Convert.ToInt32(klokka);

string test = $"int32 | ronnyscript , value = {tidToInt32}";
Console.WriteLine("int16 | ronnyscript, value = " + "123456789");

Console.WriteLine($"stringvariabel | ronnyscript , value = {klokka}");
Console.WriteLine(test);

Console.WriteLine("hardkodetint | ronnyscript , value = " + 1337);
Console.WriteLine("hardkodetlong | ronnyscript , value = " + 777L);
Console.WriteLine("hardkodetdouble | ronnyscript , value = " + 3.14);
Console.WriteLine("metricx | ronnyscript , value = " + 3.14);
Console.WriteLine("metricy | ronnyscript , value = 78");

 

None of this worked, even though the last line of code was just like one of those which worked the day before.

 

Checking the logs a little bit later i see an error message stating i have reached some sort of metric limit of a maximum of 200 metrics.

 

Do you think maybe i have reached some sort of limit, or do you think all of this is because i didnt run my C# application from a cmd script?

 

Also i would like to get as much information about this as you can offer me.

I am also interested in DLL based custom extension.

 

And thank you again.

 

Kind Regards

Ronny Ellingsen