Hi, We are trying to integrate Metric Kit into our MacOS Application. Our application is a background process. We are interested in getting CPU and Memory metrics for our process. MXMetricPayload is the one we are looking at. We tried to integrate metric Kit and left the background app for 24 hours, we did not get any callback. So, does metric kit work for background app in MacOS? Also does it for Network Extension?
we received approximately 48 hours of past metric payloads
Oh, interesting. I’m not 100% sure what’s going on here but this behaviour doesn’t surprise me. Internally, MetricKit uses an XPC activity to drive metric delivery [1], and XPC activities a very much a best effort kinda thing.
could u comment if MetricKit works for NE Process?
Well, I think you have pretty solid evidence that it doesn’t (-:
I’m going to talk about what’s going on in a sec, but before I do that I want to give you some concrete advice: If you want MetricKit to work in your NE system extension, I encourage you to file an enhancement request that describes your setup and why MetricKit is important to you. Once you’re done, please post your bug number here, just for the record.
As to why this doesn’t work, consider this:
% find /System/Library/LaunchDaemons /System/Library/LaunchAgents -name "*[^a-z]metrickitd*"
/System/Library/LaunchAgents/com.apple.metrickitd.plist
The MetricKit ‘daemon’ is not actually a daemon but rather a launchd agent. That means it’s only available to programs running in some sort of user login session [2]. All system extensions run in the global context, and thus don’t have access to services vended by an agent.
For more about execution contexts on macOS, see TN2083 Daemons and Agents. It’s super old, but the fundamentals are still valid.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] You can see evidence for this its launchd property list:
% plutil -p /System/Library/LaunchAgents/com.apple.metrickitd.plist
{
…
"Label" => "com.apple.metrickitd"
"LaunchEvents" => {
"com.apple.xpc.activity" => {
"com.apple.metrickitd.setup" => {
"AllowBattery" => true
"Delay" => 60
"Priority" => "Maintenance"
"Repeating" => false
"RequireScreenSleep" => true
}
}
}
…
}
Be aware, however, that this is only a part of the story. The relationship between MetricKit and XPC activities is very much an implementation detail.
[2] The exact set of sessions is set by the LimitLoadToSessionType property in the launchd property list. You can learn more about this in the launchd.plist man page, along with TN2083. I’m not going to explore it here because it’s not relevant to your situation.