mirror of https://github.com/nicolargo/glances
Alert timestamp is incorrect #2591
parent
f19e98417a
commit
2aa3f418df
3
Makefile
3
Makefile
|
@ -253,6 +253,9 @@ run-docker-ubuntu-dev: ## Start Glances Ubuntu Docker dev in console mode
|
||||||
run-webserver: ## Start Glances in Web server mode
|
run-webserver: ## Start Glances in Web server mode
|
||||||
./venv/bin/python -m glances -C ./conf/glances.conf -w
|
./venv/bin/python -m glances -C ./conf/glances.conf -w
|
||||||
|
|
||||||
|
run-webserver-local-conf: ## Start Glances in Web server mode with the system conf file
|
||||||
|
./venv/bin/python -m glances -w
|
||||||
|
|
||||||
run-restapiserver: ## Start Glances in REST API server mode
|
run-restapiserver: ## Start Glances in REST API server mode
|
||||||
./venv/bin/python -m glances -C ./conf/glances.conf -w --disable-webui
|
./venv/bin/python -m glances -C ./conf/glances.conf -w --disable-webui
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ NodeJS should be installed/updated on your system.
|
||||||
Example on Ubuntu OS:
|
Example on Ubuntu OS:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt install nodejs
|
sudo apt install nodejs npm
|
||||||
```
|
```
|
||||||
|
|
||||||
### Upgrade NodeJS
|
### Upgrade NodeJS
|
||||||
|
@ -22,7 +22,7 @@ Example on Ubuntu OS:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo apt update
|
sudo apt update
|
||||||
sudo apt install nodejs
|
sudo apt install nodejs npm
|
||||||
sudo npm install -g n
|
sudo npm install -g n
|
||||||
sudo n lts
|
sudo n lts
|
||||||
hash -r
|
hash -r
|
||||||
|
|
|
@ -95,10 +95,7 @@ export default {
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
formatDate(date) {
|
formatDate(date) {
|
||||||
return new Date(date)
|
return new Date(date).toLocaleString();
|
||||||
.toISOString()
|
|
||||||
.slice(0, 19)
|
|
||||||
.replace(/[^\d-:]/, ' ');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<section id="now" class="plugin">
|
<section id="now" class="plugin">
|
||||||
<div class="table-row">
|
<div class="table-row">
|
||||||
<div class="table-cell text-left">{{ localDate(value) }}</div>
|
<div class="table-cell text-left">{{ localDate(date_iso) }}</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
@ -14,16 +14,13 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
value() {
|
date_iso() {
|
||||||
return this.data.stats['now'];
|
return this.data.stats['now']['iso'];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
localDate(date) {
|
localDate(date) {
|
||||||
console.log(date)
|
return new Date(date).toLocaleString();
|
||||||
var local_date = new Date(date)
|
|
||||||
console.log(local_date)
|
|
||||||
return local_date.toISOString().slice(0, 19).replace(/[^\d-:]/, ' ');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2,7 +2,7 @@
|
||||||
#
|
#
|
||||||
# This file is part of Glances.
|
# This file is part of Glances.
|
||||||
#
|
#
|
||||||
# SPDX-FileCopyrightText: 2022 Nicolas Hennion <nicolas@nicolargo.com>
|
# SPDX-FileCopyrightText: 2024 Nicolas Hennion <nicolas@nicolargo.com>
|
||||||
#
|
#
|
||||||
# SPDX-License-Identifier: LGPL-3.0-only
|
# SPDX-License-Identifier: LGPL-3.0-only
|
||||||
#
|
#
|
||||||
|
@ -10,18 +10,42 @@
|
||||||
"""Now (current date) plugin."""
|
"""Now (current date) plugin."""
|
||||||
|
|
||||||
from time import tzname, strftime
|
from time import tzname, strftime
|
||||||
|
import datetime
|
||||||
from glances.plugins.plugin.model import GlancesPluginModel
|
from glances.plugins.plugin.model import GlancesPluginModel
|
||||||
|
|
||||||
|
# Fields description
|
||||||
|
# description: human readable description
|
||||||
|
# short_name: shortname to use un UI
|
||||||
|
# unit: unit type
|
||||||
|
# rate: if True then compute and add *_gauge and *_rate_per_is fields
|
||||||
|
# min_symbol: Auto unit should be used if value > than 1 'X' (K, M, G)...
|
||||||
|
fields_description = {
|
||||||
|
'custom': {
|
||||||
|
'description': 'Current date in custom format.'
|
||||||
|
},
|
||||||
|
'iso': {
|
||||||
|
'description': 'Current date in ISO 8601 format.'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class PluginModel(GlancesPluginModel):
|
class PluginModel(GlancesPluginModel):
|
||||||
"""Plugin to get the current date/time.
|
"""Plugin to get the current date/time.
|
||||||
|
|
||||||
stats is (string)
|
stats is a dict:
|
||||||
|
{
|
||||||
|
"custom": "2024-04-27 16:43:52 CEST",
|
||||||
|
"iso": "2024-04-27T16:28:23.382748"
|
||||||
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, args=None, config=None):
|
def __init__(self, args=None, config=None):
|
||||||
"""Init the plugin."""
|
"""Init the plugin."""
|
||||||
super(PluginModel, self).__init__(args=args, config=config)
|
super(PluginModel, self).__init__(
|
||||||
|
args=args,
|
||||||
|
config=config,
|
||||||
|
fields_description=fields_description,
|
||||||
|
stats_init_value={})
|
||||||
|
|
||||||
# We want to display the stat in the curse interface
|
# We want to display the stat in the curse interface
|
||||||
self.display_curse = True
|
self.display_curse = True
|
||||||
|
@ -35,23 +59,23 @@ class PluginModel(GlancesPluginModel):
|
||||||
if 'global' in config.as_dict():
|
if 'global' in config.as_dict():
|
||||||
self.strftime = config.as_dict()['global']['strftime_format']
|
self.strftime = config.as_dict()['global']['strftime_format']
|
||||||
|
|
||||||
def reset(self):
|
|
||||||
"""Reset/init the stats."""
|
|
||||||
self.stats = ''
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update current date/time."""
|
"""Update current date/time."""
|
||||||
# Had to convert it to string because datetime is not JSON serializable
|
stats = self.get_init_value()
|
||||||
# Add the time zone (issue #1249 / #1337 / #1598)
|
|
||||||
|
|
||||||
|
# Start with the ISO format
|
||||||
|
stats['iso'] = datetime.datetime.now().astimezone().replace(microsecond=0).isoformat()
|
||||||
|
|
||||||
|
# Then the custom
|
||||||
if self.strftime:
|
if self.strftime:
|
||||||
self.stats = strftime(self.strftime)
|
stats['custom'] = strftime(self.strftime)
|
||||||
else:
|
else:
|
||||||
if len(tzname[1]) > 6:
|
if len(tzname[1]) > 6:
|
||||||
self.stats = strftime('%Y-%m-%d %H:%M:%S %z')
|
stats['custom'] = strftime('%Y-%m-%d %H:%M:%S %z')
|
||||||
else:
|
else:
|
||||||
self.stats = strftime('%Y-%m-%d %H:%M:%S %Z')
|
stats['custom'] = strftime('%Y-%m-%d %H:%M:%S %Z')
|
||||||
|
|
||||||
|
self.stats = stats
|
||||||
return self.stats
|
return self.stats
|
||||||
|
|
||||||
def msg_curse(self, args=None, max_width=None):
|
def msg_curse(self, args=None, max_width=None):
|
||||||
|
@ -64,7 +88,7 @@ class PluginModel(GlancesPluginModel):
|
||||||
|
|
||||||
# Build the string message
|
# Build the string message
|
||||||
# 23 is the padding for the process list
|
# 23 is the padding for the process list
|
||||||
msg = '{:23}'.format(self.stats)
|
msg = '{:23}'.format(self.stats['custom'])
|
||||||
ret.append(self.curse_add_line(msg))
|
ret.append(self.curse_add_line(msg))
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
Loading…
Reference in New Issue