mirror of https://github.com/apache/cloudstack.git
CID-1254832 tyr-with-resource
This commit is contained in:
parent
22ad646aca
commit
6bc0defa1d
|
|
@ -78,17 +78,14 @@ public class GraphiteClient {
|
|||
* @param timeStamp the timestamp
|
||||
*/
|
||||
public void sendMetrics(Map<String, Integer> metrics, long timeStamp) {
|
||||
try {
|
||||
DatagramSocket sock = new DatagramSocket();
|
||||
InetAddress addr = InetAddress.getByName(graphiteHost);
|
||||
try (DatagramSocket sock = new DatagramSocket()){
|
||||
InetAddress addr = InetAddress.getByName(this.graphiteHost);
|
||||
|
||||
for (Map.Entry<String, Integer> metric: metrics.entrySet()) {
|
||||
byte[] message = new String(metric.getKey() + " " + metric.getValue() + " " + timeStamp + "\n").getBytes();
|
||||
DatagramPacket packet = new DatagramPacket(message, message.length, addr, graphitePort);
|
||||
sock.send(packet);
|
||||
}
|
||||
|
||||
sock.close();
|
||||
} catch (UnknownHostException e) {
|
||||
throw new GraphiteException("Unknown host: " + graphiteHost);
|
||||
} catch (IOException e) {
|
||||
|
|
@ -122,4 +119,4 @@ public class GraphiteClient {
|
|||
metrics.put(key, value);
|
||||
sendMetrics(metrics, timeStamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue