add hostname in influx request

This commit is contained in:
Wolfgang Hottgenroth 2019-10-10 20:03:59 +01:00
parent 95f938e0b5
commit 562ee0d16c

View File

@ -13,9 +13,13 @@ const char INFLUXURL[] = "http://172.16.3.15:8086/write?db=smarthome2&precision=
char influxBuffer[BUFSIZE];
char *bufferNextEntry;
#define HOSTNAMESIZE 128
char hostname[HOSTNAMESIZE];
void influxInit() {
memset(influxBuffer, 0, BUFSIZE);
bufferNextEntry = influxBuffer;
gethostname(hostname, HOSTNAMESIZE);
}
static void influxSendRequest() {
@ -36,12 +40,12 @@ static void influxSendRequest() {
void influxAddFrequency(double f) {
static uint32_t entries = 0;
static uint32_t totalEntries = 0;
char tmpBuf[128];
char tmpBuf[256];
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
uint64_t tt = (((uint64_t)t.tv_sec) * 1000) + (((uint64_t)t.tv_nsec) / 1000000);
int c = sprintf(tmpBuf, "mainsfrequency freq=%f %llu\n", f, tt);
int c = sprintf(tmpBuf, "mainsfrequency,host=%s freq=%f %llu\n", hostname, f, tt);
if ((bufferNextEntry + c + 10) > (influxBuffer + BUFSIZE)) {
influxSendRequest();