From 7f10b8f5b94c6f4bba5c8cd13d606fe984099ae2 Mon Sep 17 00:00:00 2001 From: bert hubert Date: Wed, 20 Nov 2019 22:45:30 +0100 Subject: [PATCH] add 'reporter' for weekly/daily/whatever Galileo statistics, plus additional URL for F9P manual. --- Makefile | 6 +- README.md | 1 + minicurl.cc | 9 +++ minicurl.hh | 2 + reporter.cc | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 174 insertions(+), 1 deletion(-) create mode 100644 reporter.cc diff --git a/Makefile b/Makefile index 515a776..fd1ad75 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ CXXFLAGS:= -std=gnu++17 -Wall -O3 -MMD -MP -ggdb -fno-omit-frame-pointer -Iext/C # CXXFLAGS += -Wno-delete-non-virtual-dtor -PROGRAMS = navparse ubxtool navnexus navcat navrecv navdump testrunner navdisplay tlecatch +PROGRAMS = navparse ubxtool navnexus navcat navrecv navdump testrunner navdisplay tlecatch reporter all: navmon.pb.cc $(PROGRAMS) @@ -25,6 +25,10 @@ clean: navparse: navparse.o ext/fmt-5.2.1/src/format.o $(H2OPP) $(SIMPLESOCKETS) minicurl.o ubx.o bits.o navmon.pb.o gps.o ephemeris.o beidou.o glonass.o $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) tle.o navmon.o coverage.o $(CXX) -std=gnu++17 $^ -o $@ -pthread -L/usr/local/lib -L/usr/local/opt/openssl/lib/ -lh2o-evloop -lssl -lcrypto -lz -lcurl -lprotobuf $(WSLAY) +reporter: reporter.o ext/fmt-5.2.1/src/format.o $(H2OPP) $(SIMPLESOCKETS) minicurl.o ubx.o bits.o navmon.pb.o gps.o ephemeris.o beidou.o glonass.o $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) tle.o navmon.o coverage.o + $(CXX) -std=gnu++17 $^ -o $@ -pthread -L/usr/local/lib -L/usr/local/opt/openssl/lib/ -lh2o-evloop -lssl -lcrypto -lz -lcurl -lprotobuf $(WSLAY) + + navdump: navdump.o ext/fmt-5.2.1/src/format.o bits.o navmon.pb.o gps.o ephemeris.o beidou.o glonass.o navmon.o $(patsubst %.cc,%.o,$(wildcard ext/sgp4/libsgp4/*.cc)) tle.o sp3.o $(CXX) -std=gnu++17 $^ -o $@ -L/usr/local/lib -pthread -lprotobuf diff --git a/README.md b/README.md index 430ac04..2d5699d 100644 --- a/README.md +++ b/README.md @@ -213,6 +213,7 @@ Documents * [GPS](https://www.gps.gov/technical/icwg/IS-GPS-200K.pdf) * [U-blox 8 interface specification](https://www.u-blox.com/sites/default/files/products/documents/u-blox8-M8_ReceiverDescrProtSpec_%28UBX-13003221%29_Public.pdf) * [U-blox 9 interface specification](https://www.u-blox.com/sites/default/files/u-blox_ZED-F9P_InterfaceDescription_%28UBX-18010854%29.pdf) + * [U-blox 9 integration manual](https://www.u-blox.com/sites/default/files/ZED-F9P_IntegrationManual_%28UBX-18010802%29.pdf) Data sources ------------ diff --git a/minicurl.cc b/minicurl.cc index a62409f..b5a0189 100644 --- a/minicurl.cc +++ b/minicurl.cc @@ -182,3 +182,12 @@ void MiniCurl::setHeaders(const MiniCurlHeaders& headers) curl_easy_setopt(d_curl, CURLOPT_HTTPHEADER, d_header_list); } } + +string MiniCurl::urlEncode(string_view str) +{ + char *ptr= curl_easy_escape(d_curl , &str[0] , str.size() ); + string ret(ptr); + curl_free(ptr); + return ret; +} + diff --git a/minicurl.hh b/minicurl.hh index b46e4d8..4ef9904 100644 --- a/minicurl.hh +++ b/minicurl.hh @@ -44,6 +44,8 @@ public: MiniCurl& operator=(const MiniCurl&) = delete; std::string getURL(const std::string& str, const ComboAddress* rem=0, const ComboAddress* src=0); std::string postURL(const std::string& str, const std::string& postdata, MiniCurlHeaders& headers); + + std::string urlEncode(std::string_view str); private: CURL *d_curl; static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata); diff --git a/reporter.cc b/reporter.cc new file mode 100644 index 0000000..d5164a3 --- /dev/null +++ b/reporter.cc @@ -0,0 +1,157 @@ +#include "ext/powerblog/h2o-pp.hh" +#include "minicurl.hh" +#include +#include "navmon.hh" +#include "fmt/format.h" +#include "fmt/printf.h" + +using namespace std; + +/* + Goal: generate statistics from influxdb. + + Method: per x minute interval, determine status for all SVs. + We only count minutes in which we have data + + We do only positive measurements, and report absence of data in neutral terms - either there was no reception or no transmission, we don't know. + + If an interval has no data: unobserved + If interval has any data, it counts as observed + If interval has a single unhealthy status, it is entirely unhealthy + If interval is NAPA, but otherwise healthy, status is NAPA + If observed and nothing else, status is healthy + + Input: time range, width if interval + Internal: per SV, interval, bitfield + Output: per SV, number of intervals healthy, number of intervals NAPA, number of intervals unhealthy, number of intervals unobserved +*/ + + +struct IntervalStat +{ + std::optional unhealthy; + std::optional sisa; +}; + + +map> g_stats; + +int main(int argc, char **argv) +{ + MiniCurl mc; + MiniCurl::MiniCurlHeaders mch; + string dbname("galileo3"); + + string url="http://127.0.0.1:8086/query?db="+dbname+"&epoch=s&q="; + string period="time > now() - 1w"; + int sigid=1; + if(argc == 2) + period = "time > now() - "+string(argv[1]); + if(argc == 3) { + period = "time > '"+string(argv[1]) +"' and time <= '" + string(argv[2])+"'"; + } + auto res = mc.getURL(url + mc.urlEncode("select distinct(value) from sisa where "+period+" and sigid='"+to_string(sigid)+"' group by gnssid,sv,sigid,time(10m)")); + + + auto j = nlohmann::json::parse(res); + // cout<first < start) + start = sv.second.begin()->first; + if(sv.second.rbegin()->first > stop) + stop = sv.second.rbegin()->first; + } + + if(sv.second.size() > maxintervals) + maxintervals = sv.second.size(); + } + + cout<<"Report on "<