@@ -8,30 +8,15 @@ public class Datadog: API {
8
8
private var timer : Timer = Timer ( )
9
9
internal let keychain = Keychain ( service: " api.datadoghq.com " )
10
10
public static let dd = Datadog ( )
11
- private var previous_wifi_sent : UInt32 = 0
12
- private var previous_wifi_received : UInt32 = 0
13
11
internal let host = UIDevice . current. identifierForVendor!. uuidString
14
12
internal let model = UIDevice . current. model
13
+ internal var use_agent = false
15
14
16
15
@objc private func sendData( ) {
17
16
print ( " Sending metrics to the Datadog API. " )
18
- if let cpu_usage = IOSAgent . current_CPU ( ) {
19
- self . metric. send ( metric: " system.cpu.user " , points: Float ( cpu_usage [ " user " ] !) , host: self . host, tags: [ ] , type: . gauge)
20
- self . metric. send ( metric: " system.cpu.idle " , points: Float ( cpu_usage [ " idle " ] !) , host: self . host, tags: [ ] , type: . gauge)
21
- self . metric. send ( metric: " system.cpu.system " , points: Float ( cpu_usage [ " system " ] !) , host: self . host, tags: [ ] , type: . gauge)
17
+ if use_agent {
18
+ IOSAgent . send_agent_metrics ( )
22
19
}
23
- if let mem_usage = IOSAgent . current_MEM ( ) {
24
- self . metric. send ( metric: " system.mem.used " , points: mem_usage, host: self . host, tags: [ ] , type: . gauge)
25
- }
26
- let data_usage_info = IOSAgent . getDataUsage ( )
27
- if previous_wifi_received != 0 || previous_wifi_sent != 0 {
28
- self . metric. send ( metric: " system.net.bytes_sent " , points: Float ( data_usage_info. wifiReceived - self . previous_wifi_received) , host: self . host, tags: [ ] , type: Metric . MetricData. MetricType. rate ( Float ( interval_seconds) ) )
29
- self . metric. send ( metric: " system.net.bytes_rcvd " , points: Float ( data_usage_info. wifiSent - self . previous_wifi_sent) , host: self . host, tags: [ ] , type: Metric . MetricData. MetricType. rate ( Float ( interval_seconds) ) )
30
- }
31
- self . metric. send ( metric: " ios.device.battery.level " , points: IOSAgent . get_battery_level ( ) )
32
- self . previous_wifi_sent = data_usage_info. wifiSent
33
- self . previous_wifi_received = data_usage_info. wifiReceived
34
-
35
20
do {
36
21
try self . metric. _send ( url: base_url) { ( error: Error ? ) in
37
22
print ( error!)
@@ -78,17 +63,24 @@ public class Datadog: API {
78
63
79
64
}
80
65
81
-
82
- private init ( ) {
66
+ public func initialize_api( with agent: Bool = false , default_tags: Bool = false ) {
83
67
do {
84
68
try get_credentials_from_plist ( )
85
69
} catch {
86
70
fatalError ( error. localizedDescription)
87
71
}
88
- self . metric. addTags ( tags: [ " agent:ios " , " model: \( IOSAgent . modelIdentifier ( ) ) " ] )
89
- self . event. addTags ( tags: [ " agent:ios " , " model: \( IOSAgent . modelIdentifier ( ) ) " ] )
72
+ self . use_agent = agent
73
+ if default_tags {
74
+ self . metric. addTags ( tags: [ " agent:ios " , " model: \( IOSAgent . modelIdentifier ( ) ) " ] )
75
+ self . event. addTags ( tags: [ " agent:ios " , " model: \( IOSAgent . modelIdentifier ( ) ) " ] )
76
+ }
90
77
self . timer = Timer . scheduledTimer ( timeInterval: self . interval_seconds, target: self , selector: #selector( Datadog . sendData) , userInfo: nil , repeats: true )
91
78
}
92
79
93
80
81
+ private init ( ) {
82
+
83
+ }
84
+
85
+
94
86
}
0 commit comments