[vlma-devel] commit: Update RRD data even if an error occurred. (Adrien Grand )

git version control git at videolan.org
Sun Sep 7 22:32:33 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sun Sep  7 21:56:10 2008 +0200| [0a49c962e00faecac7f90390339c87fb709a854c] | committer: Adrien Grand 

Update RRD data even if an error occurred.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=0a49c962e00faecac7f90390339c87fb709a854c
---

 .../java/org/videolan/vlma/VLMaServiceImpl.java    |   22 +++++++++++++++----
 1 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java b/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
index dbe0af2..3c77e59 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
@@ -193,7 +193,7 @@ public class VLMaServiceImpl implements VLMaService {
             String value = dataRetriever.retrieve(server, data);
             if(value == null) {
                 // the dataRetriever failed to retrieve data
-                continue;
+                value = "0";
             }
             try {
                 if(Data.TRAFFIC_IN.equals(data) || Data.TRAFFIC_OUT.equals(data)) {
@@ -201,10 +201,22 @@ public class VLMaServiceImpl implements VLMaService {
                 } else {
                     sample.setValue(data.name().toLowerCase(), Double.parseDouble(value.trim()));
                 }
-            } catch (NumberFormatException e) {
-                logger.error("Cannot convert value to the expected format (Server " + server.getName() + ")", e);
-            } catch (RrdException e) {
-                logger.error("Error while adding value to the RRD database", e);
+            } catch (Exception e) {
+                if (e instanceof NumberFormatException)
+                    logger.error("Cannot convert value to the expected format (Server " + server.getName() + ")", e);
+                else
+                    logger.error("Error while adding value to the RRD database", e);
+                // Even if there was an error, update the sample so that every data in the sample has the same timestamp
+                try {
+                    if(Data.TRAFFIC_IN.equals(data) || Data.TRAFFIC_OUT.equals(data)) {
+                        sample.setValue(data.name().toLowerCase(), 0L);
+                    } else {
+                        sample.setValue(data.name().toLowerCase(), 0d);
+                    }
+                } catch (RrdException f) {
+                    // Should not happen
+                    logger.error("Unexpected error!", f);
+                }
             }
         }
 



More information about the vlma-devel mailing list