diff options
author | Nicolas Hennion <nicolas@nicolargo.com> | 2014-01-26 21:42:48 +0100 |
---|---|---|
committer | Nicolas Hennion <nicolas@nicolargo.com> | 2014-01-26 21:42:48 +0100 |
commit | 05c675d7932eb0fcbaac691804d3040940c67902 (patch) | |
tree | 98e22e155e958dca8741d240b9fe3c793bd5661b /glances/plugins/glances_uptime.py | |
parent | 311ba7cef2f8745b66320d921d69e36727d253be (diff) |
Add Uptime and Now plugin. First step for processes plugins. Had to be optimezd
Diffstat (limited to 'glances/plugins/glances_uptime.py')
-rw-r--r-- | glances/plugins/glances_uptime.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/glances/plugins/glances_uptime.py b/glances/plugins/glances_uptime.py new file mode 100644 index 00000000..3359bb1d --- /dev/null +++ b/glances/plugins/glances_uptime.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Glances - An eye on your system
+#
+# Copyright (C) 2014 Nicolargo <nicolas@nicolargo.com>
+#
+# Glances is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Glances is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Import system libs
+# Check for PSUtil already done in the glances_core script
+try:
+ from psutil import get_boot_time
+except:
+ from putil import BOOT_TIME
+
+from datetime import datetime
+
+# from ..plugins.glances_plugin import GlancesPlugin
+from glances_plugin import GlancesPlugin
+
+class Plugin(GlancesPlugin):
+ """
+ Glances' Core Plugin
+ Get stats about uptime
+
+ stats is date (string)
+ """
+
+ def __init__(self):
+ GlancesPlugin.__init__(self)
+
+
+ def update(self):
+ """
+ Update uptime stat
+ """
+
+ # Uptime
+ try:
+ # For PsUtil >= 0.7.0
+ self.uptime = datetime.now() - datetime.fromtimestamp(get_boot_time())
+ except:
+ self.uptime = datetime.now() - datetime.fromtimestamp(BOOT_TIME)
+
+ # Convert uptime to string (because datetime is not JSONifi)
+ self.stats = str(self.uptime).split('.')[0]
|