Skip to content

Commit e4a7db0

Browse files
Can now report stats from statman
1 parent f9e5a57 commit e4a7db0

3 files changed

Lines changed: 46 additions & 8 deletions

File tree

transport.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace uplink {
3333
UPDATE = 5,
3434
APPDATA = 6,
3535
PANIC = 7,
36+
STATS = 8,
3637
ERROR = 255 // Legacy
3738
};
3839

ws_uplink.cpp

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <kernel/pci_manager.hpp>
3737
#include <hw/pci_device.hpp>
3838
#include <kernel/cpuid.hpp>
39+
#include <statman>
3940

4041
namespace uplink {
4142

@@ -209,17 +210,23 @@ namespace uplink {
209210
return;
210211
}
211212

212-
MYINFO("New transport (%lu bytes)", t->size());
213+
//MYINFO("New transport (%lu bytes)", t->size());
213214
switch(t->code())
214215
{
215216
case Transport_code::UPDATE:
216217
{
217-
INFO2("Update received - commencing update...");
218+
MYINFO("Update received - commencing update...");
218219

219220
update({t->begin(), t->end()});
220221
return;
221222
}
222223

224+
case Transport_code::STATS:
225+
{
226+
send_stats();
227+
break;
228+
}
229+
223230
default:
224231
{
225232
INFO2("Bad transport");
@@ -383,12 +390,7 @@ namespace uplink {
383390

384391
MYINFO("%s", str.c_str());
385392

386-
auto transport = Transport{Header{Transport_code::IDENT, static_cast<uint32_t>(str.size())}};
387-
388-
transport.load_cargo(str.data(), str.size());
389-
390-
ws_->write(transport.data().data(), transport.data().size());
391-
393+
send_message(Transport_code::IDENT, str.data(), str.size());
392394
}
393395

394396
void WS_uplink::send_message(Transport_code code, const char* data, size_t len) {
@@ -419,4 +421,37 @@ namespace uplink {
419421
inet_.nic().flush();
420422
}
421423

424+
void WS_uplink::send_stats()
425+
{
426+
using namespace rapidjson;
427+
428+
StringBuffer buf;
429+
Writer<StringBuffer> writer{buf};
430+
431+
writer.StartArray();
432+
auto& statman = Statman::get();
433+
for(auto it = statman.begin(); it != statman.end(); ++it)
434+
{
435+
auto& stat = *it;
436+
writer.StartObject();
437+
438+
writer.Key("name");
439+
writer.String(stat.name());
440+
441+
writer.Key("value");
442+
switch(stat.type()) {
443+
case Stat::UINT64: writer.Uint64(stat.get_uint64()); break;
444+
case Stat::UINT32: writer.Uint(stat.get_uint32()); break;
445+
case Stat::FLOAT: writer.Double(stat.get_float()); break;
446+
}
447+
448+
writer.EndObject();
449+
}
450+
writer.EndArray();
451+
452+
std::string str = buf.GetString();
453+
454+
send_message(Transport_code::STATS, str.data(), str.size());
455+
}
456+
422457
}

ws_uplink.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class WS_uplink {
5757

5858
void send_error(const std::string& err);
5959

60+
void send_stats();
61+
6062
void send_message(Transport_code, const char* data, size_t len);
6163

6264
bool is_online() const

0 commit comments

Comments
 (0)