Hello All,
Greetings!!
I am newbie in Telegraf, influxDB. I have written a module as follows.
[[inputs.exec]]
commands = [
"/etc/telegraf/singh_test.ksh"
]
timeout = "50s"
interval = "60s"
name_override = "singh_test"
data_format = "value"
data_type = "integer"
Looks like my script is getting called every 1 min and its output file is getting created also. But script’s data is NOT being sent to influx; though all other modules(default ones) work fine on same time.
Also when I change data_type to string its sending but I don’t want data_type to be string.
Could experts please do help in here? Will be grateful to you, searched for hours but NOT getting any way out for this one.
Thanks,
R. Singh
Hello Team,
I apologies for asking again here, since I tried my best but couldn’t find a way out of this problem. Will be grateful if experts could guide me here.
Thanks,
R. Singh
Hello @Ravinder_Singh,
Welcome! Sorry for the delay. What format are you hoping to write your data to? You have the following options for data_format:
- InfluxDB Line Protocol
- Carbon2
- Graphite
- JSON
- Prometheus
- SplunkMetric
- Wavefront
It looks like your config isn’t quite right.
The exec plugin should look like
[[outputs.exec]]
## Command to ingest metrics via stdin.
command = ["tee", "-a", "/dev/null"]
## Timeout for command to complete.
# timeout = "5s"
## Data format to output.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
# data_format = "influx"
And then you can include specifics for your data_format type.
1 Like
Thanks a TON @Anaisdg for your reply here. I tried following.
[[inputs.exec]]
commands = [
"/etc/telegraf/test.ksh"
]
timeout = "50s"
interval = "60s"
name_override = "test123"
data_format = "influx"
But it didn’t create table with name test123
Ultimately my script gives output in integer form thats why I was trying to put in integer form(which was wrong off course).
Could you please guide on this one, will be grateful to you, thank you.
Thanks,
R. Singh
@Ravinder_Singh,
If you’re going to use the data_format =. influx, then you need to include the config as shown:
- InfluxDB Line Protocol
## Files to write to, "stdout" is a specially handled file.
files = ["stdout", "/tmp/metrics.out"]
## Data format to output.
## Each data format has its own unique set of configuration options, read
## more about them here:
## https://github.com/influxdata/telegraf/blob/master/docs/DATA_FORMATS_OUTPUT.md
data_format = "influx"
## Maximum line length in bytes. Useful only for debugging.
influx_max_line_bytes = 0
## When true, fields will be output in ascending lexical order. Enabling
## this option will result in decreased performance and is only recommended
## when you need predictable ordering while debugging.
influx_sort_fields = false
## When true, Telegraf will output unsigned integers as unsigned values,
## i.e.: `42u`. You will need a version of InfluxDB supporting unsigned
## integer values. Enabling this option will result in field type errors if
## existing data has been written.
influx_uint_support = false
Where are you getting data from?
1 Like
@Anaisdg Thanks a TON for replying on same. My script is running(mentioned in inputs.exec section) my script gives integer output 0
OR 1
to tell service is up or down basically.
But how to take this data into influx not sure, I could see script is getting kicked off since its output file is getting created but data is NOT going to influx
Will be grateful to you if you could here, I am a newbie in telegraf, influx and Grafana.
PS: I would like to appreciate GREAT work from team which they have done for telegraf and influx DB, would like to really learn it more
Thanks,
R. Singh
@Ravinder_Singh,
Your data output from your script needs to be in one of the data formats listed above in order to use the exec plugin. InfluxDB ingests data in line protocol v1 and v2. The data_format options allow you to convert data from your exec plugin into line protocol or write directly with line protocol (data_format=influx).
Here is a blog on how to get started writing data to InfluxDB that you might find useful (it includes an exec plugin example)
What does your script do exactly? What service is it monitoring? You might be able to use an existing telegraf plugin already. I would look into this first.
Otherwise you’ll have to modify your script to output data in one of the acceptable data formats (probably outputting line protocol will be the easiest, so you don’t have to convert the data)
And sure thing! That’s what I’m here for I will pass on your thanks!
1 Like
@Anaisdg, Let me start from starting now
I have made use of telegraf’s inputs.net_response
module to get multiple services status. Now I want to get a single status, for which I have written script to collect status from all tables and then print 0(SUCCESS) or 1(failure). Here is where I am stuck
BTW I am sending this data to create graph to Grafana that’s why I need to have output into integer so that color of my graph will change RED for failure and stay GREEN for OK.
I hope I have not confused you(since English is not my first language)
Any guidance is appreciated and welcome here. BTW I tried running that type to influx and it didn’t work.
Thanks,
R. Singh
@Anaisdg,
After hours of efforts and with help of links of documentation which you sent I understood that we need to send data to influx in a specific format, so my script is now sending data like:
test123,host=test_singh dance="etc",value=0i 1588282400000000000
But now problem is this measurement is NOT getting created in influx DB, I spent few hours in it but its too late night here, if you/experts could guide on this one will be grateful I think I am near to achieve success here
Thanks,
R. Singh
So you are using inputs.net_response successfully?
Can you please share your data and what you want to get? So that I can build a query for you?
1 Like
How are you trying to write
test123,host=test_singh dance="etc",value=0i 1588282400000000000
With telegraf? curl? through the UI?
If you’re writing that point with telegraf, can you please share your config?
The way I typically debug is through verifying whether I can write the point through curl or the UI, to identify whether my telegraf config has a problem.
1 Like
@Anaisdg, Thanks a TON for your reply I was waiting for it eagerly to fix it
This output is coming from when I run telegraf command sudo -u telegraf telegraf -test -config /etc/telegraf/telegraf.conf
. That’s why I believe my script is giving correct data(because previously when I ws using wrong data type in starting of this thread it was failing).
test123,host=test_singh dance="etc",result_code=0i 1588282400000000000
My module is as follows:
[[inputs.exec]]
commands = [
"bash /etc/telegraf/test_singh.ksh"
]
timeout = "40s"
interval = "80s"
name_override = "test123"
data_format= "influx"
Line protocol looks good to me but not sure why measurement is not getting created here.
PS: Reiterating again here, my shell script is running and querying fro different tables(which are running and getting output from inputs.net_response) then I am looking for a final return code out of all of them.
Thanks,
R. Singh
@Anaisdg, Thank you for your reply here, yes other things are working fine module inputs.net_response tables. Sorry I can’t share much on it apart from logical things since its official work
It’s summary is I have used this net_response telegraf module for many services and successfully getting result_code but that were components of app. Now for overall app status I need to make sure all result_code values are zero hence I written script for it. I hope I am clear here, appreciate your help and great guidance here.
Thanks,
R. Singh
Can you please share your query/how you’re identifying that the measurement isn’t being written? It is very odd that telegraf would be able to write that data and drop the measurement.
1 Like
@Anaisdg, Yes even I am surprised that why table is not being created in influx. I am simply doing show measurements
inside database and its not showing the measurement name, though all other measurements were created automatically(when inputs.net_response
is used).
EDIT: BTW my script’s output(test sample only here) is as follows.
test123,host=test_bla_bla result_code=0i,dance="Bhangra" 123458102000000000
@Anaisdg Will be grateful if you could guide me here how to troubleshoot this one, BIG THANKS for your guidance till now
Thanks,
R. Singh
1 Like
Hello @Ravinder_Singh,
First, I want to apologize. I have never used the value format. I didn’t think it existed in the way I thought. I didn’t read carefully enough. I will generate scripts that output both data formats with the exec plugin and see what I can get working/figure out what’s happening with your example. I will do this in a few hours.
1 Like
@Anaisdg, No need to apologise here I learnt new things in process. I appreciate your help here and LOVING telegraf, influx too much. I will be grateful if you could guide me here and will wait for your response here.
Again well done you folks for creating these nice monitoring software(s), these are ROCKING
I will go to sleep in next 4 to 5 hours and will monitor thread, in case I see your post will try to execute it asap then
Cheers and have a nice day.
Thanks,
R. Singh
What version of influx are you using btw?
@Anaisdg, sure influx version is InfluxDB shell version: 1.7.10
, please do let me know in case any more info is needed.
Okay so I decided to use the value, as you did because I think it’s the simplest.
Here is my script that’s generating random numbers*:
test.py.txt (165 Bytes)
Here is my telegraf plugin*:
exec.conf.txt (20.0 KB)
*Please note the extensions have been changed so I could upload them here.
FYI I’m huge fan of the following command telegraf --input-filter exec --output-filter influxdb config >exec.conf
which allows you to create a config with just your desired plugins.
We can see with show databases
my exec_test
database and my_metric_mycollector
measurement.
This measurement was created with name_overide
and name_suffix
.
I was able to write data successfully:
Also, I set debug=True
to ensure that I was able to write data to InfluxDB. Which gives me the following detailed output:
2020-05-01T20:09:38Z I! Starting Telegraf 1.13.4
2020-05-01T20:09:38Z I! Loaded inputs: exec
2020-05-01T20:09:38Z I! Loaded aggregators:
2020-05-01T20:09:38Z I! Loaded processors:
2020-05-01T20:09:38Z I! Loaded outputs: influxdb
2020-05-01T20:09:38Z I! Tags enabled: host=Anais.attlocal.net
2020-05-01T20:09:38Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"Anais.attlocal.net", Flush Interval:10s
2020-05-01T20:09:38Z D! [agent] Initializing plugins
2020-05-01T20:09:38Z D! [agent] Connecting outputs
2020-05-01T20:09:38Z D! [agent] Attempting connection to [outputs.influxdb]
2020-05-01T20:09:38Z D! [agent] Successfully connected to outputs.influxdb
2020-05-01T20:09:38Z D! [agent] Starting service inputs
2020-05-01T20:09:50Z D! [outputs.influxdb] Wrote batch of 1 metrics in 15.426867ms
2020-05-01T20:09:50Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
2020-05-01T20:10:00Z D! [outputs.influxdb] Wrote batch of 1 metrics in 84.434329ms
2020-05-01T20:10:00Z D! [outputs.influxdb] Buffer fullness: 1 / 10000 metrics
2020-05-01T20:10:10Z D! [outputs.influxdb] Wrote batch of 1 metrics in 12.729231ms
2020-05-01T20:10:10Z D! [outputs.influxdb] Buffer fullness: 0 / 10000 metrics
Can you please share the logs for telegraf after setting debug=True
?
My hope is that with this example, you can try the value way again?
1 Like