mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
WebStatus:add syslog count/fail, show only enabled services
This commit is contained in:
@@ -116,7 +116,8 @@ void SyslogService::remove_queued_messages(uuid::log::Level level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log_message_id_ -= offset;
|
log_message_id_ -= offset;
|
||||||
|
log_message_fails_ += offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyslogService::log_level(uuid::log::Level level) {
|
void SyslogService::log_level(uuid::log::Level level) {
|
||||||
@@ -232,6 +233,7 @@ void SyslogService::operator<<(std::shared_ptr<uuid::log::Message> message) {
|
|||||||
if (log_messages_.size() >= maximum_log_messages_) {
|
if (log_messages_.size() >= maximum_log_messages_) {
|
||||||
log_messages_overflow_ = true;
|
log_messages_overflow_ = true;
|
||||||
log_messages_.pop_front();
|
log_messages_.pop_front();
|
||||||
|
log_message_fails_++;
|
||||||
}
|
}
|
||||||
|
|
||||||
log_messages_.emplace_back(log_message_id_++, std::move(message));
|
log_messages_.emplace_back(log_message_id_++, std::move(message));
|
||||||
|
|||||||
@@ -198,6 +198,13 @@ class SyslogService : public uuid::log::Handler {
|
|||||||
return ip_;
|
return ip_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned long message_count() {
|
||||||
|
return log_message_id_;
|
||||||
|
}
|
||||||
|
unsigned long message_fails() {
|
||||||
|
return log_message_fails_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Log message that has been queued.
|
* Log message that has been queued.
|
||||||
@@ -268,8 +275,9 @@ class SyslogService : public uuid::log::Handler {
|
|||||||
unsigned long log_message_id_ = 0; /*!< The next identifier to use for queued log messages. @since 1.0.0 */
|
unsigned long log_message_id_ = 0; /*!< The next identifier to use for queued log messages. @since 1.0.0 */
|
||||||
std::list<QueuedLogMessage> log_messages_; /*!< Queued log messages, in the order they were received. @since 1.0.0 */
|
std::list<QueuedLogMessage> log_messages_; /*!< Queued log messages, in the order they were received. @since 1.0.0 */
|
||||||
std::atomic<bool> log_messages_overflow_{false}; /*!< Check if log messages have overflowed the buffer. @since 1.0.0 */
|
std::atomic<bool> log_messages_overflow_{false}; /*!< Check if log messages have overflowed the buffer. @since 1.0.0 */
|
||||||
uint64_t mark_interval_ = 0; /*!< Mark interval in milliseconds. @since 2.0.0 */
|
uint64_t mark_interval_ = 0; /*!< Mark interval in milliseconds. @since 2.0.0 */
|
||||||
uint64_t last_message_ = 0; /*!< Last message/mark time. @since 2.0.0 */
|
uint64_t last_message_ = 0; /*!< Last message/mark time. @since 2.0.0 */
|
||||||
|
unsigned long log_message_fails_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace syslog
|
} // namespace syslog
|
||||||
|
|||||||
12
src/system.h
12
src/system.h
@@ -77,6 +77,18 @@ class System {
|
|||||||
bool heartbeat_json(JsonObject & output);
|
bool heartbeat_json(JsonObject & output);
|
||||||
void send_heartbeat();
|
void send_heartbeat();
|
||||||
|
|
||||||
|
bool syslog_enabled() {
|
||||||
|
return syslog_enabled_;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long syslog_count() {
|
||||||
|
return syslog_.message_count();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long syslog_fails() {
|
||||||
|
return syslog_.message_fails();
|
||||||
|
}
|
||||||
|
|
||||||
void led_init(bool refresh);
|
void led_init(bool refresh);
|
||||||
void network_init(bool refresh);
|
void network_init(bool refresh);
|
||||||
void button_init(bool refresh);
|
void button_init(bool refresh);
|
||||||
|
|||||||
@@ -158,29 +158,44 @@ void WebStatusService::webStatusService(AsyncWebServerRequest * request) {
|
|||||||
statJson["f"] = EMSESP::txservice_.telegram_write_fail_count();
|
statJson["f"] = EMSESP::txservice_.telegram_write_fail_count();
|
||||||
statJson["q"] = EMSESP::txservice_.write_quality();
|
statJson["q"] = EMSESP::txservice_.write_quality();
|
||||||
|
|
||||||
statJson = statsJson.createNestedObject();
|
if (EMSESP::dallassensor_.dallas_enabled()) {
|
||||||
statJson["id"] = "Temperature Sensor Reads";
|
statJson = statsJson.createNestedObject();
|
||||||
statJson["s"] = EMSESP::dallassensor_.reads();
|
statJson["id"] = "Temperature Sensor Reads";
|
||||||
statJson["f"] = EMSESP::dallassensor_.fails();
|
statJson["s"] = EMSESP::dallassensor_.reads();
|
||||||
statJson["q"] = EMSESP::dallassensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::dallassensor_.fails()) / EMSESP::dallassensor_.reads());
|
statJson["f"] = EMSESP::dallassensor_.fails();
|
||||||
|
statJson["q"] = EMSESP::dallassensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::dallassensor_.fails()) / EMSESP::dallassensor_.reads());
|
||||||
statJson = statsJson.createNestedObject();
|
}
|
||||||
statJson["id"] = "Analog Sensor Reads";
|
if (EMSESP::analog_enabled()) {
|
||||||
statJson["s"] = EMSESP::analogsensor_.reads();
|
statJson = statsJson.createNestedObject();
|
||||||
statJson["f"] = EMSESP::analogsensor_.fails();
|
statJson["id"] = "Analog Sensor Reads";
|
||||||
statJson["q"] = EMSESP::analogsensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::analogsensor_.fails()) / EMSESP::analogsensor_.reads());
|
statJson["s"] = EMSESP::analogsensor_.reads();
|
||||||
|
statJson["f"] = EMSESP::analogsensor_.fails();
|
||||||
statJson = statsJson.createNestedObject();
|
statJson["q"] = EMSESP::analogsensor_.reads() == 0 ? 100 : 100 - (uint8_t)((100 * EMSESP::analogsensor_.fails()) / EMSESP::analogsensor_.reads());
|
||||||
statJson["id"] = "MQTT Publishes";
|
}
|
||||||
statJson["s"] = Mqtt::publish_count();
|
if (Mqtt::enabled()) {
|
||||||
statJson["f"] = Mqtt::publish_fails();
|
statJson = statsJson.createNestedObject();
|
||||||
statJson["q"] = Mqtt::publish_count() == 0 ? 100 : 100 - (Mqtt::publish_fails() * 100) / (Mqtt::publish_count() + Mqtt::publish_fails());
|
statJson["id"] = "MQTT Publishes";
|
||||||
|
statJson["s"] = Mqtt::publish_count();
|
||||||
|
statJson["f"] = Mqtt::publish_fails();
|
||||||
|
statJson["q"] = Mqtt::publish_count() == 0 ? 100 : 100 - (uint8_t)((100 * Mqtt::publish_fails()) / (Mqtt::publish_count() + Mqtt::publish_fails()));
|
||||||
|
}
|
||||||
|
|
||||||
statJson = statsJson.createNestedObject();
|
statJson = statsJson.createNestedObject();
|
||||||
statJson["id"] = "API Calls";
|
statJson["id"] = "API Calls";
|
||||||
statJson["s"] = WebAPIService::api_count(); // + WebAPIService::api_fails();
|
statJson["s"] = WebAPIService::api_count(); // + WebAPIService::api_fails();
|
||||||
statJson["f"] = WebAPIService::api_fails();
|
statJson["f"] = WebAPIService::api_fails();
|
||||||
statJson["q"] = WebAPIService::api_count() == 0 ? 100 : 100 - (WebAPIService::api_fails() * 100) / (WebAPIService::api_count() + WebAPIService::api_fails());
|
statJson["q"] =
|
||||||
|
WebAPIService::api_count() == 0 ? 100 : 100 - (uint8_t)((100 * WebAPIService::api_fails()) / (WebAPIService::api_count() + WebAPIService::api_fails()));
|
||||||
|
|
||||||
|
if (EMSESP::system_.syslog_enabled()) {
|
||||||
|
statJson = statsJson.createNestedObject();
|
||||||
|
statJson["id"] = "Syslog Messages";
|
||||||
|
statJson["s"] = EMSESP::system_.syslog_count();
|
||||||
|
statJson["f"] = EMSESP::system_.syslog_fails();
|
||||||
|
statJson["q"] = EMSESP::system_.syslog_count() == 0
|
||||||
|
? 100
|
||||||
|
: 100 - (uint8_t)((100 * EMSESP::system_.syslog_fails()) / (EMSESP::system_.syslog_count() + EMSESP::system_.syslog_fails()));
|
||||||
|
}
|
||||||
|
|
||||||
response->setLength();
|
response->setLength();
|
||||||
request->send(response);
|
request->send(response);
|
||||||
|
|||||||
Reference in New Issue
Block a user