save raw freq, add location
This commit is contained in:
parent
6a13da024d
commit
08c76f13de
@ -15,3 +15,10 @@ all: counter
|
|||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
-rm -f *.o counter
|
-rm -f *.o counter
|
||||||
|
|
||||||
|
.PHONY: deploy
|
||||||
|
deploy:
|
||||||
|
sudo systemctl stop counter
|
||||||
|
sudo cp counter /opt/sbin/
|
||||||
|
sudo systemctl start counter
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <libconfig.h>
|
#include <libconfig.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#include "LS7366R.h"
|
#include "LS7366R.h"
|
||||||
#include "influx.h"
|
#include "influx.h"
|
||||||
@ -77,6 +78,7 @@ int main (void) {
|
|||||||
if (! config_lookup_float(&cfg, EPSILON_KEY, &epsilon)) {
|
if (! config_lookup_float(&cfg, EPSILON_KEY, &epsilon)) {
|
||||||
epsilon = DEFAULT_EPSILON;
|
epsilon = DEFAULT_EPSILON;
|
||||||
}
|
}
|
||||||
|
fprintf(stderr, "CONFIG: epsilon=%f\n", epsilon);
|
||||||
|
|
||||||
|
|
||||||
double lastF = 0;
|
double lastF = 0;
|
||||||
@ -86,18 +88,19 @@ int main (void) {
|
|||||||
uint32_t diff = ringbufferGet();
|
uint32_t diff = ringbufferGet();
|
||||||
|
|
||||||
double f = 1.0 / (((double) diff) / 1000000.0);
|
double f = 1.0 / (((double) diff) / 1000000.0);
|
||||||
|
double fRaw = f;
|
||||||
int valid = settled ? 1 : 0;
|
int valid = settled ? 1 : 0;
|
||||||
|
|
||||||
double gradient = abs(f - lastF);
|
double gradient = f - lastF;
|
||||||
if (settled && (gradient > epsilon)) {
|
if (settled && (fabs(gradient) > epsilon)) {
|
||||||
logmsg(LOG_INFO, "Current f=%f, last f=%f, gradient too large, skipped\n", f, lastF);
|
logmsg(LOG_INFO, "Current f=%f, last f=%f, gradient too large, invalid\n", f, lastF);
|
||||||
skipped++;
|
skipped++;
|
||||||
f = lastF;
|
f = lastF;
|
||||||
valid = 0;
|
valid = 0;
|
||||||
}
|
}
|
||||||
lastF = f;
|
lastF = f;
|
||||||
// printf("%f, %d\n", f, valid);
|
// printf("%f, %d\n", f, valid);
|
||||||
influxAddFrequency(f, gradient, valid);
|
influxAddFrequency(fRaw, f, gradient, valid);
|
||||||
|
|
||||||
ledTick++;
|
ledTick++;
|
||||||
if (ledTick == 50) {
|
if (ledTick == 50) {
|
||||||
|
19
src/influx.c
19
src/influx.c
@ -19,6 +19,10 @@ const char INFLUXPASS_KEY[] = "influxPass";
|
|||||||
const char *influxPass;
|
const char *influxPass;
|
||||||
const char INFLUXTAG_KEY[] = "influxTag";
|
const char INFLUXTAG_KEY[] = "influxTag";
|
||||||
const char *influxTag;
|
const char *influxTag;
|
||||||
|
const char DEFAULT_LOCATION[] = "Essen_DE";
|
||||||
|
const char LOCATION_KEY[] = "location";
|
||||||
|
const char *location;
|
||||||
|
|
||||||
|
|
||||||
extern uint32_t skipped;
|
extern uint32_t skipped;
|
||||||
|
|
||||||
@ -42,16 +46,24 @@ void influxInit(config_t *pCfg) {
|
|||||||
if (! config_lookup_string(pCfg, INFLUXURL_KEY, &influxUrl)) {
|
if (! config_lookup_string(pCfg, INFLUXURL_KEY, &influxUrl)) {
|
||||||
influxUrl = DEFAULT_INFLUXURL;
|
influxUrl = DEFAULT_INFLUXURL;
|
||||||
}
|
}
|
||||||
|
fprintf(stderr, "CONFIG: influxUrl=%s\n", influxUrl);
|
||||||
if (! config_lookup_string(pCfg, INFLUXUSER_KEY, &influxUser)) {
|
if (! config_lookup_string(pCfg, INFLUXUSER_KEY, &influxUser)) {
|
||||||
influxUser = NULL;
|
influxUser = NULL;
|
||||||
}
|
}
|
||||||
|
fprintf(stderr, "CONFIG: influxUser=%s\n", (influxUser == NULL ? "<null>" : influxUser));
|
||||||
if (! config_lookup_string(pCfg, INFLUXPASS_KEY, &influxPass)) {
|
if (! config_lookup_string(pCfg, INFLUXPASS_KEY, &influxPass)) {
|
||||||
influxPass = NULL;
|
influxPass = NULL;
|
||||||
}
|
}
|
||||||
|
fprintf(stderr, "CONFIG: influxPass=%s\n", (influxPass == NULL ? "<null>" : influxPass));
|
||||||
|
if (! config_lookup_string(pCfg, LOCATION_KEY, &location)) {
|
||||||
|
location = DEFAULT_LOCATION;
|
||||||
|
}
|
||||||
|
fprintf(stderr, "CONFIG: location=%s\n", location);
|
||||||
if (! config_lookup_string(pCfg, INFLUXTAG_KEY, &influxTag)) {
|
if (! config_lookup_string(pCfg, INFLUXTAG_KEY, &influxTag)) {
|
||||||
gethostname(hostname, HOSTNAMESIZE);
|
gethostname(hostname, HOSTNAMESIZE);
|
||||||
influxTag = hostname;
|
influxTag = hostname;
|
||||||
}
|
}
|
||||||
|
fprintf(stderr, "CONFIG: influxTag=%s\n", influxTag);
|
||||||
influxClearBuffer();
|
influxClearBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +91,8 @@ static void influxSendRequest() {
|
|||||||
led(E_BLUE, false);
|
led(E_BLUE, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void influxAddFrequency(double f, double gradient, int valid) {
|
void influxAddFrequency(double fRaw, double fSmoothed, double gradient,
|
||||||
|
int valid) {
|
||||||
static uint32_t entries = 0;
|
static uint32_t entries = 0;
|
||||||
static uint32_t totalEntries = 0;
|
static uint32_t totalEntries = 0;
|
||||||
char tmpBuf[256];
|
char tmpBuf[256];
|
||||||
@ -87,13 +100,13 @@ void influxAddFrequency(double f, double gradient, int valid) {
|
|||||||
|
|
||||||
clock_gettime(CLOCK_REALTIME, &t);
|
clock_gettime(CLOCK_REALTIME, &t);
|
||||||
uint64_t tt = (((uint64_t)t.tv_sec) * 1000) + (((uint64_t)t.tv_nsec) / 1000000);
|
uint64_t tt = (((uint64_t)t.tv_sec) * 1000) + (((uint64_t)t.tv_nsec) / 1000000);
|
||||||
int c = sprintf(tmpBuf, "mainsfrequency,host=%s,valid=%d freq=%f,gradient=%f %llu\n", influxTag, valid, f, gradient, tt);
|
int c = sprintf(tmpBuf, "mainsfrequency,host=%s,valid=%d,location=%s freq=%f,gradient=%f,freqRaw=%f %llu\n", influxTag, valid, location, fSmoothed, gradient, fRaw, tt);
|
||||||
|
|
||||||
if ((bufferNextEntry + c + 10) > (influxBuffer + BUFSIZE)) {
|
if ((bufferNextEntry + c + 10) > (influxBuffer + BUFSIZE)) {
|
||||||
influxSendRequest();
|
influxSendRequest();
|
||||||
influxClearBuffer();
|
influxClearBuffer();
|
||||||
totalEntries += entries;
|
totalEntries += entries;
|
||||||
logmsg(LOG_INFO, "%u entries sent to database, in total %u, skipped: %u\n", entries, totalEntries, skipped);
|
logmsg(LOG_INFO, "%u entries sent to database, in total %u, invalid: %u\n", entries, totalEntries, skipped);
|
||||||
entries = 0;
|
entries = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include <libconfig.h>
|
#include <libconfig.h>
|
||||||
|
|
||||||
void influxAddFrequency(double f, double gradient, int valid);
|
void influxAddFrequency(double fRaw, double fSmoothed, double gradient, int valid);
|
||||||
void influxInit(config_t *pCfg);
|
void influxInit(config_t *pCfg);
|
||||||
|
|
||||||
#endif // _INFLUX_H_
|
#endif // _INFLUX_H_
|
||||||
|
Loading…
x
Reference in New Issue
Block a user