Application Insights Analytics - Chart X axis - azure-application-insights

How can I render a chart for the query
performanceCounters
| where name == "% Processor Time"
| summarize avg(value) by bin(timestamp, 5s),cloud_RoleInstance
where i get a point for every 5 seconds and not every 1 min?

Perf counters are collected at a regular interval (about 1 min) the effect of the bin function will move the time stamp to the nearest 5 second interval. What you're seeing is because of the counter collection interval and you won't get that granularity. You would need to implement your own module to do that.
https://github.com/Microsoft/ApplicationInsights-dotnet-server/blob/v2.3.0/Src/PerformanceCollector/Shared/PerformanceCollectorModule.cs#L49

Related

Aggregate/Summarize Timeseries data in Azure Data Explorer using Kusto

I have a requirement where I need to regularize/aggregate data which is polled every 1 sec into 1 min intervals. And I have two columns which need to be aggregated as well, say SensorName, SensorValue. I am able to bin the timestamp to 1 minute, but I am not able to get the corresponding two colums. How do I do that? Below is the query I used and the output I get.
Table
| where TimeStamp between (datetime(2020-09-01)..datetime(2020-09-30))
| summarize by bin(TimeStamp , 1min)
based on my understanding of the question (could be wrong, as there's no clear specification of sample input/schema and matching output), you could try following this example - it calculates the average sensor value for each sensor name, using an aggregation span of 1 minute:
Table
| where TimeStamp between (datetime(2020-09-01)..datetime(2020-09-30))
| summarize avg(SensorValue) by SensorName, bin(TimeStamp, 1min)

Azure VM avage cpu usage past 30 days

I'm trying to write down an Azure Log analytics query that would show me the average CPU usage in the past 30 days for my Azure virtual machines.
With the following query I have some results, but not really what I'm looking for:
Perf
| where ObjectName == 'Processor' and CounterName == '% Processor Time' and InstanceName == '_Total'
| summarize CPUAvarage = avg(CounterValue) by Computer, bin(TimeGenerated, 1h)
Result:
The result are are in the correct form, but the TimeGenerated should be last 30 days and "CPUAvarage" should display 1 number for past 30 days (30 days average cpu). If I'm correct query should add all values together past 30 days and then divide it by count but my with my current Kusto skills I'm not able to do this.
I don't fully understand what you're trying to achieve, so here are your options:
If you want the result to be per day, and not per hour, then you should replace bin(TimeGenerated, 1h) with bin(TimeGenerated, 1d), because 1h is an hour, and 1d is a day.
If you want the average CPU per computer over the whole month, then replace your summarize line with | summarize CPUAvarage = avg(CounterValue) (note that I removed the bin part).
If you want the average CPU per day for all your computers (rather than per computer), then replace your summarize line with | summarize CPUAvarage = avg(CounterValue) by bin(TimeGenerated, 1d).

SQLite query GROUP BY range

Here are my table's columns :
Time | Close | High | Low | Open | pairVolume | Trades | Volume
I would love to have my data group by range of time.
Now the tricky part is that this range is custom (it's a user input which could very well be grouping by 10 minutes, 2 hours, or even 5 days)
My time field is stored in millisecond since epoch.
Solution I found for now which I'm uncertain about :
SELECT time + (21600000 - (time%21600000)) as gap, count(time)
FROM price_chart
WHERE time >= 1517418000000 and time <= 1518195600000
GROUP BY gap
21600000 is 6 hours in milliseconds
time is time since epoch
Yes, it works.
Putting some numbers into excel with your formula below, it works for me. Your gap value will be returned as the top end of each time range grouping.
SELECT time + (21600000 - (time%21600000)) as gap ...
Using the below:
SELECT time - (time%21600000) as gap_bottom ...
Would return you the bottom end of each time range grouping. You could add this as an additional calculated column and have both returned.
EDIT / PS:
You can also use the SQLite date formatting functions after dividing 1,000 milliseconds out of your epoch time and converting it to the SQLite unixepoch:
strftime('%Y-%m-%d %H:%M:%S', datetime(1517418000000 / 1000, 'unixepoch') )
... for ...
SELECT strftime('%Y-%m-%d %H:%M:%S', datetime( (time + (21600000 - (time%21600000))) / 1000, 'unixepoch') ) as gap ...

Get total time and create an average based on timestamps

Background: I want to use coldfusion to find the total time a process takes by taking two timestamps and then adding all of the total times to create an average.
Question: What is the best way to take two timestamps and find out the difference in time by minutes.
Example:
Time Stamp #1: 2015-05-08 15:44:00.000
Time Stamp #2: 2015-05-11 08:52:00.000
So the time between the above timestamps would be:
2 Days 6 hours 52 mins = 3,292 minutes
I want to run this conversion on a handful of timestamp's and take the total minutes and divide to get an average.
To add more information to my question. 1. Yes the values are coming from a DB MSSQL. 2. I am actually going to be using the individual time differences and showing and overall average. So in my for loop each line will have a value like 3,292 (converted to mins or hours or days) and at the end of the for loop I want to show an average of all the lines shown on the page. Let me know if I need to add any other information.
Assuming your query is sorted properly, something like this should work.
totalMinutes = 0;
for (i = 2; i <= yourQuery.recordcount; i++)
totalMinutes +=
DateDiff('n'
, yourQuery.timestampField[i-1]
,yourQuery.timestampField[i]);
avgMinutes = totalMinutes / (yourQuery.recordcount -1);
Use the dateDiff() function
diffInMinutes = dateDiff('n', date1, date2);

Graphite how to summarize based on selected interval

How can I summarize graphite data depending on the selected interval? If the selected interval is up to 1 hour, the data counter should show data points for every minute. If the interval is up to 3 hours, the data should be summarized over 5 minutes. If the interval is up to 1 day, the data should be summarized over 15 minutes.
Is this possible?
You can get something close this this using by creating an interval template variable, enable the Auto option, and set number of steps. In the example below it's set to 40 steps so it will pick an appropriate interval based on the time range.
Use the variable like this:
AFAIK Graphite doesn't do this automatically.
However since Graphite has a public API you can script this yourself automatically to retrieve the graph with the correct summarizing period. Grafana for example does this when using the 'auto' option for interval template.
Pseudo-code:
if interval == '1h':
get_metric(summarize(metric, '1min', 'sum')
elif interval == '3h':
get_metric(summarize(metric, '5min', 'sum')
elif interval == '1d':
get_metric(summarize(metric, '15min', 'sum')

Resources