Spaces:
Sleeping
Sleeping
Commit ·
b1acbf2
1
Parent(s): eb77a04
updated telegraf
Browse filesFiles changed (3)
81 unmodified lines8283848586878889909192939481 unmodified linesfig = go.Figure()fig.add_trace(go.Scatter(x=[point["timestamp"] for point in data_points],y=[point["value"] for point in data_points],mode='lines+markers'))fig.update_layout(title="MQTT Data Visualization",xaxis_title="Timestamp",yaxis_title="Value")return fig81 unmodified lines8283848586878889909192939481 unmodified linesfig = go.Figure()fig.add_trace(go.Scatter(x=[point["timestamp"] for point in data_points],y=[point["current"] for point in data_points],mode='lines+markers'))fig.update_layout(title="MQTT Data Visualization",xaxis_title="Timestamp",yaxis_title="Current (A)")return fig
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657function toInfluxDBFormat(measurement, tags, fields, timestamp = null) {// Validate inputif (typeof measurement !== 'string' || measurement.length === 0) {throw new Error('Measurement must be a non-empty string');}if (typeof tags !== 'object' || typeof fields !== 'object') {throw new Error('Tags and fields must be objects');}if (Object.keys(fields).length === 0) {throw new Error('At least one field is required');}// Escape special characters in measurementconst escapedMeasurement = measurement.replace(/,|\s/g, '\\$&');// Process tagsconst tagString = Object.entries(tags).map(([key, value]) => `${escapeKey(key)}=${escapeValue(value)}`).join(',');// Process fieldsconst fieldString = Object.entries(fields).map(([key, value]) => `${escapeKey(key)}=${formatValue(value)}`).join(',');// Construct the line protocol stringlet lineProtocol = escapedMeasurement;if (tagString) lineProtocol += `,${tagString}`;lineProtocol += ` ${fieldString}`;if (timestamp !== null) lineProtocol += ` ${timestamp}`;return lineProtocol;}function escapeKey(key) {return key.replace(/,|=|\s/g, '\\$&');}function escapeValue(value) {return String(value).replace(/,|=|\s/g, '\\$&');}function formatValue(value) {if (typeof value === 'string') return `"${value.replace(/"/g, '\\"')}"`;if (typeof value === 'number') return isFinite(value) ? String(value) : 'null';if (typeof value === 'boolean') return value ? 'true' : 'false';return 'null';}// Example usageconst measurement = "fan";const tags = { location: 'Chicago', sensor: 'S1' };const fields = { temperature: 72.5, humidity: 60, description: 'Partly cloudy', current:msg.payload};const influxDBLine = toInfluxDBFormat(measurement, tags, fields);msg.payload = influxDBLine;return msg;
323 unmodified lines3243253263273283293303313323333343353363373383393403413423431250 unmodified lines1594159515961597159815991600160116021603160416051606323 unmodified lines## Multiple URLs can be specified for a single cluster, only ONE of the## urls will be written to each interval.## ex: urls = ["https://us-west-2-1.aws.cloud2.influxdata.com"]urls = ["http://127.0.0.1:8086"]## Local address to bind when connecting to the server## If empty or not set, the local address is automatically chosen.# local_address = ""## Token for authentication.token = ""## Organization is the name of the organization you wish to write to.organization = ""## Destination bucket to write into.bucket = ""## The value of this tag will be used to determine the bucket. If this## tag is not set the 'bucket' option is used as the default.1250 unmodified lines## example: servers = ["tcp://localhost:1883"]## servers = ["ssl://localhost:1883"]## servers = ["ws://localhost:1883"]servers = ["tcp://127.0.0.1:1883"]## Topics that will be subscribed to.topics = ["telegraf/host01/cpu","telegraf/+/mem","sensors/#",]## The message topic will be stored in a tag specified by this value. If set323 unmodified lines3243253263273283293303313323333343353363373383393403413423431250 unmodified lines15941595159615971598159916001601160216031604323 unmodified lines## Multiple URLs can be specified for a single cluster, only ONE of the## urls will be written to each interval.## ex: urls = ["https://us-west-2-1.aws.cloud2.influxdata.com"]urls = ["https://us-east-1-1.aws.cloud2.influxdata.com/"]## Local address to bind when connecting to the server## If empty or not set, the local address is automatically chosen.# local_address = ""## Token for authentication.token = "${INFLUXDB_TOKEN}"## Organization is the name of the organization you wish to write to.organization = "dd7895c825a7c36a"## Destination bucket to write into.bucket = "machine_monitoring"## The value of this tag will be used to determine the bucket. If this## tag is not set the 'bucket' option is used as the default.1250 unmodified lines## example: servers = ["tcp://localhost:1883"]## servers = ["ssl://localhost:1883"]## servers = ["ws://localhost:1883"]servers = ["mqtt://broker.hivemq.com:1883"]## Topics that will be subscribed to.topics = ["test_fan"]## The message topic will be stored in a tag specified by this value. If set
gradio/app.py+2-2
node-red/influxdb_line_protocol_conversion.js+57
telegraf/telegraf.conf+7-9