wb2osz / direwolf

Dire Wolf is a software "soundcard" AX.25 packet modem/TNC and APRS encoder/decoder. It can be used stand-alone to observe APRS traffic, as a tracker, digipeater, APRStt gateway, or Internet Gateway (IGate). For more information, look at the bottom 1/4 of this page and in https://github.com/wb2osz/direwolf/blob/dev/doc/README.md
GNU General Public License v2.0
1.58k stars 306 forks source link

Feature Request: Stats File #164

Open nayrnet opened 6 years ago

nayrnet commented 6 years ago

Story: As an operator I'd like an easy way to scrape internal stats for use with external graphing (MRTG)

Proposal: I've implemented a new beacon type called SBEACON that replicates the functionality of IBEACON but only writes to /tmp/dw-stats.txt

                case BEACON_STATS:

                  {
                    int last_minutes = 60;

                    FILE *statFile = fopen("/tmp/dw-stats.txt", "w");
                    if (statFile == NULL)
                        {
                            dw_printf("Error opening stats file!\n");
                        }

                    fprintf (statFile, "MSG_CNT=%d\r\nPKT_CNT=%d\r\nDIR_CNT=%d\r\nLOC_CNT=%d\r\nRF_CNT=%d\r\nUPL_CNT=%d\r\nDNL_CNT=%d\r\n",
                                                igate_get_msg_cnt(),
                                                igate_get_pkt_cnt(),
                                                mheard_count(0,last_minutes),
                                                mheard_count(g_igate_config_p->max_digi_hops,last_minutes),
                                                mheard_count(8,last_minutes),
                                                igate_get_upl_cnt(),
                                                igate_get_dnl_cnt());
                    fclose(statFile);
                    strlcpy (beacon_text, "", sizeof(beacon_text));  // abort!
                  }
                  break;

I set this to beacon every 5mins and then I whipped up a few simple bash scripts to feed MRTG

#!/bin/bash
# APRS-IS Traffic - MRTG Script for DireWolf

source /tmp/dw-stats.txt
echo $DNL_CNT
echo $UPL_CNT
uptime -p
hostname -a

and

#!/bin/bash
# Local RF - MRTG Script for DireWolf

source /tmp/dw-stats.txt
echo $DIR_CNT
echo $LOC_CNT
uptime -p
hostname -a

You can see them in action at http://igate.nayr.net

I'd offer a merge request, but my solution is not windows compatible (hardcoded filename) and kinda stomps on the toes of beacons with this pseduo beacon, and feels hacky because well it is.. so I dont think you'll take it.. But I would like to discuss such functionality.. I noticed your collecting other stats but had a TODO on using em, perhaps a json/xml/csv file that contains all this info and is updated at a configured interval.. or some sort of external API to retrieve this at our own rates.

dm-o commented 6 years ago

Sound very interesting. I love to give out stats on my own website too.

bhcleek commented 3 years ago

I wonder if this feature might be accepted by leveraging the IBEACON, but using a file path in the VIA field to cause it to write to a file similarly to how NOGATE will cause it to only write to the usual log file. Using VIA with a file path value could allow the beacon stats to be written to a specific file.

@wb2osz would you take such a patch?

wb2osz commented 3 years ago

There are a few outstanding requests for something external to change direwolf parameters on the fly or to query the internal state, e,g, statistics, recently heard stations, and so on. Rather polling for lots of assorted files, I was thinking of a more unified approach such as a network interface. Not necessarily REST, but that concept.

bhcleek commented 3 years ago

That's sounds great. I was just thinking last night that I wish I could reload the config with restarting. SIGHUP support would be a welcome change, too