mptsd icon indicating copy to clipboard operation
mptsd copied to clipboard

add more statistics and /status.json page

Open freddy36 opened this issue 1 year ago • 11 comments

freddy36 avatar Mar 13 '24 17:03 freddy36

Great @freddy36 !

This will be useful.

Perhaps you want also to complete the code about the UDP listening COMMAND from here: https://github.com/lars18th/mptsd/commit/e38fb3bd29ad2d190ff16ec86e5375d5bf064053 For the LCN part I'll provide a new updated PR. But this code includes the listing thread from the UDP socket. However, it doesn't take any action when receive the message. Open to implement anything to execute actions on-the-fly. What you think?

lars18th avatar Mar 13 '24 18:03 lars18th

Hi @freddy36 ,

Perhaps you want to add one compile option to enable/disable the JSON code. I feel it will be useful to compile this tool without the JSON dependency in some small environments. You agree?

lars18th avatar Mar 13 '24 18:03 lars18th

What kind of commands do you intend to send via UDP? For functions like modifying inputs, etc. we probably would prefer a REST API over a UDP command API.

In general I try to avoid having compile time options. If someone really is running mptsd in a heavily storage/memory constraint environment, it's easy to add. But unless requested by @gfto we're not planning to add it.

freddy36 avatar Mar 13 '24 19:03 freddy36

Hi @freddy36 ,

Regarding the remote control, perhaps you're right and it's preferable a REST API.

Regarding json library linking, the idea is to reduce library dependencies as much as possible. But if @gfto agrees with that, then I'm not opposed to it.

lars18th avatar Mar 13 '24 21:03 lars18th

At minimum the libjson-c dep should be optional and enabled via make -DWITH_JSON=1 (or something similar).

Far better (since the library is only used to generate output) is to avoid the dependency. The generated output json does not look that complex.

gfto avatar Mar 14 '24 06:03 gfto

Hi @freddy36 ,

I have this suggestion:

  • Move the JSON output to the request /status.json. And make it optional when compiling.
  • Implement the plain text /status as with the friend tool tomcast (check: https://github.com/gfto/tomcast/blob/master/README.WEB_ACCESS)
  • Add oder options (like in tomcast): /getconfig and /reload.

I feel that this part of the code from tomcast could be reused. What you think?

lars18th avatar Mar 14 '24 06:03 lars18th

updated the PR JSON support can be disabled via make WITH_JSON=0 (default is enabled) Also moved it to /status.json to keep /status free for future use.

freddy36 avatar Mar 14 '24 16:03 freddy36

@gfto is this ok for you now or would you like to see any other changes?

freddy36 avatar Mar 18 '24 08:03 freddy36

@gfto do you have any otehr change request/other feedback regading this pull request?

freddy36 avatar Apr 26 '24 10:04 freddy36

Hi @freddy36 i cannot compile this, this is the error:

  LINK  libfuncs.a
  MAKE  libtsfuncs/libtsfuncs.a
  LINK  libtsfuncs.a
  CC    mptsd           iniparser.c
  CC    mptsd           inidict.c
  CC    mptsd           pidref.c
  CC    mptsd           data.c
  CC    mptsd           config.c
  CC    mptsd           sleep.c
  CC    mptsd           network.c
  CC    mptsd           input.c
  CC    mptsd           output_psi.c
  CC    mptsd           output_mix.c
  CC    mptsd           output_write.c
  CC    mptsd           web_pages.c
web_pages.c: In function ‘cmd_status_json’:
web_pages.c:314:9: warning: implicit declaration of function ‘send_header_applicationjson’ [-Wimplicit-function-declaration]
  314 |         send_header_applicationjson(clientsock);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
web_pages.c:334:9: warning: implicit declaration of function ‘send_header_content_length’ [-Wimplicit-function-declaration]
  334 |         send_header_content_length(clientsock, length);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
web_pages.c:336:29: warning: passing argument 2 of ‘fdwrite’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  336 |         fdwrite(clientsock, jbuf, length);
      |                             ^~~~
In file included from web_pages.c:29:
libfuncs/io.h:29:31: note: expected ‘char *’ but argument is of type ‘const char *’
   29 | ssize_t fdwrite(int fd, char *buf, size_t buf_size);
      |                         ~~~~~~^~~
  CC    mptsd           web_server.c
  CC    mptsd           mptsd.c
  LINK  mptsd
/usr/bin/ld: web_pages.o: en la función `cmd_status_json':
/home/usuario/sources/mptsd_stats/mptsd/web_pages.c:314: referencia a `send_header_applicationjson' sin definir
/usr/bin/ld: /home/usuario/sources/mptsd_stats/mptsd/web_pages.c:334: referencia a `send_header_content_length' sin definir
collect2: error: ld returned 1 exit status
make: *** [Makefile:68: mptsd] Error ```


Any sugestion? 
Regards,


TagorePde avatar Jul 26 '24 15:07 TagorePde

Hi @freddy36 i cannot compile this, this is the error:

  LINK  libfuncs.a
  MAKE  libtsfuncs/libtsfuncs.a
  LINK  libtsfuncs.a
  CC    mptsd           iniparser.c
  CC    mptsd           inidict.c
  CC    mptsd           pidref.c
  CC    mptsd           data.c
  CC    mptsd           config.c
  CC    mptsd           sleep.c
  CC    mptsd           network.c
  CC    mptsd           input.c
  CC    mptsd           output_psi.c
  CC    mptsd           output_mix.c
  CC    mptsd           output_write.c
  CC    mptsd           web_pages.c
web_pages.c: In function ‘cmd_status_json’:
web_pages.c:314:9: warning: implicit declaration of function ‘send_header_applicationjson’ [-Wimplicit-function-declaration]
  314 |         send_header_applicationjson(clientsock);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~
web_pages.c:334:9: warning: implicit declaration of function ‘send_header_content_length’ [-Wimplicit-function-declaration]
  334 |         send_header_content_length(clientsock, length);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
web_pages.c:336:29: warning: passing argument 2 of ‘fdwrite’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  336 |         fdwrite(clientsock, jbuf, length);
      |                             ^~~~
In file included from web_pages.c:29:
libfuncs/io.h:29:31: note: expected ‘char *’ but argument is of type ‘const char *’
   29 | ssize_t fdwrite(int fd, char *buf, size_t buf_size);
      |                         ~~~~~~^~~
  CC    mptsd           web_server.c
  CC    mptsd           mptsd.c
  LINK  mptsd
/usr/bin/ld: web_pages.o: en la función `cmd_status_json':
/home/usuario/sources/mptsd_stats/mptsd/web_pages.c:314: referencia a `send_header_applicationjson' sin definir
/usr/bin/ld: /home/usuario/sources/mptsd_stats/mptsd/web_pages.c:334: referencia a `send_header_content_length' sin definir
collect2: error: ld returned 1 exit status
make: *** [Makefile:68: mptsd] Error ```


Any sugestion? 
Regards,



Go to the libfuncs directory and git pull the latest version: https://github.com/gfto/libfuncs

freddy36 avatar Jul 27 '24 00:07 freddy36