-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Device Defender demo to send custom metrics #1547
Update Device Defender demo to send custom metrics #1547
Conversation
…hrough base and child struct hierarchy
…metrics collection for memory data strings
a5b834d
to
382cd8b
Compare
61121e0
to
c132c55
Compare
…ead of key-value pairs
"}" | ||
|
||
#define JSON_REPORT_CUSTOM_METRIC_START \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the following 4 macros be combined and thereby written in one snprintf
call as opposed to 5 snprintf
calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done. I was trying to separate out the formats of number-list and string-list through macros to make the different formats easier for the reader to see.
@@ -479,6 +670,41 @@ ReportBuilderStatus_t GenerateJsonReport( char * pBuffer, | |||
} | |||
} | |||
|
|||
/* Write custom metrics. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combining the 5 macros into one could reduce all this code into:
#define JSON_REPORT_FORMAT_PART5 \
"\"custom_metrics\":{" \
"\"cpu-usage\":[" \
"{" \
"\"number_list\":[" \
"%lu," \
"%lu" \
"]" \
"}" \
"]," \
"\"memory-info\":[" \
"{" \
"\"number_list\":[" \
"%u," \
"%u" \
"]}" \
"]" \
"}" \
/* Write custom metrics. */
if( status == ReportBuilderSuccess )
{
charactersWritten = snprintf( pCurrentWritePos,
remainingBufferLength,
JSON_REPORT_FORMAT_PART5,
pMetrics->pCustomMetrics->cpuUsageStats.upTime,
pMetrics->pCustomMetrics->cpuUsageStats.idleTime,
pMetrics->pCustomMetrics->memoryStats.totalMemory,
pMetrics->pCustomMetrics->memoryStats.availableMemory );
if( !SNPRINTF_SUCCESS( charactersWritten, remainingBufferLength ) )
{
LogError( ( "Failed to write part 5." ) );
status = ReportBuilderBufferTooSmall;
}
else
{
remainingBufferLength -= charactersWritten;
pCurrentWritePos += charactersWritten;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
7a08223
to
469c03e
Compare
{ | ||
while( ( fgets( &( lineBuffer[ 0 ] ), MAX_LINE_LENGTH, fileHandle ) != NULL ) ) | ||
{ | ||
lineNumber++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other function that has lineNumber
is GetEstablishedConnections
which uses it to skip the first line.
Co-authored-by: Gaurav-Aggarwal-AWS <33462878+aggarg@users.noreply.github.com>
…3/aws-iot-device-sdk-embedded-C into defender-demo/add-custom-metrics
This PR updates the device defender demo to demonstrate sending of custom metrics from a Linux platform to the AWS IoT Device Defender service. For more information on device-side custom metrics, refer to the AWS docs: https://docs.aws.amazon.com/iot/latest/developerguide/dd-detect-custom-metrics.html.
This PR makes the following changes:
/proc/uptime
) and System Memory data (obtained from/proc/meminfo
)Following is an example JSON report created from running the demo (Notice the custom metric objects of cpu-usage and memory-info at the end of the report):