@@ -61,4 +61,86 @@ public function getMetrics(int $widgetId, $additionalQueryParams)
61
61
}
62
62
return $ data ->getBody ()->getContents ();
63
63
}
64
+
65
+
66
+
67
+ namespace UKFast \SDK \eCloud ;
68
+
69
+ use UKFast \SDK \Entities \ClientEntityInterface ;
70
+ use UKFast \SDK \Traits \PageItems ;
71
+ use UKFast \SDK \eCloud \Entities \Instance ;
72
+
73
+ class MonitoringClient extends Client implements ClientEntityInterface
74
+ {
75
+ use PageItems;
76
+
77
+ protected $ collectionPath = 'v2/monitoring ' ;
78
+
79
+ public function getEntityMap ()
80
+ {
81
+ return [
82
+ 'id ' => 'id ' ,
83
+ 'name ' => 'name ' ,
84
+ ];
85
+ }
86
+
87
+ /**
88
+ * @param $data
89
+ * @return Instance
90
+ */
91
+ public function loadEntity ($ data )
92
+ {
93
+ return new Instance (
94
+ $ this ->apiToFriendly ($ data , $ this ->getEntityMap ())
95
+ );
96
+ }
97
+
98
+ /**
99
+ * @param string $vmId
100
+ * @return array|string
101
+ * @throws \GuzzleHttp\Exception\GuzzleException
102
+ */
103
+ public function getAvailableMetrics (string $ vmId )
104
+ {
105
+ try {
106
+ $ data = $ this ->get ($ this ->collectionPath . "/ {$ vmId }" );
107
+ } catch (\Exception $ e ) {
108
+ return [];
109
+ }
110
+ return $ data ->getBody ()->getContents ();
111
+ }
112
+
113
+ /**
114
+ * @param int $widgetId
115
+ * @param $additionalQueryParams
116
+ * @return array|string
117
+ * @throws \GuzzleHttp\Exception\GuzzleException
118
+ */
119
+ public function getMetrics (string $ widgetId , $ additionalQueryParams )
120
+ {
121
+ try {
122
+ $ data = $ this ->get ($ this ->collectionPath . "/ {$ widgetId }/widget? {$ additionalQueryParams }" );
123
+ } catch (\Exception $ e ) {
124
+ return [];
125
+ }
126
+ return $ data ->getBody ()->getContents ();
127
+ }
128
+
129
+ /**
130
+ * @param int $pingId
131
+ * @param int $instanceId
132
+ * @param $additionalQueryParams
133
+ * @return array|string
134
+ * @throws \GuzzleHttp\Exception\GuzzleException
135
+ */
136
+ public function getPingMetrics (int $ pingId , int $ instanceId , $ additionalQueryParams )
137
+ {
138
+ try {
139
+ $ data = $ this ->get ($ this ->collectionPath . "/ {$ pingId }/ {$ instanceId }/ping? {$ additionalQueryParams }" );
140
+ } catch (\Exception $ e ) {
141
+ return $ e ->getMessage ();
142
+ return [];
143
+ }
144
+ return $ data ->getBody ()->getContents ();
145
+ }
64
146
}
0 commit comments